blob: 1893e25bdcf0a535a2592188c70777610e3aa02b [file] [log] [blame]
[email protected]05d478752009-04-08 23:38:161// Copyright (c) 2009 The Chromium Authors. All rights reserved.
license.botbf09a502008-08-24 00:55:552// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
initial.commit09911bf2008-07-26 23:55:294
5#include "chrome/renderer/render_view.h"
6
7#include <algorithm>
8#include <string>
9#include <vector>
10
11#include "base/command_line.h"
[email protected]bb063b72009-03-27 23:18:5012#include "base/compiler_specific.h"
initial.commit09911bf2008-07-26 23:55:2913#include "base/gfx/png_encoder.h"
[email protected]18bcc3c2009-01-27 21:39:1514#include "base/gfx/native_widget_types.h"
initial.commit09911bf2008-07-26 23:55:2915#include "base/string_piece.h"
16#include "base/string_util.h"
[email protected]6c8afae52009-01-22 02:24:5717#include "build/build_config.h"
[email protected]81e63782009-02-27 19:35:0918#include "chrome/common/bindings_policy.h"
initial.commit09911bf2008-07-26 23:55:2919#include "chrome/common/chrome_switches.h"
initial.commit09911bf2008-07-26 23:55:2920#include "chrome/common/gfx/favicon_size.h"
21#include "chrome/common/gfx/color_utils.h"
22#include "chrome/common/jstemplate_builder.h"
23#include "chrome/common/l10n_util.h"
[email protected]2e4bdcdc2009-03-27 23:07:3024#include "chrome/common/message_box_flags.h"
[email protected]630e26b2008-10-14 22:55:1725#include "chrome/common/page_zoom.h"
[email protected]e09ba552009-02-05 03:26:2926#include "chrome/common/render_messages.h"
initial.commit09911bf2008-07-26 23:55:2927#include "chrome/common/resource_bundle.h"
initial.commit09911bf2008-07-26 23:55:2928#include "chrome/common/thumbnail_score.h"
[email protected]6de74452009-02-25 18:04:5929#include "chrome/common/url_constants.h"
initial.commit09911bf2008-07-26 23:55:2930#include "chrome/renderer/about_handler.h"
[email protected]5fb88962009-04-16 19:03:2531#include "chrome/renderer/audio_message_filter.h"
initial.commit09911bf2008-07-26 23:55:2932#include "chrome/renderer/debug_message_handler.h"
[email protected]e4ac5df2009-03-17 15:33:1133#include "chrome/renderer/devtools_agent.h"
34#include "chrome/renderer/devtools_client.h"
[email protected]309d7a282009-03-24 09:18:2735#include "chrome/renderer/extensions/extension_process_bindings.h"
initial.commit09911bf2008-07-26 23:55:2936#include "chrome/renderer/localized_error.h"
[email protected]6f56d482009-02-20 05:02:5637#include "chrome/renderer/media/audio_renderer_impl.h"
[email protected]39008c02009-02-11 23:59:2538#include "chrome/renderer/render_process.h"
[email protected]fcf19542009-03-30 21:24:0739#include "chrome/renderer/renderer_logging.h"
[email protected]0938d3c2009-01-09 20:37:3540#include "chrome/renderer/user_script_slave.h"
initial.commit09911bf2008-07-26 23:55:2941#include "chrome/renderer/visitedlink_slave.h"
[email protected]ec9212f2008-12-18 21:40:3642#include "chrome/renderer/webmediaplayer_delegate_impl.h"
[email protected]ba4b17f2009-02-11 21:32:2943#include "chrome/renderer/webplugin_delegate_proxy.h"
[email protected]eb47a132009-03-04 00:39:5644#include "chrome/renderer/webworker_proxy.h"
[email protected]34ac8f32009-02-22 23:03:2745#include "grit/generated_resources.h"
46#include "grit/renderer_resources.h"
[email protected]f11ca0732009-04-11 00:09:3447#include "net/base/data_url.h"
initial.commit09911bf2008-07-26 23:55:2948#include "net/base/escape.h"
49#include "net/base/net_errors.h"
[email protected]88a3ecc2009-03-19 17:36:2250#include "printing/units.h"
[email protected]c399a8a2008-11-22 19:38:0051#include "skia/ext/bitmap_platform_device.h"
[email protected]83c9e6552008-12-03 16:22:1052#include "skia/ext/image_operations.h"
[email protected]e80c73b2009-04-07 23:24:5853#include "third_party/WebKit/WebKit/chromium/public/WebDragData.h"
54#include "third_party/WebKit/WebKit/chromium/public/WebPoint.h"
[email protected]b3f2b912009-04-09 16:18:5255#include "third_party/WebKit/WebKit/chromium/public/WebRect.h"
[email protected]4f999132009-03-31 18:08:4056#include "third_party/WebKit/WebKit/chromium/public/WebScriptSource.h"
[email protected]b3f2b912009-04-09 16:18:5257#include "third_party/WebKit/WebKit/chromium/public/WebSize.h"
[email protected]ba4b17f2009-02-11 21:32:2958#include "webkit/default_plugin/default_plugin_shared.h"
initial.commit09911bf2008-07-26 23:55:2959#include "webkit/glue/dom_operations.h"
60#include "webkit/glue/dom_serializer.h"
[email protected]f11ca0732009-04-11 00:09:3461#include "webkit/glue/image_decoder.h"
initial.commit09911bf2008-07-26 23:55:2962#include "webkit/glue/password_form.h"
[email protected]ba4b17f2009-02-11 21:32:2963#include "webkit/glue/plugins/plugin_list.h"
initial.commit09911bf2008-07-26 23:55:2964#include "webkit/glue/searchable_form_data.h"
[email protected]6a983b42009-03-20 20:12:2565#include "webkit/glue/webaccessibilitymanager_impl.h"
initial.commit09911bf2008-07-26 23:55:2966#include "webkit/glue/webdatasource.h"
[email protected]611cad42009-03-16 18:51:3467#include "webkit/glue/webdevtoolsagent_delegate.h"
initial.commit09911bf2008-07-26 23:55:2968#include "webkit/glue/webdropdata.h"
69#include "webkit/glue/weberror.h"
70#include "webkit/glue/webframe.h"
71#include "webkit/glue/webhistoryitem.h"
initial.commit09911bf2008-07-26 23:55:2972#include "webkit/glue/webkit_glue.h"
73#include "webkit/glue/webpreferences.h"
[email protected]b94d3322009-02-12 19:49:0474#include "webkit/glue/webplugin_delegate.h"
initial.commit09911bf2008-07-26 23:55:2975#include "webkit/glue/webresponse.h"
[email protected]00d7e622009-04-21 23:06:0576#include "webkit/glue/webtextinput.h"
initial.commit09911bf2008-07-26 23:55:2977#include "webkit/glue/weburlrequest.h"
78#include "webkit/glue/webview.h"
initial.commit09911bf2008-07-26 23:55:2979
[email protected]6c8afae52009-01-22 02:24:5780#if defined(OS_WIN)
81// TODO(port): these files are currently Windows only because they concern:
[email protected]f8b6b6f2009-03-10 16:48:2682// * logging
[email protected]6c8afae52009-01-22 02:24:5783// * printing
84// * theming
85// * views
86#include "base/gfx/gdi_util.h"
87#include "base/gfx/native_theme.h"
88#include "chrome/common/gfx/emf.h"
[email protected]fcf19542009-03-30 21:24:0789#include "chrome/views/controls/message_box_view.h"
[email protected]6c8afae52009-01-22 02:24:5790#include "skia/ext/vector_canvas.h"
[email protected]6c8afae52009-01-22 02:24:5791#endif
92
[email protected]c20210e62009-04-03 21:39:2693using base::Time;
[email protected]e1acf6f2008-10-27 20:43:3394using base::TimeDelta;
[email protected]6a983b42009-03-20 20:12:2595using webkit_glue::WebAccessibility;
[email protected]0dea3ea2009-03-31 23:30:5996using WebKit::WebConsoleMessage;
[email protected]e80c73b2009-04-07 23:24:5897using WebKit::WebDragData;
[email protected]b3f2b912009-04-09 16:18:5298using WebKit::WebRect;
[email protected]4f999132009-03-31 18:08:4099using WebKit::WebScriptSource;
[email protected]e1acf6f2008-10-27 20:43:33100
initial.commit09911bf2008-07-26 23:55:29101//-----------------------------------------------------------------------------
102
103// define to write the time necessary for thumbnail/DOM text retrieval,
104// respectively, into the system debug log
105// #define TIME_BITMAP_RETRIEVAL
106// #define TIME_TEXT_RETRIEVAL
107
108// maximum number of characters in the document to index, any text beyond this
109// point will be clipped
[email protected]6c8afae52009-01-22 02:24:57110static const size_t kMaxIndexChars = 65535;
initial.commit09911bf2008-07-26 23:55:29111
112// Size of the thumbnails that we'll generate
113static const int kThumbnailWidth = 196;
114static const int kThumbnailHeight = 136;
115
116// Delay in milliseconds that we'll wait before capturing the page contents
117// and thumbnail.
118static const int kDelayForCaptureMs = 500;
119
120// Typically, we capture the page data once the page is loaded.
121// Sometimes, the page never finishes to load, preventing the page capture
122// To workaround this problem, we always perform a capture after the following
123// delay.
124static const int kDelayForForcedCaptureMs = 6000;
125
[email protected]81a34412009-01-05 19:17:24126// The default value for RenderView.delay_seconds_for_form_state_sync_, see
127// that variable for more.
128const int kDefaultDelaySecondsForFormStateSync = 5;
initial.commit09911bf2008-07-26 23:55:29129
130// The next available page ID to use. This ensures that the page IDs are
131// globally unique in the renderer.
132static int32 next_page_id_ = 1;
133
[email protected]0aa55312008-10-17 21:53:08134// The maximum number of popups that can be spawned from one page.
135static const int kMaximumNumberOfUnacknowledgedPopups = 25;
136
initial.commit09911bf2008-07-26 23:55:29137static const char* const kUnreachableWebDataURL =
[email protected]9527f9c2009-01-29 18:35:42138 "chrome-ui://chromewebdata/";
initial.commit09911bf2008-07-26 23:55:29139
[email protected]50b691c2008-10-31 19:08:35140static const char* const kBackForwardNavigationScheme = "history";
141
initial.commit09911bf2008-07-26 23:55:29142namespace {
143
144// Associated with browser-initiated navigations to hold tracking data.
145class RenderViewExtraRequestData : public WebRequest::ExtraData {
146 public:
147 RenderViewExtraRequestData(int32 pending_page_id,
[email protected]c20210e62009-04-03 21:39:26148 PageTransition::Type transition,
149 Time request_time)
[email protected]6c8afae52009-01-22 02:24:57150 : transition_type(transition),
[email protected]c20210e62009-04-03 21:39:26151 request_time(request_time),
[email protected]6c8afae52009-01-22 02:24:57152 request_committed(false),
153 pending_page_id_(pending_page_id) {
initial.commit09911bf2008-07-26 23:55:29154 }
155
156 // Contains the page_id for this navigation or -1 if there is none yet.
157 int32 pending_page_id() const { return pending_page_id_; }
158
159 // Is this a new navigation?
160 bool is_new_navigation() const { return pending_page_id_ == -1; }
161
162 // Contains the transition type that the browser specified when it
163 // initiated the load.
164 PageTransition::Type transition_type;
[email protected]c20210e62009-04-03 21:39:26165 Time request_time;
initial.commit09911bf2008-07-26 23:55:29166
167 // True if we have already processed the "DidCommitLoad" event for this
168 // request. Used by session history.
169 bool request_committed;
170
171 private:
172 int32 pending_page_id_;
173
[email protected]4f3dc372009-02-24 00:10:29174 DISALLOW_COPY_AND_ASSIGN(RenderViewExtraRequestData);
initial.commit09911bf2008-07-26 23:55:29175};
176
177} // namespace
178
179///////////////////////////////////////////////////////////////////////////////
180
[email protected]81a34412009-01-05 19:17:24181RenderView::RenderView(RenderThreadBase* render_thread)
182 : RenderWidget(render_thread, true),
[email protected]81e63782009-02-27 19:35:09183 enabled_bindings_(0),
[email protected]e75cb49e2009-01-05 23:13:21184 target_url_status_(TARGET_NONE),
[email protected]81a34412009-01-05 19:17:24185 is_loading_(false),
[email protected]e75cb49e2009-01-05 23:13:21186 navigation_gesture_(NavigationGestureUnknown),
[email protected]81a34412009-01-05 19:17:24187 page_id_(-1),
188 last_page_id_sent_to_browser_(-1),
189 last_indexed_page_id_(-1),
[email protected]81a34412009-01-05 19:17:24190 opened_by_user_gesture_(true),
[email protected]bb063b72009-03-27 23:18:50191 ALLOW_THIS_IN_INITIALIZER_LIST(method_factory_(this)),
[email protected]81a34412009-01-05 19:17:24192 first_default_plugin_(NULL),
[email protected]e4ac5df2009-03-17 15:33:11193 devtools_agent_(NULL),
194 devtools_client_(NULL),
[email protected]81a34412009-01-05 19:17:24195 history_back_list_count_(0),
196 history_forward_list_count_(0),
197 disable_popup_blocking_(false),
198 has_unload_listener_(false),
199 decrement_shared_popup_at_destruction_(false),
[email protected]81a34412009-01-05 19:17:24200 form_field_autofill_request_id_(0),
201 popup_notification_visible_(false),
202 delay_seconds_for_form_state_sync_(kDefaultDelaySecondsForFormStateSync) {
[email protected]3a453fa2008-08-15 18:46:34203#ifdef CHROME_PERSONALIZATION
204 personalization_ = Personalization::CreateRendererPersonalization();
205#endif
initial.commit09911bf2008-07-26 23:55:29206}
207
208RenderView::~RenderView() {
[email protected]0aa55312008-10-17 21:53:08209 if (decrement_shared_popup_at_destruction_)
210 shared_popup_counter_->data--;
211
initial.commit09911bf2008-07-26 23:55:29212 // Clear any back-pointers that might still be held by plugins.
213 PluginDelegateList::iterator it = plugin_delegates_.begin();
214 while (it != plugin_delegates_.end()) {
215 (*it)->DropRenderView();
216 it = plugin_delegates_.erase(it);
217 }
218
[email protected]81a34412009-01-05 19:17:24219 render_thread_->RemoveFilter(debug_message_handler_);
[email protected]5fb88962009-04-16 19:03:25220 render_thread_->RemoveFilter(audio_message_filter_);
[email protected]3a453fa2008-08-15 18:46:34221
222#ifdef CHROME_PERSONALIZATION
223 Personalization::CleanupRendererPersonalization(personalization_);
224 personalization_ = NULL;
225#endif
initial.commit09911bf2008-07-26 23:55:29226}
227
228/*static*/
[email protected]0aa55312008-10-17 21:53:08229RenderView* RenderView::Create(
[email protected]81a34412009-01-05 19:17:24230 RenderThreadBase* render_thread,
[email protected]18bcc3c2009-01-27 21:39:15231 gfx::NativeViewId parent_hwnd,
[email protected]1c4947f2009-01-15 22:25:11232 base::WaitableEvent* modal_dialog_event,
[email protected]0aa55312008-10-17 21:53:08233 int32 opener_id,
234 const WebPreferences& webkit_prefs,
235 SharedRenderViewCounter* counter,
236 int32 routing_id) {
initial.commit09911bf2008-07-26 23:55:29237 DCHECK(routing_id != MSG_ROUTING_NONE);
[email protected]81a34412009-01-05 19:17:24238 scoped_refptr<RenderView> view = new RenderView(render_thread);
initial.commit09911bf2008-07-26 23:55:29239 view->Init(parent_hwnd,
240 modal_dialog_event,
241 opener_id,
242 webkit_prefs,
[email protected]0aa55312008-10-17 21:53:08243 counter,
initial.commit09911bf2008-07-26 23:55:29244 routing_id); // adds reference
245 return view;
246}
247
248/*static*/
249void RenderView::SetNextPageID(int32 next_page_id) {
250 // This method should only be called during process startup, and the given
251 // page id had better not exceed our current next page id!
252 DCHECK(next_page_id_ == 1);
253 DCHECK(next_page_id >= next_page_id_);
254 next_page_id_ = next_page_id;
255}
256
257void RenderView::PluginDestroyed(WebPluginDelegateProxy* proxy) {
258 PluginDelegateList::iterator it =
259 std::find(plugin_delegates_.begin(), plugin_delegates_.end(), proxy);
260 DCHECK(it != plugin_delegates_.end());
261 plugin_delegates_.erase(it);
262 // If the plugin is deleted, we need to clear our reference in case user
263 // clicks the info bar to install. Unfortunately we are getting
264 // PluginDestroyed in single process mode. However, that is not a huge
265 // concern.
[email protected]6c8afae52009-01-22 02:24:57266#if defined(OS_WIN)
initial.commit09911bf2008-07-26 23:55:29267 if (proxy == first_default_plugin_)
268 first_default_plugin_ = NULL;
[email protected]6c8afae52009-01-22 02:24:57269#else
270 // TODO(port): because of the headers that we aren't including, the compiler
271 // has only seen a forward decl, not the subclass relation. Thus it doesn't
272 // know that the two pointer types compared above are comparable. Once we
273 // port and include the headers this problem should go away.
274 NOTIMPLEMENTED();
275#endif
initial.commit09911bf2008-07-26 23:55:29276}
277
[email protected]690a99c2009-01-06 16:48:45278void RenderView::PluginCrashed(const FilePath& plugin_path) {
initial.commit09911bf2008-07-26 23:55:29279 Send(new ViewHostMsg_CrashedPlugin(routing_id_, plugin_path));
280}
281
282
283void RenderView::JSOutOfMemory() {
284 Send(new ViewHostMsg_JSOutOfMemory(routing_id_));
285}
286
[email protected]18bcc3c2009-01-27 21:39:15287void RenderView::Init(gfx::NativeViewId parent_hwnd,
[email protected]1c4947f2009-01-15 22:25:11288 base::WaitableEvent* modal_dialog_event,
initial.commit09911bf2008-07-26 23:55:29289 int32 opener_id,
290 const WebPreferences& webkit_prefs,
[email protected]0aa55312008-10-17 21:53:08291 SharedRenderViewCounter* counter,
initial.commit09911bf2008-07-26 23:55:29292 int32 routing_id) {
293 DCHECK(!webview());
294
295 if (opener_id != MSG_ROUTING_NONE)
296 opener_id_ = opener_id;
297
[email protected]0aa55312008-10-17 21:53:08298 if (counter) {
299 shared_popup_counter_ = counter;
300 shared_popup_counter_->data++;
301 decrement_shared_popup_at_destruction_ = true;
302 } else {
303 shared_popup_counter_ = new SharedRenderViewCounter(0);
304 decrement_shared_popup_at_destruction_ = false;
305 }
306
[email protected]90ca3692009-04-09 16:09:43307 const CommandLine& command_line = *CommandLine::ForCurrentProcess();
308
309 bool dev_tools_enabled = command_line.HasSwitch(
310 switches::kEnableOutOfProcessDevTools);
311 if (dev_tools_enabled)
312 devtools_agent_.reset(new DevToolsAgent(routing_id, this));
[email protected]9b9d7282009-04-08 14:13:04313
[email protected]c5b3b5e2009-02-13 06:41:11314 webwidget_ = WebView::Create(this, webkit_prefs);
initial.commit09911bf2008-07-26 23:55:29315
[email protected]2e417c82009-04-02 22:30:26316#if defined(OS_LINUX)
317 // We have to enable ourselves as the editor delegate on linux so we can copy
318 // text selections to the X clipboard.
319 webview()->SetUseEditorDelegate(true);
320#endif
321
initial.commit09911bf2008-07-26 23:55:29322 // Don't let WebCore keep a B/F list - we have our own.
323 // We let it keep 1 entry because FrameLoader::goToItem expects an item in the
324 // backForwardList, which is used only in ASSERTs.
325 webview()->SetBackForwardListSize(1);
326
327 routing_id_ = routing_id;
[email protected]81a34412009-01-05 19:17:24328 render_thread_->AddRoute(routing_id_, this);
initial.commit09911bf2008-07-26 23:55:29329 // Take a reference on behalf of the RenderThread. This will be balanced
330 // when we receive ViewMsg_Close.
331 AddRef();
332
333 // If this is a popup, we must wait for the CreatingNew_ACK message before
334 // completing initialization. Otherwise, we can finish it now.
335 if (opener_id == MSG_ROUTING_NONE) {
336 did_show_ = true;
337 CompleteInit(parent_hwnd);
338 }
339
340 host_window_ = parent_hwnd;
[email protected]1c4947f2009-01-15 22:25:11341 modal_dialog_event_.reset(modal_dialog_event);
initial.commit09911bf2008-07-26 23:55:29342
[email protected]81e63782009-02-27 19:35:09343 if (command_line.HasSwitch(switches::kDomAutomationController))
344 enabled_bindings_ |= BindingsPolicy::DOM_AUTOMATION;
initial.commit09911bf2008-07-26 23:55:29345 disable_popup_blocking_ =
346 command_line.HasSwitch(switches::kDisablePopupBlocking);
347
348 debug_message_handler_ = new DebugMessageHandler(this);
[email protected]81a34412009-01-05 19:17:24349 render_thread_->AddFilter(debug_message_handler_);
[email protected]5fb88962009-04-16 19:03:25350
351 audio_message_filter_ = new AudioMessageFilter(routing_id_);
352 render_thread_->AddFilter(audio_message_filter_);
initial.commit09911bf2008-07-26 23:55:29353}
354
355void RenderView::OnMessageReceived(const IPC::Message& message) {
[email protected]f8b6b6f2009-03-10 16:48:26356 WebFrame* main_frame = webview() ? webview()->GetMainFrame() : NULL;
357 renderer_logging::ScopedActiveRenderingURLSetter url_setter(
358 main_frame ? main_frame->GetURL() : GURL());
[email protected]f8b6b6f2009-03-10 16:48:26359
[email protected]b2abac72009-02-26 12:39:28360 // If this is developer tools renderer intercept tools messages first.
[email protected]e4ac5df2009-03-17 15:33:11361 if (devtools_client_.get() && devtools_client_->OnMessageReceived(message))
[email protected]b2abac72009-02-26 12:39:28362 return;
[email protected]b4b967e2009-04-22 11:33:05363 if (devtools_agent_.get() && devtools_agent_->OnMessageReceived(message))
364 return;
[email protected]b2abac72009-02-26 12:39:28365
initial.commit09911bf2008-07-26 23:55:29366 IPC_BEGIN_MESSAGE_MAP(RenderView, message)
initial.commit09911bf2008-07-26 23:55:29367 IPC_MESSAGE_HANDLER(ViewMsg_CaptureThumbnail, SendThumbnail)
initial.commit09911bf2008-07-26 23:55:29368 IPC_MESSAGE_HANDLER(ViewMsg_PrintPages, OnPrintPages)
369 IPC_MESSAGE_HANDLER(ViewMsg_Navigate, OnNavigate)
370 IPC_MESSAGE_HANDLER(ViewMsg_Stop, OnStop)
371 IPC_MESSAGE_HANDLER(ViewMsg_LoadAlternateHTMLText, OnLoadAlternateHTMLText)
372 IPC_MESSAGE_HANDLER(ViewMsg_StopFinding, OnStopFinding)
373 IPC_MESSAGE_HANDLER(ViewMsg_Undo, OnUndo)
374 IPC_MESSAGE_HANDLER(ViewMsg_Redo, OnRedo)
375 IPC_MESSAGE_HANDLER(ViewMsg_Cut, OnCut)
376 IPC_MESSAGE_HANDLER(ViewMsg_Copy, OnCopy)
377 IPC_MESSAGE_HANDLER(ViewMsg_Paste, OnPaste)
378 IPC_MESSAGE_HANDLER(ViewMsg_Replace, OnReplace)
[email protected]bbbd545c2008-12-15 20:18:04379 IPC_MESSAGE_HANDLER(ViewMsg_ToggleSpellCheck, OnToggleSpellCheck)
initial.commit09911bf2008-07-26 23:55:29380 IPC_MESSAGE_HANDLER(ViewMsg_Delete, OnDelete)
381 IPC_MESSAGE_HANDLER(ViewMsg_SelectAll, OnSelectAll)
382 IPC_MESSAGE_HANDLER(ViewMsg_CopyImageAt, OnCopyImageAt)
383 IPC_MESSAGE_HANDLER(ViewMsg_Find, OnFind)
[email protected]630e26b2008-10-14 22:55:17384 IPC_MESSAGE_HANDLER(ViewMsg_Zoom, OnZoom)
[email protected]ea8c7452009-04-02 20:47:06385 IPC_MESSAGE_HANDLER(ViewMsg_InsertText, OnInsertText)
initial.commit09911bf2008-07-26 23:55:29386 IPC_MESSAGE_HANDLER(ViewMsg_SetPageEncoding, OnSetPageEncoding)
387 IPC_MESSAGE_HANDLER(ViewMsg_InspectElement, OnInspectElement)
388 IPC_MESSAGE_HANDLER(ViewMsg_ShowJavaScriptConsole, OnShowJavaScriptConsole)
[email protected]b2abac72009-02-26 12:39:28389 IPC_MESSAGE_HANDLER(ViewMsg_SetupDevToolsClient, OnSetupDevToolsClient)
initial.commit09911bf2008-07-26 23:55:29390 IPC_MESSAGE_HANDLER(ViewMsg_DownloadImage, OnDownloadImage)
391 IPC_MESSAGE_HANDLER(ViewMsg_ScriptEvalRequest, OnScriptEvalRequest)
[email protected]1810e132009-03-24 23:35:48392 IPC_MESSAGE_HANDLER(ViewMsg_CSSInsertRequest, OnCSSInsertRequest)
initial.commit09911bf2008-07-26 23:55:29393 IPC_MESSAGE_HANDLER(ViewMsg_AddMessageToConsole, OnAddMessageToConsole)
394 IPC_MESSAGE_HANDLER(ViewMsg_DebugAttach, OnDebugAttach)
[email protected]88010e082008-08-29 11:07:40395 IPC_MESSAGE_HANDLER(ViewMsg_DebugDetach, OnDebugDetach)
initial.commit09911bf2008-07-26 23:55:29396 IPC_MESSAGE_HANDLER(ViewMsg_ReservePageIDRange, OnReservePageIDRange)
397 IPC_MESSAGE_HANDLER(ViewMsg_UploadFile, OnUploadFileRequest)
398 IPC_MESSAGE_HANDLER(ViewMsg_FormFill, OnFormFill)
399 IPC_MESSAGE_HANDLER(ViewMsg_FillPasswordForm, OnFillPasswordForm)
400 IPC_MESSAGE_HANDLER(ViewMsg_DragTargetDragEnter, OnDragTargetDragEnter)
401 IPC_MESSAGE_HANDLER(ViewMsg_DragTargetDragOver, OnDragTargetDragOver)
402 IPC_MESSAGE_HANDLER(ViewMsg_DragTargetDragLeave, OnDragTargetDragLeave)
403 IPC_MESSAGE_HANDLER(ViewMsg_DragTargetDrop, OnDragTargetDrop)
[email protected]18cb2572008-08-21 20:34:45404 IPC_MESSAGE_HANDLER(ViewMsg_AllowBindings, OnAllowBindings)
initial.commit09911bf2008-07-26 23:55:29405 IPC_MESSAGE_HANDLER(ViewMsg_SetDOMUIProperty, OnSetDOMUIProperty)
[email protected]266eb6f2008-09-30 23:56:50406 IPC_MESSAGE_HANDLER(ViewMsg_DragSourceEndedOrMoved,
407 OnDragSourceEndedOrMoved)
initial.commit09911bf2008-07-26 23:55:29408 IPC_MESSAGE_HANDLER(ViewMsg_DragSourceSystemDragEnded,
409 OnDragSourceSystemDragEnded)
410 IPC_MESSAGE_HANDLER(ViewMsg_SetInitialFocus, OnSetInitialFocus)
411 IPC_MESSAGE_HANDLER(ViewMsg_FindReplyACK, OnFindReplyAck)
412 IPC_MESSAGE_HANDLER(ViewMsg_UpdateTargetURL_ACK, OnUpdateTargetURLAck)
413 IPC_MESSAGE_HANDLER(ViewMsg_UpdateWebPreferences, OnUpdateWebPreferences)
414 IPC_MESSAGE_HANDLER(ViewMsg_SetAltErrorPageURL, OnSetAltErrorPageURL)
415 IPC_MESSAGE_HANDLER(ViewMsg_InstallMissingPlugin, OnInstallMissingPlugin)
416 IPC_MESSAGE_HANDLER(ViewMsg_RunFileChooserResponse, OnFileChooserResponse)
417 IPC_MESSAGE_HANDLER(ViewMsg_EnableViewSourceMode, OnEnableViewSourceMode)
418 IPC_MESSAGE_HANDLER(ViewMsg_UpdateBackForwardListCount,
419 OnUpdateBackForwardListCount)
420 IPC_MESSAGE_HANDLER(ViewMsg_GetAllSavableResourceLinksForCurrentPage,
421 OnGetAllSavableResourceLinksForCurrentPage)
[email protected]f09c7182009-03-10 12:54:04422 IPC_MESSAGE_HANDLER(
423 ViewMsg_GetSerializedHtmlDataForCurrentPageWithLocalLinks,
424 OnGetSerializedHtmlDataForCurrentPageWithLocalLinks)
initial.commit09911bf2008-07-26 23:55:29425 IPC_MESSAGE_HANDLER(ViewMsg_GetApplicationInfo, OnGetApplicationInfo)
[email protected]266eb6f2008-09-30 23:56:50426 IPC_MESSAGE_HANDLER(ViewMsg_GetAccessibilityInfo, OnGetAccessibilityInfo)
427 IPC_MESSAGE_HANDLER(ViewMsg_ClearAccessibilityInfo,
428 OnClearAccessibilityInfo)
initial.commit09911bf2008-07-26 23:55:29429 IPC_MESSAGE_HANDLER(ViewMsg_ShouldClose, OnMsgShouldClose)
430 IPC_MESSAGE_HANDLER(ViewMsg_ClosePage, OnClosePage)
431 IPC_MESSAGE_HANDLER(ViewMsg_ThemeChanged, OnThemeChanged)
[email protected]3c17b9c2008-08-26 02:08:00432#ifdef CHROME_PERSONALIZATION
[email protected]1cc879642008-08-26 01:27:35433 IPC_MESSAGE_HANDLER(ViewMsg_PersonalizationEvent, OnPersonalizationEvent)
[email protected]3c17b9c2008-08-26 02:08:00434#endif
[email protected]18cb2572008-08-21 20:34:45435 IPC_MESSAGE_HANDLER(ViewMsg_HandleMessageFromExternalHost,
436 OnMessageFromExternalHost)
[email protected]0aa55312008-10-17 21:53:08437 IPC_MESSAGE_HANDLER(ViewMsg_DisassociateFromPopupCount,
438 OnDisassociateFromPopupCount)
[email protected]0ebf3872008-11-07 21:35:03439 IPC_MESSAGE_HANDLER(ViewMsg_AutofillSuggestions,
440 OnReceivedAutofillSuggestions)
[email protected]634a6f92008-12-01 21:39:31441 IPC_MESSAGE_HANDLER(ViewMsg_PopupNotificationVisiblityChanged,
442 OnPopupNotificationVisiblityChanged)
[email protected]30f75e62009-02-25 22:01:00443 IPC_MESSAGE_HANDLER(ViewMsg_MoveOrResizeStarted, OnMoveOrResizeStarted)
[email protected]309d7a282009-03-24 09:18:27444 IPC_MESSAGE_HANDLER(ViewMsg_ExtensionResponse, OnExtensionResponse)
[email protected]05d478752009-04-08 23:38:16445 IPC_MESSAGE_HANDLER(ViewMsg_ClearFocusedNode, OnClearFocusedNode)
[email protected]634a6f92008-12-01 21:39:31446
initial.commit09911bf2008-07-26 23:55:29447 // Have the super handle all other messages.
448 IPC_MESSAGE_UNHANDLED(RenderWidget::OnMessageReceived(message))
449 IPC_END_MESSAGE_MAP()
450}
451
initial.commit09911bf2008-07-26 23:55:29452void RenderView::SendThumbnail() {
453 WebFrame* main_frame = webview()->GetMainFrame();
454 if (!main_frame)
455 return;
456
457 // get the URL for this page
458 GURL url(main_frame->GetURL());
459 if (url.is_empty())
460 return;
461
462 if (size_.IsEmpty())
463 return; // Don't create an empty thumbnail!
464
465 ThumbnailScore score;
466 SkBitmap thumbnail;
[email protected]b6e4bec2008-11-12 01:17:15467 if (!CaptureThumbnail(main_frame, kThumbnailWidth, kThumbnailHeight,
468 &thumbnail, &score))
469 return;
470
initial.commit09911bf2008-07-26 23:55:29471 // send the thumbnail message to the browser process
[email protected]674741932009-02-04 23:44:46472 Send(new ViewHostMsg_Thumbnail(routing_id_, url, score, thumbnail));
initial.commit09911bf2008-07-26 23:55:29473}
474
initial.commit09911bf2008-07-26 23:55:29475void RenderView::PrintPage(const ViewMsg_PrintPage_Params& params,
[email protected]88a3ecc2009-03-19 17:36:22476 const gfx::Size& canvas_size,
initial.commit09911bf2008-07-26 23:55:29477 WebFrame* frame) {
[email protected]6c8afae52009-01-22 02:24:57478#if defined(OS_WIN)
initial.commit09911bf2008-07-26 23:55:29479 // Generate a memory-based EMF file. The EMF will use the current screen's
480 // DPI.
481 gfx::Emf emf;
482
483 emf.CreateDc(NULL, NULL);
484 HDC hdc = emf.hdc();
485 DCHECK(hdc);
[email protected]21f527e2008-12-17 23:29:40486 skia::PlatformDeviceWin::InitializeDC(hdc);
[email protected]0e92fa32009-03-31 20:39:33487 // Since WebKit extends the page width depending on the magical shrink
[email protected]0dea3ea2009-03-31 23:30:59488 // factor we make sure the canvas covers the worst case scenario
[email protected]0e92fa32009-03-31 20:39:33489 // (x2.0 currently). PrintContext will then set the correct clipping region.
490 int size_x = static_cast<int>(canvas_size.width() * params.params.max_shrink);
491 int size_y = static_cast<int>(canvas_size.height() *
492 params.params.max_shrink);
[email protected]88a3ecc2009-03-19 17:36:22493 // Calculate the dpi adjustment.
494 float shrink = static_cast<float>(canvas_size.width()) /
495 params.params.printable_size.width();
initial.commit09911bf2008-07-26 23:55:29496#if 0
497 // TODO(maruel): This code is kept for testing until the 100% GDI drawing
498 // code is stable. maruels use this code's output as a reference when the
499 // GDI drawing code fails.
500
501 // Mix of Skia and GDI based.
[email protected]88a3ecc2009-03-19 17:36:22502 skia::PlatformCanvasWin canvas(size_x, size_y, true);
initial.commit09911bf2008-07-26 23:55:29503 canvas.drawARGB(255, 255, 255, 255, SkPorterDuff::kSrc_Mode);
[email protected]88a3ecc2009-03-19 17:36:22504 float webkit_shrink = frame->PrintPage(params.page_number, &canvas);
505 if (shrink <= 0) {
initial.commit09911bf2008-07-26 23:55:29506 NOTREACHED() << "Printing page " << params.page_number << " failed.";
[email protected]88a3ecc2009-03-19 17:36:22507 } else {
508 // Update the dpi adjustment with the "page shrink" calculated in webkit.
509 shrink /= webkit_shrink;
initial.commit09911bf2008-07-26 23:55:29510 }
511
512 // Create a BMP v4 header that we can serialize.
513 BITMAPV4HEADER bitmap_header;
[email protected]88a3ecc2009-03-19 17:36:22514 gfx::CreateBitmapV4Header(size_x, size_y, &bitmap_header);
initial.commit09911bf2008-07-26 23:55:29515 const SkBitmap& src_bmp = canvas.getDevice()->accessBitmap(true);
516 SkAutoLockPixels src_lock(src_bmp);
517 int retval = StretchDIBits(hdc,
518 0,
519 0,
[email protected]88a3ecc2009-03-19 17:36:22520 size_x, size_y,
initial.commit09911bf2008-07-26 23:55:29521 0, 0,
[email protected]88a3ecc2009-03-19 17:36:22522 size_x, size_y,
initial.commit09911bf2008-07-26 23:55:29523 src_bmp.getPixels(),
524 reinterpret_cast<BITMAPINFO*>(&bitmap_header),
525 DIB_RGB_COLORS,
526 SRCCOPY);
527 DCHECK(retval != GDI_ERROR);
528#else
529 // 100% GDI based.
[email protected]88a3ecc2009-03-19 17:36:22530 skia::VectorCanvas canvas(hdc, size_x, size_y);
531 float webkit_shrink = frame->PrintPage(params.page_number, &canvas);
532 if (shrink <= 0) {
initial.commit09911bf2008-07-26 23:55:29533 NOTREACHED() << "Printing page " << params.page_number << " failed.";
[email protected]88a3ecc2009-03-19 17:36:22534 } else {
535 // Update the dpi adjustment with the "page shrink" calculated in webkit.
536 shrink /= webkit_shrink;
initial.commit09911bf2008-07-26 23:55:29537 }
538#endif
539
540 // Done printing. Close the device context to retrieve the compiled EMF.
541 if (!emf.CloseDc()) {
542 NOTREACHED() << "EMF failed";
543 }
544
545 // Get the size of the compiled EMF.
546 unsigned buf_size = emf.GetDataSize();
547 DCHECK(buf_size > 128);
548 ViewHostMsg_DidPrintPage_Params page_params;
549 page_params.data_size = 0;
550 page_params.emf_data_handle = NULL;
551 page_params.page_number = params.page_number;
552 page_params.document_cookie = params.params.document_cookie;
553 page_params.actual_shrink = shrink;
[email protected]176aa482008-11-14 03:25:15554 base::SharedMemory shared_buf;
initial.commit09911bf2008-07-26 23:55:29555
556 // http://msdn2.microsoft.com/en-us/library/ms535522.aspx
557 // Windows 2000/XP: When a page in a spooled file exceeds approximately 350
558 // MB, it can fail to print and not send an error message.
559 if (buf_size < 350*1024*1024) {
560 // Allocate a shared memory buffer to hold the generated EMF data.
561 if (shared_buf.Create(L"", false, false, buf_size) &&
562 shared_buf.Map(buf_size)) {
563 // Copy the bits into shared memory.
564 if (emf.GetData(shared_buf.memory(), buf_size)) {
565 page_params.emf_data_handle = shared_buf.handle();
566 page_params.data_size = buf_size;
567 } else {
568 NOTREACHED() << "GetData() failed";
569 }
570 shared_buf.Unmap();
571 } else {
572 NOTREACHED() << "Buffer allocation failed";
573 }
574 } else {
575 NOTREACHED() << "Buffer too large: " << buf_size;
576 }
577 emf.CloseEmf();
578 if (Send(new ViewHostMsg_DuplicateSection(routing_id_,
579 page_params.emf_data_handle,
580 &page_params.emf_data_handle))) {
581 Send(new ViewHostMsg_DidPrintPage(routing_id_, page_params));
582 }
[email protected]6c8afae52009-01-22 02:24:57583#else // defined(OS_WIN)
584 // TODO(port) implement printing
585 NOTIMPLEMENTED();
586#endif
initial.commit09911bf2008-07-26 23:55:29587}
588
[email protected]068637222009-01-29 16:58:07589void RenderView::OnPrintPages() {
initial.commit09911bf2008-07-26 23:55:29590 DCHECK(webview());
[email protected]068637222009-01-29 16:58:07591 if (webview()) {
592 // The renderer own the control flow as if it was a window.print() call.
593 ScriptedPrint(webview()->GetMainFrame());
initial.commit09911bf2008-07-26 23:55:29594 }
initial.commit09911bf2008-07-26 23:55:29595}
596
597void RenderView::PrintPages(const ViewMsg_PrintPages_Params& params,
598 WebFrame* frame) {
[email protected]88a3ecc2009-03-19 17:36:22599 int page_count = 0;
600 gfx::Size canvas_size;
601 canvas_size.set_width(
602 printing::ConvertUnit(params.params.printable_size.width(),
603 static_cast<int>(params.params.dpi),
604 params.params.desired_dpi));
605 canvas_size.set_height(
606 printing::ConvertUnit(params.params.printable_size.height(),
607 static_cast<int>(params.params.dpi),
608 params.params.desired_dpi));
609 frame->BeginPrint(canvas_size, &page_count);
initial.commit09911bf2008-07-26 23:55:29610 Send(new ViewHostMsg_DidGetPrintedPagesCount(routing_id_,
611 params.params.document_cookie,
[email protected]88a3ecc2009-03-19 17:36:22612 page_count));
613 if (page_count) {
initial.commit09911bf2008-07-26 23:55:29614 ViewMsg_PrintPage_Params page_params;
615 page_params.params = params.params;
616 if (params.pages.empty()) {
[email protected]88a3ecc2009-03-19 17:36:22617 for (int i = 0; i < page_count; ++i) {
initial.commit09911bf2008-07-26 23:55:29618 page_params.page_number = i;
[email protected]88a3ecc2009-03-19 17:36:22619 PrintPage(page_params, canvas_size, frame);
initial.commit09911bf2008-07-26 23:55:29620 }
621 } else {
622 for (size_t i = 0; i < params.pages.size(); ++i) {
623 page_params.page_number = params.pages[i];
[email protected]88a3ecc2009-03-19 17:36:22624 PrintPage(page_params, canvas_size, frame);
initial.commit09911bf2008-07-26 23:55:29625 }
626 }
627 }
[email protected]88a3ecc2009-03-19 17:36:22628 frame->EndPrint();
initial.commit09911bf2008-07-26 23:55:29629}
630
631void RenderView::CapturePageInfo(int load_id, bool preliminary_capture) {
632 if (load_id != page_id_)
633 return; // this capture call is no longer relevant due to navigation
634 if (load_id == last_indexed_page_id_)
635 return; // we already indexed this page
636
637 if (!webview())
638 return;
639
640 WebFrame* main_frame = webview()->GetMainFrame();
641 if (!main_frame)
642 return;
643
644 // Don't index/capture pages that are in view source mode.
645 if (main_frame->GetInViewSourceMode())
646 return;
647
648 // Don't index/capture pages that failed to load. This only checks the top
649 // level frame so the thumbnail may contain a frame that failed to load.
650 WebDataSource* ds = main_frame->GetDataSource();
651 if (ds && ds->HasUnreachableURL())
652 return;
653
654 if (!preliminary_capture)
655 last_indexed_page_id_ = load_id;
656
657 // get the URL for this page
658 GURL url(main_frame->GetURL());
659 if (url.is_empty())
660 return;
661
662 // full text
663 std::wstring contents;
664 CaptureText(main_frame, &contents);
665 if (contents.size()) {
666 // Send the text to the browser for indexing.
667 Send(new ViewHostMsg_PageContents(url, load_id, contents));
668 }
669
670 // thumbnail
671 SendThumbnail();
672}
673
674void RenderView::CaptureText(WebFrame* frame, std::wstring* contents) {
675 contents->clear();
676 if (!frame)
677 return;
678
[email protected]0faf0bd92008-09-09 20:53:27679 // Don't index any https pages. People generally don't want their bank
680 // accounts, etc. indexed on their computer, especially since some of these
681 // things are not marked cachable.
682 // TODO(brettw) we may want to consider more elaborate heuristics such as
683 // the cachability of the page. We may also want to consider subframes (this
684 // test will still index subframes if the subframe is SSL).
685 if (frame->GetURL().SchemeIsSecure())
686 return;
687
initial.commit09911bf2008-07-26 23:55:29688#ifdef TIME_TEXT_RETRIEVAL
689 double begin = time_util::GetHighResolutionTimeNow();
690#endif
691
692 // get the contents of the frame
693 frame->GetContentAsPlainText(kMaxIndexChars, contents);
694
695#ifdef TIME_TEXT_RETRIEVAL
696 double end = time_util::GetHighResolutionTimeNow();
697 char buf[128];
698 sprintf_s(buf, "%d chars retrieved for indexing in %gms\n",
699 contents.size(), (end - begin)*1000);
700 OutputDebugStringA(buf);
701#endif
702
703 // When the contents are clipped to the maximum, we don't want to have a
704 // partial word indexed at the end that might have been clipped. Therefore,
705 // terminate the string at the last space to ensure no words are clipped.
706 if (contents->size() == kMaxIndexChars) {
707 size_t last_space_index = contents->find_last_of(kWhitespaceWide);
708 if (last_space_index == std::wstring::npos)
709 return; // don't index if we got a huge block of text with no spaces
710 contents->resize(last_space_index);
711 }
712}
713
[email protected]b6e4bec2008-11-12 01:17:15714bool RenderView::CaptureThumbnail(WebFrame* frame,
initial.commit09911bf2008-07-26 23:55:29715 int w,
716 int h,
717 SkBitmap* thumbnail,
718 ThumbnailScore* score) {
719#ifdef TIME_BITMAP_RETRIEVAL
720 double begin = time_util::GetHighResolutionTimeNow();
721#endif
722
[email protected]21f527e2008-12-17 23:29:40723 scoped_ptr<skia::BitmapPlatformDevice> device;
[email protected]b6e4bec2008-11-12 01:17:15724 if (!frame->CaptureImage(&device, true))
725 return false;
726
727 const SkBitmap& src_bmp = device->accessBitmap(false);
initial.commit09911bf2008-07-26 23:55:29728
729 SkRect dest_rect;
730 dest_rect.set(0, 0, SkIntToScalar(w), SkIntToScalar(h));
731 float dest_aspect = dest_rect.width() / dest_rect.height();
732
733 // Get the src rect so that we can preserve the aspect ratio while filling
734 // the destination.
735 SkIRect src_rect;
736 if (src_bmp.width() < dest_rect.width() ||
737 src_bmp.height() < dest_rect.height()) {
738 // Source image is smaller: we clip the part of source image within the
739 // dest rect, and then stretch it to fill the dest rect. We don't respect
740 // the aspect ratio in this case.
741 src_rect.set(0, 0, static_cast<S16CPU>(dest_rect.width()),
742 static_cast<S16CPU>(dest_rect.height()));
743 score->good_clipping = false;
744 } else {
745 float src_aspect = static_cast<float>(src_bmp.width()) / src_bmp.height();
746 if (src_aspect > dest_aspect) {
747 // Wider than tall, clip horizontally: we center the smaller thumbnail in
748 // the wider screen.
749 S16CPU new_width = static_cast<S16CPU>(src_bmp.height() * dest_aspect);
750 S16CPU x_offset = (src_bmp.width() - new_width) / 2;
751 src_rect.set(x_offset, 0, new_width + x_offset, src_bmp.height());
752 score->good_clipping = false;
753 } else {
754 src_rect.set(0, 0, src_bmp.width(),
755 static_cast<S16CPU>(src_bmp.width() / dest_aspect));
756 score->good_clipping = true;
757 }
758 }
759
[email protected]b3f2b912009-04-09 16:18:52760 score->at_top = (frame->ScrollOffset().height == 0);
initial.commit09911bf2008-07-26 23:55:29761
762 SkBitmap subset;
[email protected]b6e4bec2008-11-12 01:17:15763 device->accessBitmap(false).extractSubset(&subset, src_rect);
initial.commit09911bf2008-07-26 23:55:29764
765 // Resample the subset that we want to get it the right size.
[email protected]465b34b72008-12-12 20:19:14766 *thumbnail = skia::ImageOperations::Resize(
767 subset, skia::ImageOperations::RESIZE_LANCZOS3, w, h);
initial.commit09911bf2008-07-26 23:55:29768
769 score->boring_score = CalculateBoringScore(thumbnail);
770
771#ifdef TIME_BITMAP_RETRIEVAL
772 double end = time_util::GetHighResolutionTimeNow();
773 char buf[128];
774 sprintf_s(buf, "thumbnail in %gms\n", (end - begin) * 1000);
775 OutputDebugStringA(buf);
776#endif
[email protected]b6e4bec2008-11-12 01:17:15777 return true;
initial.commit09911bf2008-07-26 23:55:29778}
779
780double RenderView::CalculateBoringScore(SkBitmap* bitmap) {
781 int histogram[256] = {0};
782 color_utils::BuildLumaHistogram(bitmap, histogram);
783
784 int color_count = *std::max_element(histogram, histogram + 256);
785 int pixel_count = bitmap->width() * bitmap->height();
786 return static_cast<double>(color_count) / pixel_count;
787}
788
789void RenderView::OnNavigate(const ViewMsg_Navigate_Params& params) {
790 if (!webview())
791 return;
792
[email protected]f8b6b6f2009-03-10 16:48:26793 renderer_logging::ScopedActiveRenderingURLSetter url_setter(params.url);
[email protected]f8b6b6f2009-03-10 16:48:26794
initial.commit09911bf2008-07-26 23:55:29795 AboutHandler::MaybeHandle(params.url);
796
797 bool is_reload = params.reload;
798
799 WebFrame* main_frame = webview()->GetMainFrame();
[email protected]606843fa2008-12-02 19:08:56800 if (is_reload && !main_frame->HasCurrentHistoryState()) {
initial.commit09911bf2008-07-26 23:55:29801 // We cannot reload if we do not have any history state. This happens, for
802 // example, when recovering from a crash. Our workaround here is a bit of
803 // a hack since it means that reload after a crashed tab does not cause an
804 // end-to-end cache validation.
805 is_reload = false;
806 }
807
808 WebRequestCachePolicy cache_policy;
809 if (is_reload) {
810 cache_policy = WebRequestReloadIgnoringCacheData;
811 } else if (params.page_id != -1 || main_frame->GetInViewSourceMode()) {
812 cache_policy = WebRequestReturnCacheDataElseLoad;
813 } else {
814 cache_policy = WebRequestUseProtocolCachePolicy;
815 }
816
817 scoped_ptr<WebRequest> request(WebRequest::Create(params.url));
818 request->SetCachePolicy(cache_policy);
819 request->SetExtraData(new RenderViewExtraRequestData(
[email protected]c20210e62009-04-03 21:39:26820 params.page_id, params.transition, params.request_time));
initial.commit09911bf2008-07-26 23:55:29821
822 // If we are reloading, then WebKit will use the state of the current page.
823 // Otherwise, we give it the state to navigate to.
824 if (!is_reload)
825 request->SetHistoryState(params.state);
826
[email protected]4c6f2c92008-10-28 20:26:15827 if (params.referrer.is_valid()) {
[email protected]8e3c1a72008-11-25 01:13:32828 request->SetHttpHeaderValue("Referer",
829 params.referrer.spec());
[email protected]c0588052008-10-27 23:01:50830 }
831
initial.commit09911bf2008-07-26 23:55:29832 main_frame->LoadRequest(request.get());
833}
834
835// Stop loading the current page
836void RenderView::OnStop() {
837 if (webview())
838 webview()->StopLoading();
839}
840
841void RenderView::OnLoadAlternateHTMLText(const std::string& html_contents,
842 bool new_navigation,
843 const GURL& display_url,
844 const std::string& security_info) {
845 if (!webview())
846 return;
847
848 scoped_ptr<WebRequest> request(WebRequest::Create(
849 GURL(kUnreachableWebDataURL)));
850 request->SetSecurityInfo(security_info);
851
852 webview()->GetMainFrame()->LoadAlternateHTMLString(request.get(),
853 html_contents,
854 display_url,
855 !new_navigation);
856}
857
858void RenderView::OnCopyImageAt(int x, int y) {
859 webview()->CopyImageAt(x, y);
860}
861
862void RenderView::OnInspectElement(int x, int y) {
863 webview()->InspectElement(x, y);
864}
865
866void RenderView::OnShowJavaScriptConsole() {
867 webview()->ShowJavaScriptConsole();
868}
869
[email protected]b2abac72009-02-26 12:39:28870void RenderView::OnSetupDevToolsClient() {
[email protected]e4ac5df2009-03-17 15:33:11871 DCHECK(!devtools_client_.get());
872 devtools_client_.reset(new DevToolsClient(this));
[email protected]b2abac72009-02-26 12:39:28873}
874
initial.commit09911bf2008-07-26 23:55:29875void RenderView::OnStopFinding(bool clear_selection) {
876 WebView* view = webview();
877 if (!view)
878 return;
879
880 if (clear_selection)
881 view->GetFocusedFrame()->ClearSelection();
882
883 WebFrame* frame = view->GetMainFrame();
884 while (frame) {
[email protected]65134c432008-09-26 21:47:20885 frame->StopFinding(clear_selection);
initial.commit09911bf2008-07-26 23:55:29886 frame = view->GetNextFrameAfter(frame, false);
887 }
888}
889
890void RenderView::OnFindReplyAck() {
891 // Check if there is any queued up request waiting to be sent.
892 if (queued_find_reply_message_.get()) {
893 // Send the search result over to the browser process.
894 Send(queued_find_reply_message_.get());
895 queued_find_reply_message_.release();
896 }
897}
898
899void RenderView::OnUpdateTargetURLAck() {
900 // Check if there is a targeturl waiting to be sent.
901 if (target_url_status_ == TARGET_PENDING) {
902 Send(new ViewHostMsg_UpdateTargetURL(routing_id_, page_id_,
903 pending_target_url_));
904 }
905
906 target_url_status_ = TARGET_NONE;
907}
908
909void RenderView::OnUndo() {
910 if (!webview())
911 return;
912
913 webview()->GetFocusedFrame()->Undo();
914}
915
916void RenderView::OnRedo() {
917 if (!webview())
918 return;
919
920 webview()->GetFocusedFrame()->Redo();
921}
922
923void RenderView::OnCut() {
924 if (!webview())
925 return;
926
927 webview()->GetFocusedFrame()->Cut();
928}
929
930void RenderView::OnCopy() {
931 if (!webview())
932 return;
933
934 webview()->GetFocusedFrame()->Copy();
935}
936
937void RenderView::OnPaste() {
938 if (!webview())
939 return;
940
941 webview()->GetFocusedFrame()->Paste();
942}
943
944void RenderView::OnReplace(const std::wstring& text) {
945 if (!webview())
946 return;
947
948 webview()->GetFocusedFrame()->Replace(text);
949}
950
[email protected]bbbd545c2008-12-15 20:18:04951void RenderView::OnToggleSpellCheck() {
952 if (!webview())
953 return;
954
955 webview()->GetFocusedFrame()->ToggleSpellCheck();
956}
957
initial.commit09911bf2008-07-26 23:55:29958void RenderView::OnDelete() {
959 if (!webview())
960 return;
961
962 webview()->GetFocusedFrame()->Delete();
963}
964
965void RenderView::OnSelectAll() {
966 if (!webview())
967 return;
968
969 webview()->GetFocusedFrame()->SelectAll();
970}
971
972void RenderView::OnSetInitialFocus(bool reverse) {
973 if (!webview())
974 return;
975 webview()->SetInitialFocus(reverse);
976}
977
978///////////////////////////////////////////////////////////////////////////////
979
980// Tell the embedding application that the URL of the active page has changed
981void RenderView::UpdateURL(WebFrame* frame) {
982 WebDataSource* ds = frame->GetDataSource();
983 DCHECK(ds);
984
985 const WebRequest& request = ds->GetRequest();
986 const WebRequest& initial_request = ds->GetInitialRequest();
987 const WebResponse& response = ds->GetResponse();
988
989 // We don't hold a reference to the extra data. The request's reference will
990 // be sufficient because we won't modify it during our call. MAY BE NULL.
991 RenderViewExtraRequestData* extra_data =
992 static_cast<RenderViewExtraRequestData*>(request.GetExtraData());
993
994 ViewHostMsg_FrameNavigate_Params params;
[email protected]2e39d2e2009-02-19 18:41:31995 params.http_status_code = response.GetHttpStatusCode();
initial.commit09911bf2008-07-26 23:55:29996 params.is_post = false;
997 params.page_id = page_id_;
[email protected]8a3422c92008-09-24 17:42:42998 params.is_content_filtered = response.IsContentFiltered();
initial.commit09911bf2008-07-26 23:55:29999 if (!request.GetSecurityInfo().empty()) {
1000 // SSL state specified in the request takes precedence over the one in the
1001 // response.
1002 // So far this is only intended for error pages that are not expected to be
1003 // over ssl, so we should not get any clash.
1004 DCHECK(response.GetSecurityInfo().empty());
1005 params.security_info = request.GetSecurityInfo();
1006 } else {
1007 params.security_info = response.GetSecurityInfo();
1008 }
1009
1010 // Set the URL to be displayed in the browser UI to the user.
1011 if (ds->HasUnreachableURL()) {
1012 params.url = ds->GetUnreachableURL();
1013 } else {
1014 params.url = request.GetURL();
1015 }
1016
1017 params.redirects = ds->GetRedirectChain();
1018 params.should_update_history = !ds->HasUnreachableURL();
1019
1020 const SearchableFormData* searchable_form_data =
1021 frame->GetDataSource()->GetSearchableFormData();
1022 if (searchable_form_data) {
1023 params.searchable_form_url = searchable_form_data->url();
1024 params.searchable_form_element_name = searchable_form_data->element_name();
1025 params.searchable_form_encoding = searchable_form_data->encoding();
1026 }
1027
1028 const PasswordForm* password_form_data =
1029 frame->GetDataSource()->GetPasswordFormData();
1030 if (password_form_data)
1031 params.password_form = *password_form_data;
1032
1033 params.gesture = navigation_gesture_;
1034 navigation_gesture_ = NavigationGestureUnknown;
1035
1036 if (webview()->GetMainFrame() == frame) {
1037 // Top-level navigation.
1038
1039 // Update contents MIME type for main frame.
[email protected]9d806f52009-03-12 22:50:541040 params.contents_mime_type = ds->GetResponse().GetMimeType();
initial.commit09911bf2008-07-26 23:55:291041
1042 // We assume top level navigations initiated by the renderer are link
1043 // clicks.
1044 params.transition = extra_data ?
1045 extra_data->transition_type : PageTransition::LINK;
1046 if (!PageTransition::IsMainFrame(params.transition)) {
1047 // If the main frame does a load, it should not be reported as a subframe
1048 // navigation. This can occur in the following case:
1049 // 1. You're on a site with frames.
1050 // 2. You do a subframe navigation. This is stored with transition type
1051 // MANUAL_SUBFRAME.
1052 // 3. You navigate to some non-frame site, say, google.com.
1053 // 4. You navigate back to the page from step 2. Since it was initially
1054 // MANUAL_SUBFRAME, it will be that same transition type here.
1055 // We don't want that, because any navigation that changes the toplevel
1056 // frame should be tracked as a toplevel navigation (this allows us to
1057 // update the URL bar, etc).
1058 params.transition = PageTransition::LINK;
1059 }
1060
1061 if (params.transition == PageTransition::LINK &&
1062 frame->GetDataSource()->IsFormSubmit()) {
1063 params.transition = PageTransition::FORM_SUBMIT;
1064 }
1065
1066 // If we have a valid consumed client redirect source,
1067 // the page contained a client redirect (meta refresh, document.loc...),
1068 // so we set the referrer and transition to match.
1069 if (completed_client_redirect_src_.is_valid()) {
[email protected]77e09a92008-08-01 18:11:041070 DCHECK(completed_client_redirect_src_ == params.redirects[0]);
initial.commit09911bf2008-07-26 23:55:291071 params.referrer = completed_client_redirect_src_;
1072 params.transition = static_cast<PageTransition::Type>(
1073 params.transition | PageTransition::CLIENT_REDIRECT);
1074 } else {
1075 // Bug 654101: the referrer will be empty on https->http transitions. It
1076 // would be nice if we could get the real referrer from somewhere.
1077 params.referrer = GURL(initial_request.GetHttpReferrer());
1078 }
1079
[email protected]8e3c1a72008-11-25 01:13:321080 std::string method = request.GetHttpMethod();
1081 if (method == "POST")
initial.commit09911bf2008-07-26 23:55:291082 params.is_post = true;
1083
1084 Send(new ViewHostMsg_FrameNavigate(routing_id_, params));
1085 } else {
1086 // Subframe navigation: the type depends on whether this navigation
1087 // generated a new session history entry. When they do generate a session
1088 // history entry, it means the user initiated the navigation and we should
1089 // mark it as such. This test checks if this is the first time UpdateURL
1090 // has been called since WillNavigateToURL was called to initiate the load.
1091 if (page_id_ > last_page_id_sent_to_browser_)
1092 params.transition = PageTransition::MANUAL_SUBFRAME;
1093 else
1094 params.transition = PageTransition::AUTO_SUBFRAME;
1095
1096 // The browser should never initiate a subframe navigation.
1097 DCHECK(!extra_data);
1098 Send(new ViewHostMsg_FrameNavigate(routing_id_, params));
1099 }
1100
1101 last_page_id_sent_to_browser_ =
1102 std::max(last_page_id_sent_to_browser_, page_id_);
1103
1104 // If we end up reusing this WebRequest (for example, due to a #ref click),
1105 // we don't want the transition type to persist.
1106 if (extra_data)
1107 extra_data->transition_type = PageTransition::LINK; // Just clear it.
[email protected]266eb6f2008-09-30 23:56:501108
[email protected]6c8afae52009-01-22 02:24:571109#if defined(OS_WIN)
[email protected]6a983b42009-03-20 20:12:251110 if (web_accessibility_manager_.get()) {
[email protected]be645db2009-02-06 20:36:331111 // Clear accessibility info cache.
[email protected]6a983b42009-03-20 20:12:251112 web_accessibility_manager_->ClearAccObjMap(-1, true);
[email protected]266eb6f2008-09-30 23:56:501113 }
[email protected]6c8afae52009-01-22 02:24:571114#else
[email protected]7d926f92009-03-03 14:26:541115 // TODO(port): accessibility not yet implemented. See http://crbug.com/8288.
[email protected]6c8afae52009-01-22 02:24:571116#endif
initial.commit09911bf2008-07-26 23:55:291117}
1118
1119// Tell the embedding application that the title of the active page has changed
1120void RenderView::UpdateTitle(WebFrame* frame, const std::wstring& title) {
1121 // Ignore all but top level navigations...
1122 if (webview()->GetMainFrame() == frame)
1123 Send(new ViewHostMsg_UpdateTitle(routing_id_, page_id_, title));
1124}
1125
1126void RenderView::UpdateEncoding(WebFrame* frame,
[email protected]e38f40152008-09-12 23:08:301127 const std::wstring& encoding_name) {
initial.commit09911bf2008-07-26 23:55:291128 // Only update main frame's encoding_name.
1129 if (webview()->GetMainFrame() == frame &&
1130 last_encoding_name_ != encoding_name) {
[email protected]e38f40152008-09-12 23:08:301131 // Save the encoding name for later comparing.
initial.commit09911bf2008-07-26 23:55:291132 last_encoding_name_ = encoding_name;
1133
[email protected]e38f40152008-09-12 23:08:301134 Send(new ViewHostMsg_UpdateEncoding(routing_id_, last_encoding_name_));
initial.commit09911bf2008-07-26 23:55:291135 }
1136}
1137
[email protected]f4d34b52008-11-24 23:05:011138// Sends the previous session history state to the browser so it will be saved
1139// before we navigate to a new page. This must be called *before* the page ID
1140// has been updated so we know what it was.
initial.commit09911bf2008-07-26 23:55:291141void RenderView::UpdateSessionHistory(WebFrame* frame) {
1142 // If we have a valid page ID at this point, then it corresponds to the page
1143 // we are navigating away from. Otherwise, this is the first navigation, so
1144 // there is no past session history to record.
1145 if (page_id_ == -1)
1146 return;
1147
initial.commit09911bf2008-07-26 23:55:291148 std::string state;
[email protected]606843fa2008-12-02 19:08:561149 if (!webview()->GetMainFrame()->GetPreviousHistoryState(&state))
initial.commit09911bf2008-07-26 23:55:291150 return;
[email protected]606843fa2008-12-02 19:08:561151 Send(new ViewHostMsg_UpdateState(routing_id_, page_id_, state));
initial.commit09911bf2008-07-26 23:55:291152}
1153
1154///////////////////////////////////////////////////////////////////////////////
1155// WebViewDelegate
1156
1157void RenderView::DidStartLoading(WebView* webview) {
1158 if (is_loading_) {
1159 DLOG(WARNING) << "DidStartLoading called while loading";
1160 return;
1161 }
1162
1163 is_loading_ = true;
1164 // Clear the pointer so that we can assign it only when there is an unknown
1165 // plugin on a page.
1166 first_default_plugin_ = NULL;
1167
1168 Send(new ViewHostMsg_DidStartLoading(routing_id_, page_id_));
1169}
1170
1171void RenderView::DidStopLoading(WebView* webview) {
1172 if (!is_loading_) {
1173 DLOG(WARNING) << "DidStopLoading called while not loading";
1174 return;
1175 }
1176
1177 is_loading_ = false;
1178
1179 // NOTE: For now we're doing the safest thing, and sending out notification
1180 // when done loading. This currently isn't an issue as the favicon is only
1181 // displayed when done loading. Ideally we would send notification when
1182 // finished parsing the head, but webkit doesn't support that yet.
1183 // The feed discovery code would also benefit from access to the head.
1184 GURL favicon_url(webview->GetMainFrame()->GetFavIconURL());
1185 if (!favicon_url.is_empty())
1186 Send(new ViewHostMsg_UpdateFavIconURL(routing_id_, page_id_, favicon_url));
1187
1188 AddGURLSearchProvider(webview->GetMainFrame()->GetOSDDURL(),
1189 true); // autodetected
1190
1191 Send(new ViewHostMsg_DidStopLoading(routing_id_, page_id_));
1192
1193 MessageLoop::current()->PostDelayedTask(FROM_HERE,
1194 method_factory_.NewRunnableMethod(&RenderView::CapturePageInfo, page_id_,
1195 false),
1196 kDelayForCaptureMs);
1197
1198 // The page is loaded. Try to process the file we need to upload if any.
1199 ProcessPendingUpload();
1200
1201 // Since the page is done loading, we are sure we don't need to try
1202 // again.
1203 ResetPendingUpload();
1204}
1205
1206void RenderView::DidStartProvisionalLoadForFrame(
1207 WebView* webview,
1208 WebFrame* frame,
1209 NavigationGesture gesture) {
[email protected]77e09a92008-08-01 18:11:041210 if (webview->GetMainFrame() == frame) {
initial.commit09911bf2008-07-26 23:55:291211 navigation_gesture_ = gesture;
[email protected]266eb6f2008-09-30 23:56:501212
[email protected]77e09a92008-08-01 18:11:041213 // Make sure redirect tracking state is clear for the new load.
1214 completed_client_redirect_src_ = GURL();
1215 }
initial.commit09911bf2008-07-26 23:55:291216
[email protected]c20210e62009-04-03 21:39:261217 WebDataSource* ds = frame->GetProvisionalDataSource();
1218 if (ds) {
1219 const WebRequest& req = ds->GetRequest();
1220 RenderViewExtraRequestData* extra_data =
1221 static_cast<RenderViewExtraRequestData*>(req.GetExtraData());
1222 if (extra_data) {
1223 ds->SetRequestTime(extra_data->request_time);
1224 }
1225 }
initial.commit09911bf2008-07-26 23:55:291226 Send(new ViewHostMsg_DidStartProvisionalLoadForFrame(
1227 routing_id_, webview->GetMainFrame() == frame,
1228 frame->GetProvisionalDataSource()->GetRequest().GetURL()));
1229}
1230
1231bool RenderView::DidLoadResourceFromMemoryCache(WebView* webview,
1232 const WebRequest& request,
1233 const WebResponse& response,
1234 WebFrame* frame) {
1235 // Let the browser know we loaded a resource from the memory cache. This
1236 // message is needed to display the correct SSL indicators.
1237 Send(new ViewHostMsg_DidLoadResourceFromMemoryCache(routing_id_,
[email protected]ffc45862009-03-17 06:11:081238 request.GetURL(), frame->GetSecurityOrigin(),
1239 frame->GetTop()->GetSecurityOrigin(),
1240 response.GetSecurityInfo()));
initial.commit09911bf2008-07-26 23:55:291241
1242 return false;
1243}
1244
1245void RenderView::DidReceiveProvisionalLoadServerRedirect(WebView* webview,
1246 WebFrame* frame) {
1247 if (frame == webview->GetMainFrame()) {
1248 // Received a redirect on the main frame.
1249 WebDataSource* data_source =
1250 webview->GetMainFrame()->GetProvisionalDataSource();
1251 if (!data_source) {
1252 // Should only be invoked when we have a data source.
1253 NOTREACHED();
1254 return;
1255 }
1256 const std::vector<GURL>& redirects = data_source->GetRedirectChain();
1257 if (redirects.size() >= 2) {
1258 Send(new ViewHostMsg_DidRedirectProvisionalLoad(
1259 routing_id_, page_id_, redirects[redirects.size() - 2],
1260 redirects[redirects.size() - 1]));
1261 }
1262 }
1263}
1264
1265void RenderView::DidFailProvisionalLoadWithError(WebView* webview,
1266 const WebError& error,
1267 WebFrame* frame) {
1268 // Notify the browser that we failed a provisional load with an error.
1269 //
1270 // Note: It is important this notification occur before DidStopLoading so the
1271 // SSL manager can react to the provisional load failure before being
1272 // notified the load stopped.
1273 //
1274 WebDataSource* ds = frame->GetProvisionalDataSource();
1275 DCHECK(ds);
1276
1277 const WebRequest& failed_request = ds->GetRequest();
1278
1279 bool show_repost_interstitial =
1280 (error.GetErrorCode() == net::ERR_CACHE_MISS &&
1281 LowerCaseEqualsASCII(failed_request.GetHttpMethod(), "post"));
1282 Send(new ViewHostMsg_DidFailProvisionalLoadWithError(
1283 routing_id_, frame == webview->GetMainFrame(),
1284 error.GetErrorCode(), error.GetFailedURL(),
1285 show_repost_interstitial));
1286
initial.commit09911bf2008-07-26 23:55:291287 // Don't display an error page if this is simply a cancelled load. Aside
1288 // from being dumb, WebCore doesn't expect it and it will cause a crash.
1289 if (error.GetErrorCode() == net::ERR_ABORTED)
1290 return;
1291
1292 // If this is a failed back/forward/reload navigation, then we need to do a
1293 // 'replace' load. This is necessary to avoid messing up session history.
1294 // Otherwise, we do a normal load, which simulates a 'go' navigation as far
1295 // as session history is concerned.
1296 RenderViewExtraRequestData* extra_data =
1297 static_cast<RenderViewExtraRequestData*>(failed_request.GetExtraData());
1298 bool replace = extra_data && !extra_data->is_new_navigation();
1299
[email protected]5df266ac2008-10-15 19:50:131300 // Use the alternate error page service if this is a DNS failure or
1301 // connection failure. ERR_CONNECTION_FAILED can be dropped once we no longer
1302 // use winhttp.
1303 int ec = error.GetErrorCode();
1304 if (ec == net::ERR_NAME_NOT_RESOLVED ||
1305 ec == net::ERR_CONNECTION_FAILED ||
1306 ec == net::ERR_CONNECTION_REFUSED ||
1307 ec == net::ERR_ADDRESS_UNREACHABLE ||
1308 ec == net::ERR_TIMED_OUT) {
1309 const GURL& failed_url = error.GetFailedURL();
1310 const GURL& error_page_url = GetAlternateErrorPageURL(failed_url,
1311 ec == net::ERR_NAME_NOT_RESOLVED ? WebViewDelegate::DNS_ERROR
1312 : WebViewDelegate::CONNECTION_ERROR);
1313 if (error_page_url.is_valid()) {
1314 // Ask the WebFrame to fetch the alternate error page for us.
1315 frame->LoadAlternateHTMLErrorPage(&failed_request, error, error_page_url,
1316 replace, GURL(kUnreachableWebDataURL));
1317 return;
1318 }
initial.commit09911bf2008-07-26 23:55:291319 }
[email protected]5df266ac2008-10-15 19:50:131320
[email protected]be645db2009-02-06 20:36:331321 // Fallback to a local error page.
[email protected]5df266ac2008-10-15 19:50:131322 LoadNavigationErrorPage(frame, &failed_request, error, std::string(),
1323 replace);
initial.commit09911bf2008-07-26 23:55:291324}
1325
1326void RenderView::LoadNavigationErrorPage(WebFrame* frame,
1327 const WebRequest* failed_request,
1328 const WebError& error,
1329 const std::string& html,
1330 bool replace) {
1331 const GURL& failed_url = error.GetFailedURL();
1332
1333 std::string alt_html;
1334 if (html.empty()) {
1335 // Use a local error page.
1336 int resource_id;
1337 DictionaryValue error_strings;
1338 if (error.GetErrorCode() == net::ERR_CACHE_MISS &&
1339 LowerCaseEqualsASCII(failed_request->GetHttpMethod(), "post")) {
1340 GetFormRepostErrorValues(failed_url, &error_strings);
1341 resource_id = IDR_ERROR_NO_DETAILS_HTML;
1342 } else {
1343 GetLocalizedErrorValues(error, &error_strings);
1344 resource_id = IDR_NET_ERROR_HTML;
1345 }
[email protected]8e50b602009-03-03 22:59:431346 error_strings.SetString(L"textdirection",
1347 (l10n_util::GetTextDirection() == l10n_util::RIGHT_TO_LEFT) ?
1348 L"rtl" : L"ltr");
initial.commit09911bf2008-07-26 23:55:291349
1350 alt_html = GetAltHTMLForTemplate(error_strings, resource_id);
1351 } else {
1352 alt_html = html;
1353 }
1354
1355 // Use a data: URL as the site URL to prevent against XSS attacks.
1356 scoped_ptr<WebRequest> request(failed_request->Clone());
1357 request->SetURL(GURL(kUnreachableWebDataURL));
1358
1359 frame->LoadAlternateHTMLString(request.get(), alt_html, failed_url,
1360 replace);
1361}
1362
1363void RenderView::DidCommitLoadForFrame(WebView *webview, WebFrame* frame,
1364 bool is_new_navigation) {
1365 const WebRequest& request =
1366 webview->GetMainFrame()->GetDataSource()->GetRequest();
1367 RenderViewExtraRequestData* extra_data =
1368 static_cast<RenderViewExtraRequestData*>(request.GetExtraData());
1369
1370 if (is_new_navigation) {
1371 // When we perform a new navigation, we need to update the previous session
1372 // history entry with state for the page we are leaving.
1373 UpdateSessionHistory(frame);
1374
1375 // We bump our Page ID to correspond with the new session history entry.
1376 page_id_ = next_page_id_++;
1377
1378 MessageLoop::current()->PostDelayedTask(FROM_HERE,
1379 method_factory_.NewRunnableMethod(&RenderView::CapturePageInfo,
1380 page_id_, true),
1381 kDelayForForcedCaptureMs);
1382 } else {
1383 // Inspect the extra_data on the main frame (set in our Navigate method) to
1384 // see if the navigation corresponds to a session history navigation...
1385 // Note: |frame| may or may not be the toplevel frame, but for the case
1386 // of capturing session history, the first committed frame suffices. We
1387 // keep track of whether we've seen this commit before so that only capture
1388 // session history once per navigation.
[email protected]f4d34b52008-11-24 23:05:011389 //
1390 // Note that we need to check if the page ID changed. In the case of a
1391 // reload, the page ID doesn't change, and UpdateSessionHistory gets the
1392 // previous URL and the current page ID, which would be wrong.
initial.commit09911bf2008-07-26 23:55:291393 if (extra_data && !extra_data->is_new_navigation() &&
[email protected]f4d34b52008-11-24 23:05:011394 !extra_data->request_committed &&
1395 page_id_ != extra_data->pending_page_id()) {
initial.commit09911bf2008-07-26 23:55:291396 // This is a successful session history navigation!
1397 UpdateSessionHistory(frame);
initial.commit09911bf2008-07-26 23:55:291398 page_id_ = extra_data->pending_page_id();
1399 }
1400 }
1401
1402 // Remember that we've already processed this request, so we don't update
1403 // the session history again. We do this regardless of whether this is
1404 // a session history navigation, because if we attempted a session history
1405 // navigation without valid HistoryItem state, WebCore will think it is a
1406 // new navigation.
1407 if (extra_data)
1408 extra_data->request_committed = true;
1409
1410 UpdateURL(frame);
1411
1412 // If this committed load was initiated by a client redirect, we're
1413 // at the last stop now, so clear it.
1414 completed_client_redirect_src_ = GURL();
1415
1416 // Check whether we have new encoding name.
1417 UpdateEncoding(frame, webview->GetMainFrameEncodingName());
1418}
1419
1420void RenderView::DidReceiveTitle(WebView* webview,
1421 const std::wstring& title,
1422 WebFrame* frame) {
1423 UpdateTitle(frame, title);
1424
1425 // Also check whether we have new encoding name.
1426 UpdateEncoding(frame, webview->GetMainFrameEncodingName());
1427}
1428
1429void RenderView::DidFinishLoadForFrame(WebView* webview, WebFrame* frame) {
[email protected]c20210e62009-04-03 21:39:261430 if (webview->GetMainFrame() == frame) {
1431 const GURL& url = frame->GetURL();
1432 if (url.SchemeIs("http") || url.SchemeIs("https"))
1433 DumpLoadHistograms();
1434 }
initial.commit09911bf2008-07-26 23:55:291435}
1436
1437void RenderView::DidFailLoadWithError(WebView* webview,
1438 const WebError& error,
1439 WebFrame* frame) {
1440}
1441
1442void RenderView::DidFinishDocumentLoadForFrame(WebView* webview,
1443 WebFrame* frame) {
1444 // Check whether we have new encoding name.
1445 UpdateEncoding(frame, webview->GetMainFrameEncodingName());
[email protected]1e0f70402008-10-16 23:57:471446
[email protected]8930d472009-02-21 08:05:281447 if (RenderThread::current()) // Will be NULL during unit tests.
1448 RenderThread::current()->user_script_slave()->InjectScripts(
[email protected]0afe8272009-02-14 04:15:161449 frame, UserScript::DOCUMENT_END);
initial.commit09911bf2008-07-26 23:55:291450}
1451
1452void RenderView::DidHandleOnloadEventsForFrame(WebView* webview,
1453 WebFrame* frame) {
1454}
1455
1456void RenderView::DidChangeLocationWithinPageForFrame(WebView* webview,
1457 WebFrame* frame,
1458 bool is_new_navigation) {
1459 DidCommitLoadForFrame(webview, frame, is_new_navigation);
[email protected]9d806f52009-03-12 22:50:541460 const string16& title =
[email protected]de56f3782008-10-01 22:31:351461 webview->GetMainFrame()->GetDataSource()->GetPageTitle();
[email protected]9d806f52009-03-12 22:50:541462 UpdateTitle(frame, UTF16ToWideHack(title));
initial.commit09911bf2008-07-26 23:55:291463}
1464
1465void RenderView::DidReceiveIconForFrame(WebView* webview,
1466 WebFrame* frame) {
1467}
1468
1469void RenderView::WillPerformClientRedirect(WebView* webview,
1470 WebFrame* frame,
1471 const GURL& src_url,
1472 const GURL& dest_url,
1473 unsigned int delay_seconds,
1474 unsigned int fire_date) {
1475}
1476
1477void RenderView::DidCancelClientRedirect(WebView* webview,
1478 WebFrame* frame) {
1479}
1480
[email protected]309d7a282009-03-24 09:18:271481void RenderView::WillCloseFrame(WebView* view, WebFrame* frame) {
1482 // Remove all the pending extension callbacks for this frame.
1483 if (pending_extension_callbacks_.IsEmpty())
1484 return;
1485
1486 std::vector<int> orphaned_callbacks;
1487 for (IDMap<WebFrame>::const_iterator iter =
1488 pending_extension_callbacks_.begin();
1489 iter != pending_extension_callbacks_.end(); ++iter) {
1490 if (iter->second == frame)
1491 orphaned_callbacks.push_back(iter->first);
1492 }
1493
1494 for (std::vector<int>::const_iterator iter = orphaned_callbacks.begin();
1495 iter != orphaned_callbacks.end(); ++iter) {
1496 pending_extension_callbacks_.Remove(*iter);
1497 }
1498}
1499
initial.commit09911bf2008-07-26 23:55:291500void RenderView::DidCompleteClientRedirect(WebView* webview,
1501 WebFrame* frame,
1502 const GURL& source) {
1503 if (webview->GetMainFrame() == frame)
1504 completed_client_redirect_src_ = source;
1505}
1506
[email protected]5b35a6b2009-03-16 19:58:081507void RenderView::WillSendRequest(WebView* webview,
1508 uint32 identifier,
1509 WebRequest* request) {
1510 request->SetRequestorID(routing_id_);
1511}
1512
initial.commit09911bf2008-07-26 23:55:291513void RenderView::BindDOMAutomationController(WebFrame* webframe) {
1514 dom_automation_controller_.set_message_sender(this);
1515 dom_automation_controller_.set_routing_id(routing_id_);
1516 dom_automation_controller_.BindToJavascript(webframe,
1517 L"domAutomationController");
1518}
1519
1520void RenderView::WindowObjectCleared(WebFrame* webframe) {
1521 external_js_object_.set_render_view(this);
1522 external_js_object_.BindToJavascript(webframe, L"external");
[email protected]81e63782009-02-27 19:35:091523 if (BindingsPolicy::is_dom_automation_enabled(enabled_bindings_))
initial.commit09911bf2008-07-26 23:55:291524 BindDOMAutomationController(webframe);
[email protected]81e63782009-02-27 19:35:091525 if (BindingsPolicy::is_dom_ui_enabled(enabled_bindings_)) {
initial.commit09911bf2008-07-26 23:55:291526 dom_ui_bindings_.set_message_sender(this);
1527 dom_ui_bindings_.set_routing_id(routing_id_);
1528 dom_ui_bindings_.BindToJavascript(webframe, L"chrome");
1529 }
[email protected]81e63782009-02-27 19:35:091530 if (BindingsPolicy::is_external_host_enabled(enabled_bindings_)) {
[email protected]18cb2572008-08-21 20:34:451531 external_host_bindings_.set_message_sender(this);
1532 external_host_bindings_.set_routing_id(routing_id_);
1533 external_host_bindings_.BindToJavascript(webframe, L"externalHost");
1534 }
[email protected]9a2051d2008-08-15 20:12:421535
[email protected]3a453fa2008-08-15 18:46:341536#ifdef CHROME_PERSONALIZATION
1537 Personalization::ConfigureRendererPersonalization(personalization_, this,
1538 routing_id_, webframe);
1539#endif
initial.commit09911bf2008-07-26 23:55:291540}
1541
[email protected]0afe8272009-02-14 04:15:161542void RenderView::DocumentElementAvailable(WebFrame* frame) {
[email protected]4b8323b2009-04-17 18:45:441543 // TODO(mpcomplete): remove this before Chrome extensions ship.
1544 // HACK. This is a temporary workaround to allow cross-origin XHR for Chrome
1545 // extensions. It grants full access to every origin, when we really want
1546 // to be able to restrict them more specifically.
[email protected]d959ce22009-04-15 21:03:421547 if (frame->GetURL().SchemeIs(chrome::kExtensionScheme))
[email protected]4b8323b2009-04-17 18:45:441548 frame->GrantUniversalAccess();
[email protected]d959ce22009-04-15 21:03:421549
[email protected]8930d472009-02-21 08:05:281550 if (RenderThread::current()) // Will be NULL during unit tests.
1551 RenderThread::current()->user_script_slave()->InjectScripts(
[email protected]0afe8272009-02-14 04:15:161552 frame, UserScript::DOCUMENT_START);
1553}
1554
initial.commit09911bf2008-07-26 23:55:291555WindowOpenDisposition RenderView::DispositionForNavigationAction(
1556 WebView* webview,
1557 WebFrame* frame,
1558 const WebRequest* request,
1559 WebNavigationType type,
1560 WindowOpenDisposition disposition,
1561 bool is_redirect) {
1562 // Webkit is asking whether to navigate to a new URL.
1563 // This is fine normally, except if we're showing UI from one security
1564 // context and they're trying to navigate to a different context.
1565 const GURL& url = request->GetURL();
1566 // We only care about navigations that are within the current tab (as opposed
1567 // to, for example, opening a new window).
1568 // But we sometimes navigate to about:blank to clear a tab, and we want to
1569 // still allow that.
[email protected]6de74452009-02-25 18:04:591570 if (disposition == CURRENT_TAB && !(url.SchemeIs(chrome::kAboutScheme))) {
initial.commit09911bf2008-07-26 23:55:291571 // GetExtraData is NULL when we did not issue the request ourselves (see
1572 // OnNavigate), and so such a request may correspond to a link-click,
1573 // script, or drag-n-drop initiated navigation.
1574 if (frame == webview->GetMainFrame() && !request->GetExtraData()) {
1575 // When we received such unsolicited navigations, we sometimes want to
1576 // punt them up to the browser to handle.
[email protected]81e63782009-02-27 19:35:091577 if (BindingsPolicy::is_dom_ui_enabled(enabled_bindings_) ||
initial.commit09911bf2008-07-26 23:55:291578 frame->GetInViewSourceMode() ||
[email protected]6de74452009-02-25 18:04:591579 url.SchemeIs(chrome::kViewSourceScheme)) {
[email protected]c0588052008-10-27 23:01:501580 OpenURL(webview, url, GURL(), disposition);
initial.commit09911bf2008-07-26 23:55:291581 return IGNORE_ACTION; // Suppress the load here.
[email protected]50b691c2008-10-31 19:08:351582 } else if (url.SchemeIs(kBackForwardNavigationScheme)) {
1583 std::string offset_str = url.ExtractFileName();
1584 int offset;
1585 if (StringToInt(offset_str, &offset)) {
[email protected]0c0383772008-11-04 00:48:311586 GoToEntryAtOffset(offset);
[email protected]50b691c2008-10-31 19:08:351587 return IGNORE_ACTION; // The browser process handles this one.
1588 }
initial.commit09911bf2008-07-26 23:55:291589 }
1590 }
1591 }
1592
1593 // Detect when a page is "forking" a new tab that can be safely rendered in
1594 // its own process. This is done by sites like Gmail that try to open links
1595 // in new windows without script connections back to the original page. We
1596 // treat such cases as browser navigations (in which we will create a new
1597 // renderer for a cross-site navigation), rather than WebKit navigations.
1598 //
1599 // We use the following heuristic to decide whether to fork a new page in its
1600 // own process:
1601 // The parent page must open a new tab to about:blank, set the new tab's
1602 // window.opener to null, and then redirect the tab to a cross-site URL using
1603 // JavaScript.
1604 bool is_fork =
1605 // Must start from a tab showing about:blank, which is later redirected.
[email protected]6aad4bd2009-02-26 22:55:171606 frame->GetURL() == GURL("about:blank") &&
initial.commit09911bf2008-07-26 23:55:291607 // Must be the first real navigation of the tab.
1608 GetHistoryBackListCount() < 1 &&
1609 GetHistoryForwardListCount() < 1 &&
1610 // The parent page must have set the child's window.opener to null before
1611 // redirecting to the desired URL.
1612 frame->GetOpener() == NULL &&
1613 // Must be a top-level frame.
1614 frame->GetParent() == NULL &&
1615 // Must not have issued the request from this page. GetExtraData is NULL
1616 // when the navigation is being done by something outside the page.
1617 !request->GetExtraData() &&
1618 // Must be targeted at the current tab.
1619 disposition == CURRENT_TAB &&
1620 // Must be a JavaScript navigation, which appears as "other".
1621 type == WebNavigationTypeOther;
1622 if (is_fork) {
1623 // Open the URL via the browser, not via WebKit.
[email protected]c0588052008-10-27 23:01:501624 OpenURL(webview, url, GURL(), disposition);
initial.commit09911bf2008-07-26 23:55:291625 return IGNORE_ACTION;
1626 }
1627
1628 return disposition;
1629}
1630
[email protected]a455d3812009-03-05 20:18:071631void RenderView::RunJavaScriptAlert(WebFrame* webframe,
initial.commit09911bf2008-07-26 23:55:291632 const std::wstring& message) {
[email protected]478ff2ed2009-04-21 23:49:181633 RunJavaScriptMessage(MessageBoxFlags::kIsJavascriptAlert,
initial.commit09911bf2008-07-26 23:55:291634 message,
1635 std::wstring(),
[email protected]a455d3812009-03-05 20:18:071636 webframe->GetURL(),
initial.commit09911bf2008-07-26 23:55:291637 NULL);
1638}
1639
[email protected]a455d3812009-03-05 20:18:071640bool RenderView::RunJavaScriptConfirm(WebFrame* webframe,
initial.commit09911bf2008-07-26 23:55:291641 const std::wstring& message) {
[email protected]478ff2ed2009-04-21 23:49:181642 return RunJavaScriptMessage(MessageBoxFlags::kIsJavascriptConfirm,
initial.commit09911bf2008-07-26 23:55:291643 message,
1644 std::wstring(),
[email protected]a455d3812009-03-05 20:18:071645 webframe->GetURL(),
initial.commit09911bf2008-07-26 23:55:291646 NULL);
1647}
1648
[email protected]a455d3812009-03-05 20:18:071649bool RenderView::RunJavaScriptPrompt(WebFrame* webframe,
initial.commit09911bf2008-07-26 23:55:291650 const std::wstring& message,
1651 const std::wstring& default_value,
1652 std::wstring* result) {
[email protected]478ff2ed2009-04-21 23:49:181653 return RunJavaScriptMessage(MessageBoxFlags::kIsJavascriptPrompt,
initial.commit09911bf2008-07-26 23:55:291654 message,
1655 default_value,
[email protected]a455d3812009-03-05 20:18:071656 webframe->GetURL(),
initial.commit09911bf2008-07-26 23:55:291657 result);
1658}
1659
1660bool RenderView::RunJavaScriptMessage(int type,
1661 const std::wstring& message,
1662 const std::wstring& default_value,
[email protected]a455d3812009-03-05 20:18:071663 const GURL& frame_url,
initial.commit09911bf2008-07-26 23:55:291664 std::wstring* result) {
1665 bool success = false;
1666 std::wstring result_temp;
1667 if (!result)
1668 result = &result_temp;
1669 IPC::SyncMessage* msg = new ViewHostMsg_RunJavaScriptMessage(
[email protected]a455d3812009-03-05 20:18:071670 routing_id_, message, default_value, frame_url, type, &success, result);
initial.commit09911bf2008-07-26 23:55:291671
[email protected]1c4947f2009-01-15 22:25:111672 msg->set_pump_messages_event(modal_dialog_event_.get());
initial.commit09911bf2008-07-26 23:55:291673 Send(msg);
1674
1675 return success;
1676}
1677
1678void RenderView::AddGURLSearchProvider(const GURL& osd_url, bool autodetected) {
1679 if (!osd_url.is_empty())
1680 Send(new ViewHostMsg_PageHasOSDD(routing_id_, page_id_, osd_url,
1681 autodetected));
1682}
1683
[email protected]4604d1f42009-03-13 21:52:321684void RenderView::UpdateFeedList(scoped_refptr<FeedList> feedlist) {
1685 ViewHostMsg_UpdateFeedList_Params params;
1686 params.page_id = page_id_;
1687 params.feedlist = feedlist;
1688 Send(new ViewHostMsg_UpdateFeedList(routing_id_, params));
1689}
1690
[email protected]a455d3812009-03-05 20:18:071691bool RenderView::RunBeforeUnloadConfirm(WebFrame* webframe,
initial.commit09911bf2008-07-26 23:55:291692 const std::wstring& message) {
1693 bool success = false;
1694 // This is an ignored return value, but is included so we can accept the same
1695 // response as RunJavaScriptMessage.
1696 std::wstring ignored_result;
1697 IPC::SyncMessage* msg = new ViewHostMsg_RunBeforeUnloadConfirm(
[email protected]a455d3812009-03-05 20:18:071698 routing_id_, webframe->GetURL(), message, &success, &ignored_result);
initial.commit09911bf2008-07-26 23:55:291699
[email protected]1c4947f2009-01-15 22:25:111700 msg->set_pump_messages_event(modal_dialog_event_.get());
initial.commit09911bf2008-07-26 23:55:291701 Send(msg);
1702
1703 return success;
1704}
1705
[email protected]0578a502008-11-10 19:34:431706void RenderView::EnableSuddenTermination() {
1707 Send(new ViewHostMsg_UnloadListenerChanged(routing_id_, false));
1708}
1709
1710void RenderView::DisableSuddenTermination() {
1711 Send(new ViewHostMsg_UnloadListenerChanged(routing_id_, true));
initial.commit09911bf2008-07-26 23:55:291712}
1713
[email protected]0ebf3872008-11-07 21:35:031714void RenderView::QueryFormFieldAutofill(const std::wstring& field_name,
1715 const std::wstring& text,
1716 int64 node_id) {
1717 static int message_id_counter = 0;
1718 form_field_autofill_request_id_ = message_id_counter++;
1719 Send(new ViewHostMsg_QueryFormFieldAutofill(routing_id_,
1720 field_name, text,
1721 node_id,
1722 form_field_autofill_request_id_));
1723}
1724
[email protected]4d2b6fb2009-03-20 22:28:171725void RenderView::RemoveStoredAutofillEntry(const std::wstring& name,
1726 const std::wstring& value) {
1727 Send(new ViewHostMsg_RemoveAutofillEntry(routing_id_, name, value));
1728}
1729
[email protected]0ebf3872008-11-07 21:35:031730void RenderView::OnReceivedAutofillSuggestions(
1731 int64 node_id,
1732 int request_id,
[email protected]8d0f15c2008-11-11 01:01:091733 const std::vector<std::wstring>& suggestions,
[email protected]0ebf3872008-11-07 21:35:031734 int default_suggestion_index) {
1735 if (!webview() || request_id != form_field_autofill_request_id_)
1736 return;
1737
1738 webview()->AutofillSuggestionsForNode(node_id, suggestions,
1739 default_suggestion_index);
1740}
1741
[email protected]634a6f92008-12-01 21:39:311742void RenderView::OnPopupNotificationVisiblityChanged(bool visible) {
1743 popup_notification_visible_ = visible;
1744}
1745
initial.commit09911bf2008-07-26 23:55:291746void RenderView::ShowModalHTMLDialog(const GURL& url, int width, int height,
1747 const std::string& json_arguments,
1748 std::string* json_retval) {
1749 IPC::SyncMessage* msg = new ViewHostMsg_ShowModalHTMLDialog(
1750 routing_id_, url, width, height, json_arguments, json_retval);
1751
[email protected]1c4947f2009-01-15 22:25:111752 msg->set_pump_messages_event(modal_dialog_event_.get());
initial.commit09911bf2008-07-26 23:55:291753 Send(msg);
1754}
1755
1756uint32 RenderView::GetCPBrowsingContext() {
1757 uint32 context = 0;
1758 Send(new ViewHostMsg_GetCPBrowsingContext(&context));
1759 return context;
1760}
1761
1762// Tell the browser to display a destination link.
1763void RenderView::UpdateTargetURL(WebView* webview, const GURL& url) {
1764 if (url != target_url_) {
1765 if (target_url_status_ == TARGET_INFLIGHT ||
1766 target_url_status_ == TARGET_PENDING) {
1767 // If we have a request in-flight, save the URL to be sent when we
1768 // receive an ACK to the in-flight request. We can happily overwrite
1769 // any existing pending sends.
1770 pending_target_url_ = url;
1771 target_url_status_ = TARGET_PENDING;
1772 } else {
1773 Send(new ViewHostMsg_UpdateTargetURL(routing_id_, page_id_, url));
1774 target_url_ = url;
1775 target_url_status_ = TARGET_INFLIGHT;
1776 }
1777 }
1778}
1779
[email protected]b62d1a8c2009-01-13 23:54:571780void RenderView::RunFileChooser(bool multi_select,
[email protected]b949f1112009-04-12 20:03:081781 const string16& title,
1782 const FilePath& default_filename,
initial.commit09911bf2008-07-26 23:55:291783 WebFileChooserCallback* file_chooser) {
1784 if (file_chooser_.get()) {
1785 // TODO(brettw): bug 1235154: This should be a synchronous message to deal
1786 // with the fact that web pages can programatically trigger this. With the
1787 // asnychronous messages, we can get an additional call when one is pending,
1788 // which this test is for. For now, we just ignore the additional file
1789 // chooser request. WebKit doesn't do anything to expect the callback, so
1790 // we can just ignore calling it.
1791 delete file_chooser;
1792 return;
1793 }
1794 file_chooser_.reset(file_chooser);
[email protected]b62d1a8c2009-01-13 23:54:571795 Send(new ViewHostMsg_RunFileChooser(routing_id_, multi_select, title,
[email protected]b949f1112009-04-12 20:03:081796 default_filename));
initial.commit09911bf2008-07-26 23:55:291797}
1798
1799void RenderView::AddMessageToConsole(WebView* webview,
1800 const std::wstring& message,
1801 unsigned int line_no,
1802 const std::wstring& source_id) {
1803 Send(new ViewHostMsg_AddMessageToConsole(routing_id_, message,
1804 static_cast<int32>(line_no),
1805 source_id));
1806}
1807
1808void RenderView::AddSearchProvider(const std::string& url) {
1809 AddGURLSearchProvider(GURL(url),
1810 false); // not autodetected
1811}
1812
1813void RenderView::DebuggerOutput(const std::wstring& out) {
1814 Send(new ViewHostMsg_DebuggerOutput(routing_id_, out));
1815}
1816
1817WebView* RenderView::CreateWebView(WebView* webview, bool user_gesture) {
[email protected]0aa55312008-10-17 21:53:081818 // Check to make sure we aren't overloading on popups.
1819 if (shared_popup_counter_->data > kMaximumNumberOfUnacknowledgedPopups)
1820 return NULL;
1821
[email protected]634a6f92008-12-01 21:39:311822 // This window can't be closed from a window.close() call until we receive a
1823 // message from the Browser process explicitly allowing it.
1824 popup_notification_visible_ = true;
1825
initial.commit09911bf2008-07-26 23:55:291826 int32 routing_id = MSG_ROUTING_NONE;
[email protected]6c8afae52009-01-22 02:24:571827
[email protected]18bcc3c2009-01-27 21:39:151828 ModalDialogEvent modal_dialog_event;
[email protected]6c8afae52009-01-22 02:24:571829 render_thread_->Send(
[email protected]15787f8f2008-10-17 15:29:031830 new ViewHostMsg_CreateWindow(routing_id_, user_gesture, &routing_id,
1831 &modal_dialog_event));
initial.commit09911bf2008-07-26 23:55:291832 if (routing_id == MSG_ROUTING_NONE) {
initial.commit09911bf2008-07-26 23:55:291833 return NULL;
1834 }
1835
1836 // The WebView holds a reference to this new RenderView
1837 const WebPreferences& prefs = webview->GetPreferences();
[email protected]6c8afae52009-01-22 02:24:571838 base::WaitableEvent* waitable_event = new base::WaitableEvent
1839#if defined(OS_WIN)
[email protected]18bcc3c2009-01-27 21:39:151840 (modal_dialog_event.event);
[email protected]6c8afae52009-01-22 02:24:571841#else
1842 (true, false);
1843#endif
[email protected]81a34412009-01-05 19:17:241844 RenderView* view = RenderView::Create(render_thread_,
[email protected]1c4947f2009-01-15 22:25:111845 NULL, waitable_event, routing_id_,
[email protected]0aa55312008-10-17 21:53:081846 prefs, shared_popup_counter_,
1847 routing_id);
initial.commit09911bf2008-07-26 23:55:291848 view->set_opened_by_user_gesture(user_gesture);
1849
1850 // Copy over the alternate error page URL so we can have alt error pages in
1851 // the new render view (we don't need the browser to send the URL back down).
1852 view->alternate_error_page_url_ = alternate_error_page_url_;
1853
1854 return view->webview();
1855}
1856
[email protected]0ebf3872008-11-07 21:35:031857WebWidget* RenderView::CreatePopupWidget(WebView* webview,
[email protected]cfd727f2009-01-09 20:21:111858 bool activatable) {
[email protected]8085dbc82008-09-26 22:53:441859 RenderWidget* widget = RenderWidget::Create(routing_id_,
[email protected]81a34412009-01-05 19:17:241860 render_thread_,
[email protected]cfd727f2009-01-09 20:21:111861 activatable);
initial.commit09911bf2008-07-26 23:55:291862 return widget->webwidget();
1863}
1864
1865WebPluginDelegate* RenderView::CreatePluginDelegate(
1866 WebView* webview,
1867 const GURL& url,
1868 const std::string& mime_type,
1869 const std::string& clsid,
1870 std::string* actual_mime_type) {
[email protected]6c8afae52009-01-22 02:24:571871#if defined(OS_WIN)
[email protected]6273e2e72009-04-17 00:13:551872 if (!PluginChannelHost::IsListening())
1873 return NULL;
1874
[email protected]88a1fb47a2009-03-13 00:18:061875 if (RenderProcess::current()->in_process_plugins()) {
[email protected]690a99c2009-01-06 16:48:451876 FilePath path;
[email protected]81a34412009-01-05 19:17:241877 render_thread_->Send(
initial.commit09911bf2008-07-26 23:55:291878 new ViewHostMsg_GetPluginPath(url, mime_type, clsid, &path,
1879 actual_mime_type));
[email protected]690a99c2009-01-06 16:48:451880 if (path.value().empty())
initial.commit09911bf2008-07-26 23:55:291881 return NULL;
1882
1883 std::string mime_type_to_use;
1884 if (actual_mime_type && !actual_mime_type->empty())
1885 mime_type_to_use = *actual_mime_type;
1886 else
1887 mime_type_to_use = mime_type;
1888
[email protected]b94d3322009-02-12 19:49:041889 return WebPluginDelegate::Create(path,
1890 mime_type_to_use,
1891 gfx::NativeViewFromId(host_window_));
initial.commit09911bf2008-07-26 23:55:291892 }
1893
1894 WebPluginDelegateProxy* proxy =
1895 WebPluginDelegateProxy::Create(url, mime_type, clsid, this);
1896 if (!proxy)
1897 return NULL;
1898
1899 // We hold onto the proxy so we can poke it when we are painting. See our
1900 // DidPaint implementation below.
1901 plugin_delegates_.push_back(proxy);
1902
1903 return proxy;
[email protected]6c8afae52009-01-22 02:24:571904#else
[email protected]157e5d22009-04-23 18:43:351905 // TODO(port): Plugins currently not supported
1906 NOTIMPLEMENTED();
1907 return NULL;
[email protected]6c8afae52009-01-22 02:24:571908#endif
initial.commit09911bf2008-07-26 23:55:291909}
1910
[email protected]ec9212f2008-12-18 21:40:361911webkit_glue::WebMediaPlayerDelegate* RenderView::CreateMediaPlayerDelegate() {
[email protected]be645db2009-02-06 20:36:331912#if defined(OS_WIN)
[email protected]d43ed912009-02-03 04:52:531913 return new WebMediaPlayerDelegateImpl(this);
[email protected]be645db2009-02-06 20:36:331914#else
1915 // TODO(port)
1916 NOTIMPLEMENTED();
1917 return NULL;
1918#endif
[email protected]ec9212f2008-12-18 21:40:361919}
1920
initial.commit09911bf2008-07-26 23:55:291921void RenderView::OnMissingPluginStatus(WebPluginDelegate* delegate,
1922 int status) {
[email protected]6c8afae52009-01-22 02:24:571923#if defined(OS_WIN)
initial.commit09911bf2008-07-26 23:55:291924 if (first_default_plugin_ == NULL) {
1925 // Show the InfoBar for the first available plugin.
1926 if (status == default_plugin::MISSING_PLUGIN_AVAILABLE) {
1927 first_default_plugin_ = delegate;
1928 Send(new ViewHostMsg_MissingPluginStatus(routing_id_, status));
1929 }
1930 } else {
1931 // Closes the InfoBar if user clicks on the plugin (instead of the InfoBar)
1932 // to start the download/install.
1933 if (status == default_plugin::MISSING_PLUGIN_USER_STARTED_DOWNLOAD) {
1934 Send(new ViewHostMsg_MissingPluginStatus(routing_id_, status));
1935 }
1936 }
[email protected]6c8afae52009-01-22 02:24:571937#else
1938 // TODO(port): plugins current not supported
1939 NOTIMPLEMENTED();
1940#endif
initial.commit09911bf2008-07-26 23:55:291941}
1942
[email protected]eb47a132009-03-04 00:39:561943WebWorker* RenderView::CreateWebWorker(WebWorkerClient* client) {
1944#if defined(OS_WIN)
[email protected]fd0995032009-03-24 02:01:111945 return new WebWorkerProxy(client, routing_id_);
[email protected]eb47a132009-03-04 00:39:561946#else
1947 // TODO(port): out of process workers
1948 NOTIMPLEMENTED();
1949 return NULL;
1950#endif
1951}
1952
initial.commit09911bf2008-07-26 23:55:291953void RenderView::OpenURL(WebView* webview, const GURL& url,
[email protected]c0588052008-10-27 23:01:501954 const GURL& referrer,
initial.commit09911bf2008-07-26 23:55:291955 WindowOpenDisposition disposition) {
[email protected]c0588052008-10-27 23:01:501956 Send(new ViewHostMsg_OpenURL(routing_id_, url, referrer, disposition));
initial.commit09911bf2008-07-26 23:55:291957}
1958
[email protected]1d522202009-04-04 01:56:421959void RenderView::DidContentsSizeChange(WebWidget* webwidget,
1960 int new_width,
1961 int new_height) {
1962 // TODO(rafaelw): This is a temporary solution. Only the ExtensionView wants
1963 // this notification at the moment. It isn't clean to test for ExtensionView
1964 // by examining the enabled_bindings. This needs to be generalized as it
1965 // becomes clear what extension toolbars need.
1966 if (BindingsPolicy::is_extension_enabled(enabled_bindings_)) {
1967 int width = webview()->GetMainFrame()->GetContentsPreferredWidth();
1968 Send(new ViewHostMsg_DidContentsPreferredWidthChange(routing_id_, width));
1969 }
1970}
1971
initial.commit09911bf2008-07-26 23:55:291972// We are supposed to get a single call to Show for a newly created RenderView
1973// that was created via RenderView::CreateWebView. So, we wait until this
1974// point to dispatch the ShowView message.
1975//
1976// This method provides us with the information about how to display the newly
1977// created RenderView (i.e., as a constrained popup or as a new tab).
1978//
1979void RenderView::Show(WebWidget* webwidget, WindowOpenDisposition disposition) {
1980 DCHECK(!did_show_) << "received extraneous Show call";
1981 DCHECK(opener_id_ != MSG_ROUTING_NONE);
1982
1983 if (did_show_)
1984 return;
1985 did_show_ = true;
1986
1987 // NOTE: initial_pos_ may still have its default values at this point, but
1988 // that's okay. It'll be ignored if disposition is not NEW_POPUP, or the
1989 // browser process will impose a default position otherwise.
1990 Send(new ViewHostMsg_ShowView(
1991 opener_id_, routing_id_, disposition, initial_pos_,
1992 WasOpenedByUserGestureHelper()));
1993}
1994
[email protected]634a6f92008-12-01 21:39:311995void RenderView::CloseWidgetSoon(WebWidget* webwidget) {
1996 if (popup_notification_visible_ == false)
1997 RenderWidget::CloseWidgetSoon(webwidget);
1998}
1999
initial.commit09911bf2008-07-26 23:55:292000void RenderView::RunModal(WebWidget* webwidget) {
2001 DCHECK(did_show_) << "should already have shown the view";
2002
2003 IPC::SyncMessage* msg = new ViewHostMsg_RunModal(routing_id_);
2004
[email protected]1c4947f2009-01-15 22:25:112005 msg->set_pump_messages_event(modal_dialog_event_.get());
initial.commit09911bf2008-07-26 23:55:292006 Send(msg);
2007}
2008
2009void RenderView::SyncNavigationState() {
2010 if (!webview())
2011 return;
2012
initial.commit09911bf2008-07-26 23:55:292013 std::string state;
[email protected]606843fa2008-12-02 19:08:562014 if (!webview()->GetMainFrame()->GetCurrentHistoryState(&state))
initial.commit09911bf2008-07-26 23:55:292015 return;
[email protected]606843fa2008-12-02 19:08:562016 Send(new ViewHostMsg_UpdateState(routing_id_, page_id_, state));
initial.commit09911bf2008-07-26 23:55:292017}
2018
2019void RenderView::ShowContextMenu(WebView* webview,
[email protected]124646932009-01-28 18:39:022020 ContextNode node,
initial.commit09911bf2008-07-26 23:55:292021 int x,
2022 int y,
2023 const GURL& link_url,
2024 const GURL& image_url,
2025 const GURL& page_url,
2026 const GURL& frame_url,
2027 const std::wstring& selection_text,
2028 const std::wstring& misspelled_word,
[email protected]6aa376b2008-09-23 18:49:522029 int edit_flags,
2030 const std::string& security_info) {
[email protected]e09ba552009-02-05 03:26:292031 ContextMenuParams params;
[email protected]124646932009-01-28 18:39:022032 params.node = node;
initial.commit09911bf2008-07-26 23:55:292033 params.x = x;
2034 params.y = y;
2035 params.image_url = image_url;
2036 params.link_url = link_url;
[email protected]e6c79812009-04-22 22:31:422037 params.unfiltered_link_url = link_url;
initial.commit09911bf2008-07-26 23:55:292038 params.page_url = page_url;
2039 params.frame_url = frame_url;
2040 params.selection_text = selection_text;
2041 params.misspelled_word = misspelled_word;
[email protected]be645db2009-02-06 20:36:332042 params.spellcheck_enabled =
[email protected]bbbd545c2008-12-15 20:18:042043 webview->GetFocusedFrame()->SpellCheckEnabled();
initial.commit09911bf2008-07-26 23:55:292044 params.edit_flags = edit_flags;
[email protected]6aa376b2008-09-23 18:49:522045 params.security_info = security_info;
initial.commit09911bf2008-07-26 23:55:292046 Send(new ViewHostMsg_ContextMenu(routing_id_, params));
2047}
2048
[email protected]e80c73b2009-04-07 23:24:582049void RenderView::StartDragging(WebView* webview,
2050 const WebDragData& drag_data) {
2051 Send(new ViewHostMsg_StartDragging(routing_id_, WebDropData(drag_data)));
initial.commit09911bf2008-07-26 23:55:292052}
2053
2054void RenderView::TakeFocus(WebView* webview, bool reverse) {
2055 Send(new ViewHostMsg_TakeFocus(routing_id_, reverse));
2056}
2057
2058void RenderView::DidDownloadImage(int id,
2059 const GURL& image_url,
2060 bool errored,
2061 const SkBitmap& image) {
2062 Send(new ViewHostMsg_DidDownloadImage(routing_id_, id, image_url, errored,
2063 image));
2064}
2065
2066
2067void RenderView::OnDownloadImage(int id,
2068 const GURL& image_url,
2069 int image_size) {
[email protected]f11ca0732009-04-11 00:09:342070
2071 bool data_image_failed = false;
2072 if (image_url.SchemeIs("data")) {
2073 SkBitmap data_image = ImageFromDataUrl(image_url);
2074 data_image_failed = data_image.empty();
2075 if (!data_image_failed) {
2076 Send(new ViewHostMsg_DidDownloadImage(routing_id_, id, image_url, false,
2077 data_image));
2078 }
2079 }
2080
2081 if (data_image_failed || !webview()->DownloadImage(id, image_url, image_size))
initial.commit09911bf2008-07-26 23:55:292082 Send(new ViewHostMsg_DidDownloadImage(routing_id_, id, image_url, true,
2083 SkBitmap()));
2084}
2085
[email protected]f11ca0732009-04-11 00:09:342086SkBitmap RenderView::ImageFromDataUrl(const GURL& url) const {
2087 std::string mime_type, char_set, data;
2088 if (net::DataURL::Parse(url, &mime_type, &char_set, &data) && !data.empty()) {
2089 // Decode the favicon using WebKit's image decoder.
2090 webkit_glue::ImageDecoder decoder(gfx::Size(kFavIconSize, kFavIconSize));
2091 const unsigned char* src_data =
2092 reinterpret_cast<const unsigned char*>(&data[0]);
2093
2094 return decoder.Decode(src_data, data.size());
2095 }
2096 return SkBitmap();
2097}
2098
initial.commit09911bf2008-07-26 23:55:292099void RenderView::OnGetApplicationInfo(int page_id) {
2100 webkit_glue::WebApplicationInfo app_info;
2101 if (page_id == page_id_)
2102 webkit_glue::GetApplicationInfo(webview(), &app_info);
2103
2104 // Prune out any data URLs in the set of icons. The browser process expects
2105 // any icon with a data URL to have originated from a favicon. We don't want
2106 // to decode arbitrary data URLs in the browser process. See
2107 // http://b/issue?id=1162972
2108 for (size_t i = 0; i < app_info.icons.size(); ++i) {
[email protected]6de74452009-02-25 18:04:592109 if (app_info.icons[i].url.SchemeIs(chrome::kDataScheme)) {
initial.commit09911bf2008-07-26 23:55:292110 app_info.icons.erase(app_info.icons.begin() + i);
2111 --i;
2112 }
2113 }
2114
2115 Send(new ViewHostMsg_DidGetApplicationInfo(routing_id_, page_id, app_info));
2116}
2117
2118GURL RenderView::GetAlternateErrorPageURL(const GURL& failedURL,
2119 ErrorPageType error_type) {
2120 if (failedURL.SchemeIsSecure()) {
2121 // If the URL that failed was secure, then the embedding web page was not
2122 // expecting a network attacker to be able to manipulate its contents. As
2123 // we fetch alternate error pages over HTTP, we would be allowing a network
2124 // attacker to manipulate the contents of the response if we tried to use
2125 // the link doctor here.
2126 return GURL::EmptyGURL();
2127 }
2128
2129 // Grab the base URL from the browser process.
2130 if (!alternate_error_page_url_.is_valid())
2131 return GURL::EmptyGURL();
2132
2133 // Strip query params from the failed URL.
2134 GURL::Replacements remove_params;
2135 remove_params.ClearUsername();
2136 remove_params.ClearPassword();
2137 remove_params.ClearQuery();
2138 remove_params.ClearRef();
2139 const GURL url_to_send = failedURL.ReplaceComponents(remove_params);
2140
2141 // Construct the query params to send to link doctor.
2142 std::string params(alternate_error_page_url_.query());
2143 params.append("&url=");
2144 params.append(EscapeQueryParamValue(url_to_send.spec()));
2145 params.append("&sourceid=chrome");
2146 params.append("&error=");
2147 switch (error_type) {
2148 case DNS_ERROR:
2149 params.append("dnserror");
2150 break;
2151
2152 case HTTP_404:
2153 params.append("http404");
2154 break;
2155
[email protected]5df266ac2008-10-15 19:50:132156 case CONNECTION_ERROR:
[email protected]e1f934b2009-01-26 20:41:332157 params.append("connectionfailure");
[email protected]5df266ac2008-10-15 19:50:132158 break;
2159
initial.commit09911bf2008-07-26 23:55:292160 default:
2161 NOTREACHED() << "unknown ErrorPageType";
2162 }
2163
2164 // OK, build the final url to return.
2165 GURL::Replacements link_doctor_params;
2166 link_doctor_params.SetQueryStr(params);
2167 GURL url = alternate_error_page_url_.ReplaceComponents(link_doctor_params);
2168 return url;
2169}
2170
[email protected]7ea066a2009-04-06 20:21:592171void RenderView::OnFind(int request_id,
2172 const string16& search_text,
2173 const WebKit::WebFindOptions& options) {
initial.commit09911bf2008-07-26 23:55:292174 WebFrame* main_frame = webview()->GetMainFrame();
2175 WebFrame* frame_after_main = webview()->GetNextFrameAfter(main_frame, true);
2176 WebFrame* focused_frame = webview()->GetFocusedFrame();
2177 WebFrame* search_frame = focused_frame; // start searching focused frame.
2178
2179 bool multi_frame = (frame_after_main != main_frame);
2180
2181 // If we have multiple frames, we don't want to wrap the search within the
2182 // frame, so we check here if we only have main_frame in the chain.
2183 bool wrap_within_frame = !multi_frame;
2184
[email protected]b3f2b912009-04-09 16:18:522185 WebRect selection_rect;
initial.commit09911bf2008-07-26 23:55:292186 bool result = false;
2187
2188 do {
[email protected]7ea066a2009-04-06 20:21:592189 result = search_frame->Find(
2190 request_id, search_text, options, wrap_within_frame, &selection_rect);
initial.commit09911bf2008-07-26 23:55:292191
2192 if (!result) {
2193 // don't leave text selected as you move to the next frame.
2194 search_frame->ClearSelection();
2195
2196 // Find the next frame, but skip the invisible ones.
2197 do {
2198 // What is the next frame to search? (we might be going backwards). Note
2199 // that we specify wrap=true so that search_frame never becomes NULL.
[email protected]7ea066a2009-04-06 20:21:592200 search_frame = options.forward ?
initial.commit09911bf2008-07-26 23:55:292201 webview()->GetNextFrameAfter(search_frame, true) :
2202 webview()->GetPreviousFrameBefore(search_frame, true);
2203 } while (!search_frame->Visible() && search_frame != focused_frame);
2204
[email protected]884db412008-11-24 23:46:502205 // Make sure selection doesn't affect the search operation in new frame.
initial.commit09911bf2008-07-26 23:55:292206 search_frame->ClearSelection();
2207
2208 // If we have multiple frames and we have wrapped back around to the
2209 // focused frame, we need to search it once more allowing wrap within
2210 // the frame, otherwise it will report 'no match' if the focused frame has
2211 // reported matches, but no frames after the focused_frame contain a
2212 // match for the search word(s).
2213 if (multi_frame && search_frame == focused_frame) {
[email protected]7ea066a2009-04-06 20:21:592214 result = search_frame->Find(
2215 request_id, search_text, options, true, // Force wrapping.
2216 &selection_rect);
initial.commit09911bf2008-07-26 23:55:292217 }
2218 }
2219
2220 // TODO(jcampan): http://b/issue?id=1157486 Remove StoreForFocus call once
2221 // we have the fix for 792423.
2222 search_frame->GetView()->StoreFocusForFrame(search_frame);
2223 webview()->SetFocusedFrame(search_frame);
2224 } while (!result && search_frame != focused_frame);
2225
2226 // Make sure we don't leave any frame focused or the focus won't be restored
2227 // properly in WebViewImpl::SetFocus(). Note that we are talking here about
2228 // focused on the SelectionController, not FocusController.
2229 // webview()->GetFocusedFrame() will still return the last focused frame (as
2230 // it queries the FocusController).
2231 // TODO(jcampan): http://b/issue?id=1157486 Remove next line once we have the
2232 // fix for 792423.
2233 webview()->SetFocusedFrame(NULL);
2234
[email protected]7ea066a2009-04-06 20:21:592235 if (options.findNext) {
[email protected]4f3dc372009-02-24 00:10:292236 // Force the main_frame to report the actual count.
[email protected]7ea066a2009-04-06 20:21:592237 main_frame->IncreaseMatchCount(0, request_id);
[email protected]4f3dc372009-02-24 00:10:292238 } else {
2239 // If nothing is found, set result to "0 of 0", otherwise, set it to
2240 // "-1 of 1" to indicate that we found at least one item, but we don't know
2241 // yet what is active.
2242 int ordinal = result ? -1 : 0; // -1 here means, we might know more later.
2243 int match_count = result ? 1 : 0; // 1 here means possibly more coming.
initial.commit09911bf2008-07-26 23:55:292244
[email protected]4f3dc372009-02-24 00:10:292245 // If we find no matches then this will be our last status update.
2246 // Otherwise the scoping effort will send more results.
2247 bool final_status_update = !result;
initial.commit09911bf2008-07-26 23:55:292248
[email protected]4f3dc372009-02-24 00:10:292249 // Send the search result over to the browser process.
[email protected]4f999132009-03-31 18:08:402250 Send(new ViewHostMsg_Find_Reply(routing_id_,
[email protected]7ea066a2009-04-06 20:21:592251 request_id,
[email protected]4f3dc372009-02-24 00:10:292252 match_count,
2253 selection_rect,
2254 ordinal,
2255 final_status_update));
initial.commit09911bf2008-07-26 23:55:292256
initial.commit09911bf2008-07-26 23:55:292257 // Scoping effort begins, starting with the mainframe.
2258 search_frame = main_frame;
2259
2260 main_frame->ResetMatchCount();
2261
2262 do {
2263 // Cancel all old scoping requests before starting a new one.
2264 search_frame->CancelPendingScopingEffort();
2265
2266 // We don't start another scoping effort unless at least one match has
2267 // been found.
2268 if (result) {
2269 // Start new scoping request. If the scoping function determines that it
2270 // needs to scope, it will defer until later.
[email protected]7ea066a2009-04-06 20:21:592271 search_frame->ScopeStringMatches(request_id,
2272 search_text,
2273 options,
initial.commit09911bf2008-07-26 23:55:292274 true); // reset the tickmarks
2275 }
2276
2277 // Iterate to the next frame. The frame will not necessarily scope, for
2278 // example if it is not visible.
2279 search_frame = webview()->GetNextFrameAfter(search_frame, true);
2280 } while (search_frame != main_frame);
2281 }
2282}
2283
2284void RenderView::ReportFindInPageMatchCount(int count, int request_id,
2285 bool final_update) {
2286 // If we have a message that has been queued up, then we should just replace
2287 // it. The ACK from the browser will make sure it gets sent when the browser
2288 // wants it.
2289 if (queued_find_reply_message_.get()) {
2290 IPC::Message* msg = new ViewHostMsg_Find_Reply(
2291 routing_id_,
2292 request_id,
2293 count,
[email protected]b3f2b912009-04-09 16:18:522294 gfx::Rect(),
initial.commit09911bf2008-07-26 23:55:292295 -1, // Don't update active match ordinal.
2296 final_update);
2297 queued_find_reply_message_.reset(msg);
2298 } else {
2299 // Send the search result over to the browser process.
2300 Send(new ViewHostMsg_Find_Reply(
2301 routing_id_,
2302 request_id,
2303 count,
[email protected]b3f2b912009-04-09 16:18:522304 gfx::Rect(),
initial.commit09911bf2008-07-26 23:55:292305 -1, // // Don't update active match ordinal.
2306 final_update));
2307 }
2308}
2309
2310void RenderView::ReportFindInPageSelection(int request_id,
2311 int active_match_ordinal,
[email protected]b3f2b912009-04-09 16:18:522312 const WebRect& selection_rect) {
initial.commit09911bf2008-07-26 23:55:292313 // Send the search result over to the browser process.
2314 Send(new ViewHostMsg_Find_Reply(routing_id_,
2315 request_id,
2316 -1,
2317 selection_rect,
2318 active_match_ordinal,
2319 false));
2320}
2321
2322bool RenderView::WasOpenedByUserGesture(WebView* webview) const {
2323 return WasOpenedByUserGestureHelper();
2324}
2325
2326bool RenderView::WasOpenedByUserGestureHelper() const {
2327 // If pop-up blocking has been disabled, then treat all new windows as if
2328 // they were opened by a user gesture. This will prevent them from being
2329 // blocked. This is a bit of a hack, there should be a more straightforward
2330 // way to disable pop-up blocking.
2331 if (disable_popup_blocking_)
2332 return true;
2333
2334 return opened_by_user_gesture_;
2335}
2336
2337void RenderView::SpellCheck(const std::wstring& word, int& misspell_location,
2338 int& misspell_length) {
2339 Send(new ViewHostMsg_SpellCheck(routing_id_, word, &misspell_location,
2340 &misspell_length));
2341}
2342
2343void RenderView::SetInputMethodState(bool enabled) {
2344 // Save the updated IME status and mark the input focus has been updated.
2345 // The IME status is to be sent to a browser process next time when
2346 // the input caret is rendered.
[email protected]9f23f592008-11-17 08:36:342347 if (!ime_control_busy_) {
2348 ime_control_updated_ = true;
2349 ime_control_new_state_ = enabled;
2350 }
initial.commit09911bf2008-07-26 23:55:292351}
2352
2353void RenderView::ScriptedPrint(WebFrame* frame) {
[email protected]6c8afae52009-01-22 02:24:572354#if defined(OS_WIN)
initial.commit09911bf2008-07-26 23:55:292355 // Retrieve the default print settings to calculate the expected number of
2356 // pages.
2357 ViewMsg_Print_Params default_settings;
2358 IPC::SyncMessage* msg =
2359 new ViewHostMsg_GetDefaultPrintSettings(routing_id_, &default_settings);
2360 if (Send(msg)) {
2361 msg = NULL;
2362 // Continue only if the settings are valid.
2363 if (default_settings.dpi && default_settings.document_cookie) {
[email protected]88a3ecc2009-03-19 17:36:222364 int expected_pages_count = 0;
2365 gfx::Size canvas_size;
2366 canvas_size.set_width(
2367 printing::ConvertUnit(default_settings.printable_size.width(),
2368 static_cast<int>(default_settings.dpi),
2369 default_settings.desired_dpi));
2370 canvas_size.set_height(
2371 printing::ConvertUnit(default_settings.printable_size.height(),
2372 static_cast<int>(default_settings.dpi),
2373 default_settings.desired_dpi));
2374 frame->BeginPrint(canvas_size, &expected_pages_count);
initial.commit09911bf2008-07-26 23:55:292375 DCHECK(expected_pages_count);
[email protected]88a3ecc2009-03-19 17:36:222376 frame->EndPrint();
initial.commit09911bf2008-07-26 23:55:292377
2378 // Ask the browser to show UI to retrieve the final print settings.
2379 ViewMsg_PrintPages_Params print_settings;
2380 // host_window_ may be NULL at this point if the current window is a popup
2381 // and the print() command has been issued from the parent. The receiver
2382 // of this message has to deal with this.
2383 msg = new ViewHostMsg_ScriptedPrint(routing_id_,
2384 host_window_,
2385 default_settings.document_cookie,
2386 expected_pages_count,
2387 &print_settings);
2388 if (Send(msg)) {
2389 msg = NULL;
2390
2391 // If the settings are invalid, early quit.
2392 if (print_settings.params.dpi &&
2393 print_settings.params.document_cookie) {
2394 // Render the printed pages. It will implicitly revert the document to
2395 // display CSS media type.
2396 PrintPages(print_settings, frame);
2397 // All went well.
2398 return;
2399 } else {
2400 // The user cancelled.
2401 }
2402 } else {
2403 // Send() failed.
2404 NOTREACHED();
2405 }
2406 } else {
2407 // The user cancelled.
2408 }
2409 } else {
2410 // Send() failed.
2411 NOTREACHED();
2412 }
2413 // TODO(maruel): bug 1123882 Alert the user that printing failed.
[email protected]6c8afae52009-01-22 02:24:572414#else // defined(OS_WIN)
2415 // TODO(port): print not implemented
2416 NOTIMPLEMENTED();
2417#endif
initial.commit09911bf2008-07-26 23:55:292418}
2419
2420void RenderView::WebInspectorOpened(int num_resources) {
2421 Send(new ViewHostMsg_InspectElement_Reply(routing_id_, num_resources));
2422}
2423
2424void RenderView::UserMetricsRecordAction(const std::wstring& action) {
2425 Send(new ViewHostMsg_UserMetricsRecordAction(routing_id_, action));
2426}
2427
2428void RenderView::DnsPrefetch(const std::vector<std::string>& host_names) {
2429 Send(new ViewHostMsg_DnsPrefetch(host_names));
2430}
2431
[email protected]630e26b2008-10-14 22:55:172432void RenderView::OnZoom(int function) {
2433 static const bool kZoomIsTextOnly = false;
2434 switch (function) {
2435 case PageZoom::SMALLER:
2436 webview()->ZoomOut(kZoomIsTextOnly);
initial.commit09911bf2008-07-26 23:55:292437 break;
[email protected]630e26b2008-10-14 22:55:172438 case PageZoom::STANDARD:
2439 webview()->ResetZoom();
initial.commit09911bf2008-07-26 23:55:292440 break;
[email protected]630e26b2008-10-14 22:55:172441 case PageZoom::LARGER:
2442 webview()->ZoomIn(kZoomIsTextOnly);
initial.commit09911bf2008-07-26 23:55:292443 break;
2444 default:
2445 NOTREACHED();
2446 }
2447}
2448
[email protected]ea8c7452009-04-02 20:47:062449void RenderView::OnInsertText(const string16& text) {
[email protected]00d7e622009-04-21 23:06:052450 WebTextInput* text_input = webview()->GetMainFrame()->GetTextInput();
2451 if (text_input)
2452 text_input->InsertText(UTF16ToUTF8(text));
[email protected]ea8c7452009-04-02 20:47:062453}
2454
[email protected]e38f40152008-09-12 23:08:302455void RenderView::OnSetPageEncoding(const std::wstring& encoding_name) {
initial.commit09911bf2008-07-26 23:55:292456 webview()->SetPageEncoding(encoding_name);
2457}
2458
2459void RenderView::OnPasswordFormsSeen(WebView* webview,
2460 const std::vector<PasswordForm>& forms) {
2461 Send(new ViewHostMsg_PasswordFormsSeen(routing_id_, forms));
2462}
2463
[email protected]8d0f15c2008-11-11 01:01:092464void RenderView::OnAutofillFormSubmitted(WebView* webview,
2465 const AutofillForm& form) {
2466 Send(new ViewHostMsg_AutofillFormSubmitted(routing_id_, form));
2467}
2468
initial.commit09911bf2008-07-26 23:55:292469WebHistoryItem* RenderView::GetHistoryEntryAtOffset(int offset) {
[email protected]50b691c2008-10-31 19:08:352470 // Our history list is kept in the browser process on the UI thread. Since
2471 // we can't make a sync IPC call to that thread without risking deadlock,
2472 // we use a trick: construct a fake history item of the form:
2473 // history://go/OFFSET
2474 // When WebCore tells us to navigate to it, we tell the browser process to
2475 // do a back/forward navigation instead.
2476
2477 GURL url(StringPrintf("%s://go/%d", kBackForwardNavigationScheme, offset));
2478 history_navigation_item_ = WebHistoryItem::Create(url, L"", "", NULL);
2479 return history_navigation_item_.get();
initial.commit09911bf2008-07-26 23:55:292480}
2481
[email protected]0c0383772008-11-04 00:48:312482void RenderView::GoToEntryAtOffset(int offset) {
[email protected]f46aff62008-10-16 07:58:052483 history_back_list_count_ += offset;
2484 history_forward_list_count_ -= offset;
2485
initial.commit09911bf2008-07-26 23:55:292486 Send(new ViewHostMsg_GoToEntryAtOffset(routing_id_, offset));
2487}
2488
2489int RenderView::GetHistoryBackListCount() {
2490 return history_back_list_count_;
2491}
2492
2493int RenderView::GetHistoryForwardListCount() {
2494 return history_forward_list_count_;
2495}
2496
2497void RenderView::OnNavStateChanged(WebView* webview) {
[email protected]81a34412009-01-05 19:17:242498 if (!nav_state_sync_timer_.IsRunning()) {
2499 nav_state_sync_timer_.Start(
2500 TimeDelta::FromSeconds(delay_seconds_for_form_state_sync_), this,
2501 &RenderView::SyncNavigationState);
2502 }
initial.commit09911bf2008-07-26 23:55:292503}
2504
2505void RenderView::SetTooltipText(WebView* webview,
2506 const std::wstring& tooltip_text) {
2507 Send(new ViewHostMsg_SetTooltipText(routing_id_, tooltip_text));
2508}
2509
[email protected]2e417c82009-04-02 22:30:262510void RenderView::DidChangeSelection(bool is_empty_selection) {
2511#if defined(OS_LINUX)
2512 if (!is_empty_selection) {
[email protected]dbadbcc2009-04-09 00:57:102513 Send(new ViewHostMsg_SelectionChanged(routing_id_,
2514 webview()->GetMainFrame()->GetSelection(false)));
[email protected]2e417c82009-04-02 22:30:262515 }
2516#endif
2517}
2518
2519
initial.commit09911bf2008-07-26 23:55:292520void RenderView::DownloadUrl(const GURL& url, const GURL& referrer) {
2521 Send(new ViewHostMsg_DownloadUrl(routing_id_, url, referrer));
2522}
2523
[email protected]611cad42009-03-16 18:51:342524WebDevToolsAgentDelegate* RenderView::GetWebDevToolsAgentDelegate() {
[email protected]b75b7d072009-04-06 13:47:002525 return devtools_agent_.get();
[email protected]611cad42009-03-16 18:51:342526}
2527
[email protected]ea8c7452009-04-02 20:47:062528void RenderView::PasteFromSelectionClipboard() {
2529 Send(new ViewHostMsg_PasteFromSelectionClipboard(routing_id_));
2530}
2531
initial.commit09911bf2008-07-26 23:55:292532WebFrame* RenderView::GetChildFrame(const std::wstring& frame_xpath) const {
2533 WebFrame* web_frame;
2534 if (frame_xpath.empty()) {
2535 web_frame = webview()->GetMainFrame();
2536 } else {
2537 web_frame = webview()->GetMainFrame()->GetChildFrame(frame_xpath);
2538 }
2539
2540 return web_frame;
2541}
2542
[email protected]f29acf52008-11-03 20:08:332543void RenderView::EvaluateScript(const std::wstring& frame_xpath,
2544 const std::wstring& script) {
initial.commit09911bf2008-07-26 23:55:292545 WebFrame* web_frame = GetChildFrame(frame_xpath);
2546 if (!web_frame)
2547 return;
2548
[email protected]4f999132009-03-31 18:08:402549 web_frame->ExecuteScript(WebScriptSource(WideToUTF16Hack(script)));
initial.commit09911bf2008-07-26 23:55:292550}
2551
[email protected]1810e132009-03-24 23:35:482552void RenderView::InsertCSS(const std::wstring& frame_xpath,
2553 const std::string& css) {
2554 WebFrame* web_frame = GetChildFrame(frame_xpath);
2555 if (!web_frame)
2556 return;
2557
2558 web_frame->InsertCSSStyles(css);
2559}
2560
initial.commit09911bf2008-07-26 23:55:292561void RenderView::OnScriptEvalRequest(const std::wstring& frame_xpath,
2562 const std::wstring& jscript) {
[email protected]f29acf52008-11-03 20:08:332563 EvaluateScript(frame_xpath, jscript);
initial.commit09911bf2008-07-26 23:55:292564}
2565
[email protected]1810e132009-03-24 23:35:482566void RenderView::OnCSSInsertRequest(const std::wstring& frame_xpath,
2567 const std::string& css) {
2568 InsertCSS(frame_xpath, css);
2569}
2570
[email protected]7ea066a2009-04-06 20:21:592571void RenderView::OnAddMessageToConsole(
2572 const string16& frame_xpath,
2573 const string16& message,
2574 const WebConsoleMessage::Level& level) {
2575 WebFrame* web_frame = GetChildFrame(UTF16ToWideHack(frame_xpath));
[email protected]0dea3ea2009-03-31 23:30:592576 if (web_frame)
[email protected]7ea066a2009-04-06 20:21:592577 web_frame->AddMessageToConsole(WebConsoleMessage(level, message));
initial.commit09911bf2008-07-26 23:55:292578}
2579
[email protected]6c8afae52009-01-22 02:24:572580#if defined(OS_WIN)
initial.commit09911bf2008-07-26 23:55:292581void RenderView::OnDebugAttach() {
initial.commit09911bf2008-07-26 23:55:292582 Send(new ViewHostMsg_DidDebugAttach(routing_id_));
2583 // Tell the plugin host to stop accepting messages in order to avoid
2584 // hangs while the renderer is paused.
2585 // TODO(1243929): It might be an improvement to add more plumbing to do this
2586 // when the renderer is actually paused vs. just the debugger being attached.
2587 PluginChannelHost::SetListening(false);
2588}
2589
2590void RenderView::OnDebugDetach() {
2591 // Tell the plugin host to start accepting plugin messages again.
2592 PluginChannelHost::SetListening(true);
2593}
[email protected]6c8afae52009-01-22 02:24:572594#else // defined(OS_WIN)
2595// TODO(port): plugins not yet supported
2596void RenderView::OnDebugAttach() { NOTIMPLEMENTED(); }
2597void RenderView::OnDebugDetach() { NOTIMPLEMENTED(); }
2598#endif
initial.commit09911bf2008-07-26 23:55:292599
[email protected]81e63782009-02-27 19:35:092600void RenderView::OnAllowBindings(int enabled_bindings_flags) {
2601 enabled_bindings_ |= enabled_bindings_flags;
initial.commit09911bf2008-07-26 23:55:292602}
2603
2604void RenderView::OnSetDOMUIProperty(const std::string& name,
2605 const std::string& value) {
[email protected]81e63782009-02-27 19:35:092606 DCHECK(BindingsPolicy::is_dom_ui_enabled(enabled_bindings_));
initial.commit09911bf2008-07-26 23:55:292607 dom_ui_bindings_.SetProperty(name, value);
2608}
2609
2610void RenderView::OnReservePageIDRange(int size_of_range) {
2611 next_page_id_ += size_of_range + 1;
2612}
2613
[email protected]e80c73b2009-04-07 23:24:582614void RenderView::OnDragSourceEndedOrMoved(const gfx::Point& client_point,
2615 const gfx::Point& screen_point,
initial.commit09911bf2008-07-26 23:55:292616 bool ended) {
2617 if (ended)
[email protected]e80c73b2009-04-07 23:24:582618 webview()->DragSourceEndedAt(client_point, screen_point);
initial.commit09911bf2008-07-26 23:55:292619 else
[email protected]e80c73b2009-04-07 23:24:582620 webview()->DragSourceMovedTo(client_point, screen_point);
initial.commit09911bf2008-07-26 23:55:292621}
2622
2623void RenderView::OnDragSourceSystemDragEnded() {
2624 webview()->DragSourceSystemDragEnded();
2625}
2626
2627void RenderView::OnUploadFileRequest(const ViewMsg_UploadFile_Params& p) {
2628 webkit_glue::FileUploadData* f = new webkit_glue::FileUploadData;
2629 f->file_path = p.file_path;
2630 f->form_name = p.form;
2631 f->file_name = p.file;
2632 f->submit_name = p.submit;
2633
2634 // Build the other form values map.
2635 if (!p.other_values.empty()) {
2636 std::vector<std::wstring> e;
2637 std::vector<std::wstring> kvp;
2638 std::vector<std::wstring>::iterator i;
2639
2640 SplitString(p.other_values, L'\n', &e);
2641 for (i = e.begin(); i != e.end(); ++i) {
2642 SplitString(*i, L'=', &kvp);
2643 if (kvp.size() == 2)
2644 f->other_form_values[kvp[0]] = kvp[1];
2645 kvp.clear();
2646 }
2647 }
2648
2649 pending_upload_data_.reset(f);
2650 ProcessPendingUpload();
2651}
2652
2653void RenderView::ProcessPendingUpload() {
2654 webkit_glue::FileUploadData* f = pending_upload_data_.get();
2655 if (f && webview() && webkit_glue::FillFormToUploadFile(webview(), *f))
2656 ResetPendingUpload();
2657}
2658
2659void RenderView::ResetPendingUpload() {
2660 pending_upload_data_.reset();
2661}
2662
2663void RenderView::OnFormFill(const FormData& form) {
2664 webkit_glue::FillForm(this->webview(), form);
2665}
2666
2667void RenderView::OnFillPasswordForm(
2668 const PasswordFormDomManager::FillData& form_data) {
2669 webkit_glue::FillPasswordForm(this->webview(), form_data);
2670}
2671
2672void RenderView::OnDragTargetDragEnter(const WebDropData& drop_data,
[email protected]e80c73b2009-04-07 23:24:582673 const gfx::Point& client_point,
2674 const gfx::Point& screen_point) {
2675 bool is_drop_target = webview()->DragTargetDragEnter(
2676 drop_data.ToDragData(),
2677 drop_data.identity,
2678 client_point,
2679 screen_point);
initial.commit09911bf2008-07-26 23:55:292680
2681 Send(new ViewHostMsg_UpdateDragCursor(routing_id_, is_drop_target));
2682}
2683
[email protected]e80c73b2009-04-07 23:24:582684void RenderView::OnDragTargetDragOver(const gfx::Point& client_point,
2685 const gfx::Point& screen_point) {
2686 bool is_drop_target =
2687 webview()->DragTargetDragOver(client_point, screen_point);
initial.commit09911bf2008-07-26 23:55:292688
2689 Send(new ViewHostMsg_UpdateDragCursor(routing_id_, is_drop_target));
2690}
2691
2692void RenderView::OnDragTargetDragLeave() {
2693 webview()->DragTargetDragLeave();
2694}
2695
[email protected]e80c73b2009-04-07 23:24:582696void RenderView::OnDragTargetDrop(const gfx::Point& client_point,
2697 const gfx::Point& screen_point) {
2698 webview()->DragTargetDrop(client_point, screen_point);
initial.commit09911bf2008-07-26 23:55:292699}
2700
2701void RenderView::OnUpdateWebPreferences(const WebPreferences& prefs) {
2702 webview()->SetPreferences(prefs);
2703}
2704
2705void RenderView::OnSetAltErrorPageURL(const GURL& url) {
2706 alternate_error_page_url_ = url;
2707}
2708
2709void RenderView::DidPaint() {
2710 PluginDelegateList::iterator it = plugin_delegates_.begin();
2711 while (it != plugin_delegates_.end()) {
2712 (*it)->FlushGeometryUpdates();
2713 ++it;
2714 }
2715}
2716
2717void RenderView::OnInstallMissingPlugin() {
2718 // This could happen when the first default plugin is deleted.
2719 if (first_default_plugin_ == NULL)
2720 return;
2721 first_default_plugin_->InstallMissingPlugin();
2722}
2723
[email protected]b62d1a8c2009-01-13 23:54:572724void RenderView::OnFileChooserResponse(
[email protected]561abe62009-04-06 18:08:342725 const std::vector<FilePath>& file_names) {
[email protected]8029f5672009-03-20 22:33:362726 // This could happen if we navigated to a different page before the user
2727 // closed the chooser.
2728 if (!file_chooser_.get())
2729 return;
2730
[email protected]b62d1a8c2009-01-13 23:54:572731 file_chooser_->OnFileChoose(file_names);
initial.commit09911bf2008-07-26 23:55:292732 file_chooser_.reset();
2733}
2734
2735void RenderView::OnEnableViewSourceMode() {
2736 if (!webview())
2737 return;
2738 WebFrame* main_frame = webview()->GetMainFrame();
2739 if (!main_frame)
2740 return;
2741
2742 main_frame->SetInViewSourceMode(true);
2743}
2744
2745void RenderView::OnUpdateBackForwardListCount(int back_list_count,
2746 int forward_list_count) {
2747 history_back_list_count_ = back_list_count;
2748 history_forward_list_count_ = forward_list_count;
2749}
2750
[email protected]266eb6f2008-09-30 23:56:502751void RenderView::OnGetAccessibilityInfo(
[email protected]6a983b42009-03-20 20:12:252752 const webkit_glue::WebAccessibility::InParams& in_params,
2753 webkit_glue::WebAccessibility::OutParams* out_params) {
[email protected]6c8afae52009-01-22 02:24:572754#if defined(OS_WIN)
[email protected]6a983b42009-03-20 20:12:252755 if (!web_accessibility_manager_.get()) {
2756 web_accessibility_manager_.reset(
2757 webkit_glue::WebAccessibilityManager::Create());
2758 }
[email protected]266eb6f2008-09-30 23:56:502759
[email protected]6a983b42009-03-20 20:12:252760 if (!web_accessibility_manager_->GetAccObjInfo(webview(), in_params,
2761 out_params)) {
[email protected]266eb6f2008-09-30 23:56:502762 return;
2763 }
[email protected]6c8afae52009-01-22 02:24:572764#else // defined(OS_WIN)
2765 // TODO(port): accessibility not yet implemented
2766 NOTIMPLEMENTED();
2767#endif
[email protected]266eb6f2008-09-30 23:56:502768}
2769
[email protected]6a983b42009-03-20 20:12:252770void RenderView::OnClearAccessibilityInfo(int acc_obj_id, bool clear_all) {
[email protected]6c8afae52009-01-22 02:24:572771#if defined(OS_WIN)
[email protected]6a983b42009-03-20 20:12:252772 if (!web_accessibility_manager_.get()) {
[email protected]266eb6f2008-09-30 23:56:502773 // If accessibility is not activated, ignore clearing message.
2774 return;
2775 }
[email protected]6a983b42009-03-20 20:12:252776 if (!web_accessibility_manager_->ClearAccObjMap(acc_obj_id, clear_all))
[email protected]266eb6f2008-09-30 23:56:502777 return;
[email protected]6c8afae52009-01-22 02:24:572778#else // defined(OS_WIN)
2779 // TODO(port): accessibility not yet implemented
2780 NOTIMPLEMENTED();
2781#endif
[email protected]266eb6f2008-09-30 23:56:502782}
2783
initial.commit09911bf2008-07-26 23:55:292784void RenderView::OnGetAllSavableResourceLinksForCurrentPage(
2785 const GURL& page_url) {
2786 // Prepare list to storage all savable resource links.
2787 std::vector<GURL> resources_list;
2788 std::vector<GURL> referrers_list;
2789 std::vector<GURL> frames_list;
2790 webkit_glue::SavableResourcesResult result(&resources_list,
2791 &referrers_list,
2792 &frames_list);
2793
2794 if (!webkit_glue::GetAllSavableResourceLinksForCurrentPage(webview(),
2795 page_url,
2796 &result)) {
2797 // If something is wrong when collecting all savable resource links,
2798 // send empty list to embedder(browser) to tell it failed.
2799 referrers_list.clear();
2800 resources_list.clear();
2801 frames_list.clear();
2802 }
2803
2804 // Send result of all savable resource links to embedder.
2805 Send(new ViewHostMsg_SendCurrentPageAllSavableResourceLinks(routing_id_,
2806 resources_list,
2807 referrers_list,
2808 frames_list));
2809}
2810
2811void RenderView::OnGetSerializedHtmlDataForCurrentPageWithLocalLinks(
[email protected]f6b48532009-02-12 01:56:322812 const std::vector<GURL>& links,
[email protected]fde6714d12009-02-18 22:39:312813 const std::vector<FilePath>& local_paths,
2814 const FilePath& local_directory_name) {
initial.commit09911bf2008-07-26 23:55:292815 webkit_glue::DomSerializer dom_serializer(webview()->GetMainFrame(),
2816 true,
2817 this,
2818 links,
2819 local_paths,
2820 local_directory_name);
2821 dom_serializer.SerializeDom();
2822}
2823
2824void RenderView::DidSerializeDataForFrame(const GURL& frame_url,
2825 const std::string& data, PageSavingSerializationStatus status) {
2826 Send(new ViewHostMsg_SendSerializedHtmlData(routing_id_,
2827 frame_url, data, static_cast<int32>(status)));
2828}
2829
[email protected]04b4a6c2008-08-02 00:44:472830void RenderView::OnMsgShouldClose() {
initial.commit09911bf2008-07-26 23:55:292831 bool should_close = webview()->ShouldClose();
[email protected]04b4a6c2008-08-02 00:44:472832 Send(new ViewHostMsg_ShouldClose_ACK(routing_id_, should_close));
initial.commit09911bf2008-07-26 23:55:292833}
2834
2835void RenderView::OnClosePage(int new_render_process_host_id,
[email protected]04b4a6c2008-08-02 00:44:472836 int new_request_id) {
initial.commit09911bf2008-07-26 23:55:292837 // TODO(creis): We'd rather use webview()->Close() here, but that currently
2838 // sets the WebView's delegate_ to NULL, preventing any JavaScript dialogs
2839 // in the onunload handler from appearing. For now, we're bypassing that and
2840 // calling the FrameLoader's CloseURL method directly. This should be
2841 // revisited to avoid having two ways to close a page. Having a single way
2842 // to close that can run onunload is also useful for fixing
2843 // http://b/issue?id=753080.
2844 WebFrame* main_frame = webview()->GetMainFrame();
2845 if (main_frame)
2846 main_frame->ClosePage();
2847
2848 Send(new ViewHostMsg_ClosePage_ACK(routing_id_,
2849 new_render_process_host_id,
[email protected]04b4a6c2008-08-02 00:44:472850 new_request_id));
initial.commit09911bf2008-07-26 23:55:292851}
2852
2853void RenderView::OnThemeChanged() {
[email protected]6c8afae52009-01-22 02:24:572854#if defined(OS_WIN)
initial.commit09911bf2008-07-26 23:55:292855 gfx::NativeTheme::instance()->CloseHandles();
2856 gfx::Rect view_rect(0, 0, size_.width(), size_.height());
2857 DidInvalidateRect(webwidget_, view_rect);
[email protected]6c8afae52009-01-22 02:24:572858#else // defined(OS_WIN)
2859 // TODO(port): we don't support theming on non-Windows platforms yet
2860 NOTIMPLEMENTED();
2861#endif
initial.commit09911bf2008-07-26 23:55:292862}
2863
[email protected]f386cca792008-08-26 02:02:182864#ifdef CHROME_PERSONALIZATION
[email protected]1cc879642008-08-26 01:27:352865void RenderView::OnPersonalizationEvent(std::string event_name,
2866 std::string event_args) {
2867 Personalization::HandleViewMsgPersonalizationEvent(personalization_,
2868 webview(),
2869 event_name,
2870 event_args);
2871}
[email protected]f386cca792008-08-26 02:02:182872#endif
[email protected]1cc879642008-08-26 01:27:352873
2874void RenderView::TransitionToCommittedForNewPage() {
[email protected]f386cca792008-08-26 02:02:182875#ifdef CHROME_PERSONALIZATION
[email protected]1cc879642008-08-26 01:27:352876 Personalization::HandleTransitionToCommittedForNewPage(personalization_);
[email protected]f386cca792008-08-26 02:02:182877#endif
[email protected]1cc879642008-08-26 01:27:352878}
2879
[email protected]f46aff62008-10-16 07:58:052880void RenderView::DidAddHistoryItem() {
[email protected]f8901082008-10-31 23:34:032881 // We don't want to update the history length for the start page
2882 // navigation.
2883 WebFrame* main_frame = webview()->GetMainFrame();
2884 DCHECK(main_frame != NULL);
2885
2886 WebDataSource* ds = main_frame->GetDataSource();
2887 DCHECK(ds != NULL);
2888
2889 const WebRequest& request = ds->GetRequest();
2890 RenderViewExtraRequestData* extra_data =
2891 static_cast<RenderViewExtraRequestData*>(request.GetExtraData());
2892
2893 if (extra_data && extra_data->transition_type == PageTransition::START_PAGE)
2894 return;
2895
[email protected]f46aff62008-10-16 07:58:052896 history_back_list_count_++;
2897 history_forward_list_count_ = 0;
2898}
2899
[email protected]28790922009-03-09 19:48:372900void RenderView::OnMessageFromExternalHost(const std::string& message,
2901 const std::string& origin,
2902 const std::string& target) {
[email protected]3ac14a052008-08-15 21:22:152903 if (message.empty())
2904 return;
2905
[email protected]28790922009-03-09 19:48:372906 external_host_bindings_.ForwardMessageFromExternalHost(message, origin,
2907 target);
[email protected]3ac14a052008-08-15 21:22:152908}
2909
[email protected]0aa55312008-10-17 21:53:082910void RenderView::OnDisassociateFromPopupCount() {
2911 if (decrement_shared_popup_at_destruction_)
2912 shared_popup_counter_->data--;
2913 shared_popup_counter_ = new SharedRenderViewCounter(0);
2914 decrement_shared_popup_at_destruction_ = false;
2915}
2916
initial.commit09911bf2008-07-26 23:55:292917std::string RenderView::GetAltHTMLForTemplate(
2918 const DictionaryValue& error_strings, int template_resource_id) const {
2919 const StringPiece template_html(
2920 ResourceBundle::GetSharedInstance().GetRawDataResource(
2921 template_resource_id));
2922
2923 if (template_html.empty()) {
2924 NOTREACHED() << "unable to load template. ID: " << template_resource_id;
2925 return "";
2926 }
2927 // "t" is the id of the templates root node.
2928 return jstemplate_builder::GetTemplateHtml(
2929 template_html, &error_strings, "t");
2930}
[email protected]0e79b9e2009-02-13 04:20:482931
2932MessageLoop* RenderView::GetMessageLoopForIO() {
2933 // Assume that we have only one RenderThread in the process and the owner loop
2934 // of RenderThread is an IO message loop.
[email protected]8930d472009-02-21 08:05:282935 if (RenderThread::current())
2936 return RenderThread::current()->owner_loop();
[email protected]0e79b9e2009-02-13 04:20:482937 return NULL;
2938}
[email protected]6f56d482009-02-20 05:02:562939
[email protected]30f75e62009-02-25 22:01:002940void RenderView::OnMoveOrResizeStarted() {
2941 if (webview())
2942 webview()->HideAutofillPopup();
2943}
2944
[email protected]30f75e62009-02-25 22:01:002945void RenderView::OnResize(const gfx::Size& new_size,
2946 const gfx::Rect& resizer_rect) {
2947 if (webview())
2948 webview()->HideAutofillPopup();
2949 RenderWidget::OnResize(new_size, resizer_rect);
2950}
[email protected]0aa477bd2009-03-23 22:21:432951
[email protected]05d478752009-04-08 23:38:162952void RenderView::OnClearFocusedNode() {
2953 if (webview())
2954 webview()->ClearFocusedNode();
2955}
2956
[email protected]309d7a282009-03-24 09:18:272957void RenderView::SendExtensionRequest(const std::string& name,
2958 const std::string& args,
2959 int callback_id,
2960 WebFrame* callback_frame) {
[email protected]309d7a282009-03-24 09:18:272961 if (callback_id != -1) {
2962 DCHECK(callback_frame) << "Callback specified without frame";
2963 pending_extension_callbacks_.AddWithID(callback_frame, callback_id);
2964 }
2965
2966 Send(new ViewHostMsg_ExtensionRequest(routing_id_, name, args, callback_id));
2967}
2968
2969void RenderView::OnExtensionResponse(int callback_id,
2970 const std::string& response) {
2971 WebFrame* web_frame = pending_extension_callbacks_.Lookup(callback_id);
2972 if (!web_frame)
2973 return; // The frame went away.
2974
[email protected]a1a0df02009-04-09 08:18:042975 ExtensionProcessBindings::ExecuteCallbackInFrame(web_frame, callback_id,
2976 response);
[email protected]309d7a282009-03-24 09:18:272977 pending_extension_callbacks_.Remove(callback_id);
2978}
[email protected]c20210e62009-04-03 21:39:262979
[email protected]e7e4f3c2009-04-21 15:24:082980// Dump all load time histograms.
[email protected]c20210e62009-04-03 21:39:262981//
[email protected]e7e4f3c2009-04-21 15:24:082982// There are 7 histograms measuring various times.
[email protected]c20210e62009-04-03 21:39:262983// The time points we keep are
2984// request: time document was requested by user
2985// start: time load of document started
2986// finishDoc: main document loaded, before onload()
2987// finish: after onload() and all resources are loaded
[email protected]e7e4f3c2009-04-21 15:24:082988// firstLayout: first layout performed
[email protected]c20210e62009-04-03 21:39:262989// The times that we histogram are
2990// requestToStart,
2991// startToFinishDoc,
2992// finishDocToFinish,
2993// startToFinish,
2994// requestToFinish,
[email protected]e7e4f3c2009-04-21 15:24:082995// requestToFirstLayout
2996// startToFirstLayout
[email protected]c20210e62009-04-03 21:39:262997//
[email protected]e7e4f3c2009-04-21 15:24:082998// It's possible for the request time not to be set, if a client
2999// redirect had been done (the user never requested the page)
3000// Also, it's possible to load a page without ever laying it out
3001// so firstLayout can be 0.
[email protected]c20210e62009-04-03 21:39:263002void RenderView::DumpLoadHistograms() const {
3003 WebFrame* main_frame = webview()->GetMainFrame();
3004 WebDataSource* ds = main_frame->GetDataSource();
[email protected]c20210e62009-04-03 21:39:263005 Time request_time = ds->GetRequestTime();
3006 Time start_load_time = ds->GetStartLoadTime();
3007 Time finish_document_load_time = ds->GetFinishDocumentLoadTime();
3008 Time finish_load_time = ds->GetFinishLoadTime();
[email protected]e7e4f3c2009-04-21 15:24:083009 Time first_layout_time = ds->GetFirstLayoutTime();
[email protected]c20210e62009-04-03 21:39:263010 TimeDelta request_to_start = start_load_time - request_time;
3011 TimeDelta start_to_finish_doc = finish_document_load_time - start_load_time;
[email protected]e7e4f3c2009-04-21 15:24:083012 TimeDelta finish_doc_to_finish =
3013 finish_load_time - finish_document_load_time;
[email protected]c20210e62009-04-03 21:39:263014 TimeDelta start_to_finish = finish_load_time - start_load_time;
3015 TimeDelta request_to_finish = finish_load_time - start_load_time;
[email protected]e7e4f3c2009-04-21 15:24:083016 TimeDelta request_to_first_layout = first_layout_time - request_time;
3017 TimeDelta start_to_first_layout = first_layout_time - start_load_time;
[email protected]c20210e62009-04-03 21:39:263018
[email protected]e7e4f3c2009-04-21 15:24:083019 // Client side redirects will have no request time
3020 if (request_time.ToInternalValue() != 0) {
3021 UMA_HISTOGRAM_TIMES("Renderer.All.RequestToStart", request_to_start);
3022 UMA_HISTOGRAM_TIMES("Renderer.All.RequestToFinish", request_to_finish);
3023 if (request_to_first_layout.ToInternalValue() >= 0) {
3024 UMA_HISTOGRAM_TIMES(
3025 "Renderer.All.RequestToFirstLayout", request_to_first_layout);
3026 }
3027 }
[email protected]c20210e62009-04-03 21:39:263028 UMA_HISTOGRAM_TIMES("Renderer.All.StartToFinishDoc", start_to_finish_doc);
3029 UMA_HISTOGRAM_TIMES("Renderer.All.FinishDocToFinish", finish_doc_to_finish);
3030 UMA_HISTOGRAM_TIMES("Renderer.All.StartToFinish", start_to_finish);
[email protected]e7e4f3c2009-04-21 15:24:083031 if (start_to_first_layout.ToInternalValue() >= 0) {
3032 UMA_HISTOGRAM_TIMES(
3033 "Renderer.All.StartToFirstLayout", start_to_first_layout);
[email protected]c20210e62009-04-03 21:39:263034 }
3035}