blob: e76d187a9e6bda2bf132a410d96e8b5a37eb138e [file] [log] [blame]
license.botbf09a502008-08-24 00:55:551// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
initial.commit09911bf2008-07-26 23:55:294
5#include "chrome/renderer/render_view.h"
6
7#include <algorithm>
8#include <string>
9#include <vector>
10
11#include "base/command_line.h"
[email protected]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"
31#include "chrome/renderer/debug_message_handler.h"
[email protected]e4ac5df2009-03-17 15:33:1132#include "chrome/renderer/devtools_agent.h"
[email protected]b75b7d072009-04-06 13:47:0033#include "chrome/renderer/devtools_agent_filter.h"
[email protected]e4ac5df2009-03-17 15:33:1134#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"
initial.commit09911bf2008-07-26 23:55:2947#include "net/base/escape.h"
48#include "net/base/net_errors.h"
[email protected]88a3ecc2009-03-19 17:36:2249#include "printing/units.h"
[email protected]c399a8a2008-11-22 19:38:0050#include "skia/ext/bitmap_platform_device.h"
[email protected]83c9e6552008-12-03 16:22:1051#include "skia/ext/image_operations.h"
[email protected]e80c73b2009-04-07 23:24:5852#include "third_party/WebKit/WebKit/chromium/public/WebDragData.h"
53#include "third_party/WebKit/WebKit/chromium/public/WebPoint.h"
[email protected]4f999132009-03-31 18:08:4054#include "third_party/WebKit/WebKit/chromium/public/WebScriptSource.h"
[email protected]ba4b17f2009-02-11 21:32:2955#include "webkit/default_plugin/default_plugin_shared.h"
initial.commit09911bf2008-07-26 23:55:2956#include "webkit/glue/dom_operations.h"
57#include "webkit/glue/dom_serializer.h"
58#include "webkit/glue/password_form.h"
[email protected]ba4b17f2009-02-11 21:32:2959#include "webkit/glue/plugins/plugin_list.h"
initial.commit09911bf2008-07-26 23:55:2960#include "webkit/glue/searchable_form_data.h"
[email protected]6a983b42009-03-20 20:12:2561#include "webkit/glue/webaccessibilitymanager_impl.h"
initial.commit09911bf2008-07-26 23:55:2962#include "webkit/glue/webdatasource.h"
[email protected]611cad42009-03-16 18:51:3463#include "webkit/glue/webdevtoolsagent_delegate.h"
initial.commit09911bf2008-07-26 23:55:2964#include "webkit/glue/webdropdata.h"
65#include "webkit/glue/weberror.h"
66#include "webkit/glue/webframe.h"
67#include "webkit/glue/webhistoryitem.h"
initial.commit09911bf2008-07-26 23:55:2968#include "webkit/glue/webkit_glue.h"
69#include "webkit/glue/webpreferences.h"
[email protected]b94d3322009-02-12 19:49:0470#include "webkit/glue/webplugin_delegate.h"
initial.commit09911bf2008-07-26 23:55:2971#include "webkit/glue/webresponse.h"
72#include "webkit/glue/weburlrequest.h"
73#include "webkit/glue/webview.h"
initial.commit09911bf2008-07-26 23:55:2974
[email protected]6c8afae52009-01-22 02:24:5775#if defined(OS_WIN)
76// TODO(port): these files are currently Windows only because they concern:
[email protected]f8b6b6f2009-03-10 16:48:2677// * logging
[email protected]6c8afae52009-01-22 02:24:5778// * printing
79// * theming
80// * views
81#include "base/gfx/gdi_util.h"
82#include "base/gfx/native_theme.h"
83#include "chrome/common/gfx/emf.h"
[email protected]fcf19542009-03-30 21:24:0784#include "chrome/views/controls/message_box_view.h"
[email protected]6c8afae52009-01-22 02:24:5785#include "skia/ext/vector_canvas.h"
[email protected]6c8afae52009-01-22 02:24:5786#endif
87
[email protected]c20210e62009-04-03 21:39:2688using base::Time;
[email protected]e1acf6f2008-10-27 20:43:3389using base::TimeDelta;
[email protected]6a983b42009-03-20 20:12:2590using webkit_glue::WebAccessibility;
[email protected]0dea3ea2009-03-31 23:30:5991using WebKit::WebConsoleMessage;
[email protected]e80c73b2009-04-07 23:24:5892using WebKit::WebDragData;
[email protected]4f999132009-03-31 18:08:4093using WebKit::WebScriptSource;
[email protected]e1acf6f2008-10-27 20:43:3394
initial.commit09911bf2008-07-26 23:55:2995//-----------------------------------------------------------------------------
96
97// define to write the time necessary for thumbnail/DOM text retrieval,
98// respectively, into the system debug log
99// #define TIME_BITMAP_RETRIEVAL
100// #define TIME_TEXT_RETRIEVAL
101
102// maximum number of characters in the document to index, any text beyond this
103// point will be clipped
[email protected]6c8afae52009-01-22 02:24:57104static const size_t kMaxIndexChars = 65535;
initial.commit09911bf2008-07-26 23:55:29105
106// Size of the thumbnails that we'll generate
107static const int kThumbnailWidth = 196;
108static const int kThumbnailHeight = 136;
109
110// Delay in milliseconds that we'll wait before capturing the page contents
111// and thumbnail.
112static const int kDelayForCaptureMs = 500;
113
114// Typically, we capture the page data once the page is loaded.
115// Sometimes, the page never finishes to load, preventing the page capture
116// To workaround this problem, we always perform a capture after the following
117// delay.
118static const int kDelayForForcedCaptureMs = 6000;
119
[email protected]81a34412009-01-05 19:17:24120// The default value for RenderView.delay_seconds_for_form_state_sync_, see
121// that variable for more.
122const int kDefaultDelaySecondsForFormStateSync = 5;
initial.commit09911bf2008-07-26 23:55:29123
124// The next available page ID to use. This ensures that the page IDs are
125// globally unique in the renderer.
126static int32 next_page_id_ = 1;
127
[email protected]0aa55312008-10-17 21:53:08128// The maximum number of popups that can be spawned from one page.
129static const int kMaximumNumberOfUnacknowledgedPopups = 25;
130
initial.commit09911bf2008-07-26 23:55:29131static const char* const kUnreachableWebDataURL =
[email protected]9527f9c2009-01-29 18:35:42132 "chrome-ui://chromewebdata/";
initial.commit09911bf2008-07-26 23:55:29133
[email protected]50b691c2008-10-31 19:08:35134static const char* const kBackForwardNavigationScheme = "history";
135
initial.commit09911bf2008-07-26 23:55:29136namespace {
137
138// Associated with browser-initiated navigations to hold tracking data.
139class RenderViewExtraRequestData : public WebRequest::ExtraData {
140 public:
141 RenderViewExtraRequestData(int32 pending_page_id,
[email protected]c20210e62009-04-03 21:39:26142 PageTransition::Type transition,
143 Time request_time)
[email protected]6c8afae52009-01-22 02:24:57144 : transition_type(transition),
[email protected]c20210e62009-04-03 21:39:26145 request_time(request_time),
[email protected]6c8afae52009-01-22 02:24:57146 request_committed(false),
147 pending_page_id_(pending_page_id) {
initial.commit09911bf2008-07-26 23:55:29148 }
149
150 // Contains the page_id for this navigation or -1 if there is none yet.
151 int32 pending_page_id() const { return pending_page_id_; }
152
153 // Is this a new navigation?
154 bool is_new_navigation() const { return pending_page_id_ == -1; }
155
156 // Contains the transition type that the browser specified when it
157 // initiated the load.
158 PageTransition::Type transition_type;
[email protected]c20210e62009-04-03 21:39:26159 Time request_time;
initial.commit09911bf2008-07-26 23:55:29160
161 // True if we have already processed the "DidCommitLoad" event for this
162 // request. Used by session history.
163 bool request_committed;
164
165 private:
166 int32 pending_page_id_;
167
[email protected]4f3dc372009-02-24 00:10:29168 DISALLOW_COPY_AND_ASSIGN(RenderViewExtraRequestData);
initial.commit09911bf2008-07-26 23:55:29169};
170
171} // namespace
172
173///////////////////////////////////////////////////////////////////////////////
174
[email protected]81a34412009-01-05 19:17:24175RenderView::RenderView(RenderThreadBase* render_thread)
176 : RenderWidget(render_thread, true),
[email protected]81e63782009-02-27 19:35:09177 enabled_bindings_(0),
[email protected]e75cb49e2009-01-05 23:13:21178 target_url_status_(TARGET_NONE),
[email protected]81a34412009-01-05 19:17:24179 is_loading_(false),
[email protected]e75cb49e2009-01-05 23:13:21180 navigation_gesture_(NavigationGestureUnknown),
[email protected]81a34412009-01-05 19:17:24181 page_id_(-1),
182 last_page_id_sent_to_browser_(-1),
183 last_indexed_page_id_(-1),
[email protected]81a34412009-01-05 19:17:24184 opened_by_user_gesture_(true),
[email protected]bb063b72009-03-27 23:18:50185 ALLOW_THIS_IN_INITIALIZER_LIST(method_factory_(this)),
[email protected]81a34412009-01-05 19:17:24186 first_default_plugin_(NULL),
[email protected]e4ac5df2009-03-17 15:33:11187 devtools_agent_(NULL),
[email protected]b75b7d072009-04-06 13:47:00188 devtools_agent_filter_(NULL),
[email protected]e4ac5df2009-03-17 15:33:11189 devtools_client_(NULL),
[email protected]81a34412009-01-05 19:17:24190 history_back_list_count_(0),
191 history_forward_list_count_(0),
192 disable_popup_blocking_(false),
193 has_unload_listener_(false),
194 decrement_shared_popup_at_destruction_(false),
[email protected]81a34412009-01-05 19:17:24195 form_field_autofill_request_id_(0),
196 popup_notification_visible_(false),
197 delay_seconds_for_form_state_sync_(kDefaultDelaySecondsForFormStateSync) {
[email protected]3a453fa2008-08-15 18:46:34198#ifdef CHROME_PERSONALIZATION
199 personalization_ = Personalization::CreateRendererPersonalization();
200#endif
initial.commit09911bf2008-07-26 23:55:29201}
202
203RenderView::~RenderView() {
[email protected]0aa55312008-10-17 21:53:08204 if (decrement_shared_popup_at_destruction_)
205 shared_popup_counter_->data--;
206
initial.commit09911bf2008-07-26 23:55:29207 // Clear any back-pointers that might still be held by plugins.
208 PluginDelegateList::iterator it = plugin_delegates_.begin();
209 while (it != plugin_delegates_.end()) {
210 (*it)->DropRenderView();
211 it = plugin_delegates_.erase(it);
212 }
213
[email protected]81a34412009-01-05 19:17:24214 render_thread_->RemoveFilter(debug_message_handler_);
[email protected]b75b7d072009-04-06 13:47:00215 render_thread_->RemoveFilter(devtools_agent_filter_);
[email protected]3a453fa2008-08-15 18:46:34216
217#ifdef CHROME_PERSONALIZATION
218 Personalization::CleanupRendererPersonalization(personalization_);
219 personalization_ = NULL;
220#endif
initial.commit09911bf2008-07-26 23:55:29221}
222
223/*static*/
[email protected]0aa55312008-10-17 21:53:08224RenderView* RenderView::Create(
[email protected]81a34412009-01-05 19:17:24225 RenderThreadBase* render_thread,
[email protected]18bcc3c2009-01-27 21:39:15226 gfx::NativeViewId parent_hwnd,
[email protected]1c4947f2009-01-15 22:25:11227 base::WaitableEvent* modal_dialog_event,
[email protected]0aa55312008-10-17 21:53:08228 int32 opener_id,
229 const WebPreferences& webkit_prefs,
230 SharedRenderViewCounter* counter,
231 int32 routing_id) {
initial.commit09911bf2008-07-26 23:55:29232 DCHECK(routing_id != MSG_ROUTING_NONE);
[email protected]81a34412009-01-05 19:17:24233 scoped_refptr<RenderView> view = new RenderView(render_thread);
initial.commit09911bf2008-07-26 23:55:29234 view->Init(parent_hwnd,
235 modal_dialog_event,
236 opener_id,
237 webkit_prefs,
[email protected]0aa55312008-10-17 21:53:08238 counter,
initial.commit09911bf2008-07-26 23:55:29239 routing_id); // adds reference
240 return view;
241}
242
243/*static*/
244void RenderView::SetNextPageID(int32 next_page_id) {
245 // This method should only be called during process startup, and the given
246 // page id had better not exceed our current next page id!
247 DCHECK(next_page_id_ == 1);
248 DCHECK(next_page_id >= next_page_id_);
249 next_page_id_ = next_page_id;
250}
251
252void RenderView::PluginDestroyed(WebPluginDelegateProxy* proxy) {
253 PluginDelegateList::iterator it =
254 std::find(plugin_delegates_.begin(), plugin_delegates_.end(), proxy);
255 DCHECK(it != plugin_delegates_.end());
256 plugin_delegates_.erase(it);
257 // If the plugin is deleted, we need to clear our reference in case user
258 // clicks the info bar to install. Unfortunately we are getting
259 // PluginDestroyed in single process mode. However, that is not a huge
260 // concern.
[email protected]6c8afae52009-01-22 02:24:57261#if defined(OS_WIN)
initial.commit09911bf2008-07-26 23:55:29262 if (proxy == first_default_plugin_)
263 first_default_plugin_ = NULL;
[email protected]6c8afae52009-01-22 02:24:57264#else
265 // TODO(port): because of the headers that we aren't including, the compiler
266 // has only seen a forward decl, not the subclass relation. Thus it doesn't
267 // know that the two pointer types compared above are comparable. Once we
268 // port and include the headers this problem should go away.
269 NOTIMPLEMENTED();
270#endif
initial.commit09911bf2008-07-26 23:55:29271}
272
[email protected]690a99c2009-01-06 16:48:45273void RenderView::PluginCrashed(const FilePath& plugin_path) {
initial.commit09911bf2008-07-26 23:55:29274 Send(new ViewHostMsg_CrashedPlugin(routing_id_, plugin_path));
275}
276
277
278void RenderView::JSOutOfMemory() {
279 Send(new ViewHostMsg_JSOutOfMemory(routing_id_));
280}
281
[email protected]18bcc3c2009-01-27 21:39:15282void RenderView::Init(gfx::NativeViewId parent_hwnd,
[email protected]1c4947f2009-01-15 22:25:11283 base::WaitableEvent* modal_dialog_event,
initial.commit09911bf2008-07-26 23:55:29284 int32 opener_id,
285 const WebPreferences& webkit_prefs,
[email protected]0aa55312008-10-17 21:53:08286 SharedRenderViewCounter* counter,
initial.commit09911bf2008-07-26 23:55:29287 int32 routing_id) {
288 DCHECK(!webview());
289
290 if (opener_id != MSG_ROUTING_NONE)
291 opener_id_ = opener_id;
292
[email protected]0aa55312008-10-17 21:53:08293 if (counter) {
294 shared_popup_counter_ = counter;
295 shared_popup_counter_->data++;
296 decrement_shared_popup_at_destruction_ = true;
297 } else {
298 shared_popup_counter_ = new SharedRenderViewCounter(0);
299 decrement_shared_popup_at_destruction_ = false;
300 }
301
[email protected]b75b7d072009-04-06 13:47:00302 devtools_agent_.reset(new DevToolsAgent(routing_id, this));
[email protected]9b9d7282009-04-08 14:13:04303
[email protected]c5b3b5e2009-02-13 06:41:11304 webwidget_ = WebView::Create(this, webkit_prefs);
initial.commit09911bf2008-07-26 23:55:29305
[email protected]9b9d7282009-04-08 14:13:04306 devtools_agent_filter_ = new DevToolsAgentFilter(
307 webview()->GetWebDevToolsAgent(),
308 routing_id);
309
[email protected]2e417c82009-04-02 22:30:26310#if defined(OS_LINUX)
311 // We have to enable ourselves as the editor delegate on linux so we can copy
312 // text selections to the X clipboard.
313 webview()->SetUseEditorDelegate(true);
314#endif
315
initial.commit09911bf2008-07-26 23:55:29316 // Don't let WebCore keep a B/F list - we have our own.
317 // We let it keep 1 entry because FrameLoader::goToItem expects an item in the
318 // backForwardList, which is used only in ASSERTs.
319 webview()->SetBackForwardListSize(1);
320
321 routing_id_ = routing_id;
[email protected]81a34412009-01-05 19:17:24322 render_thread_->AddRoute(routing_id_, this);
initial.commit09911bf2008-07-26 23:55:29323 // Take a reference on behalf of the RenderThread. This will be balanced
324 // when we receive ViewMsg_Close.
325 AddRef();
326
327 // If this is a popup, we must wait for the CreatingNew_ACK message before
328 // completing initialization. Otherwise, we can finish it now.
329 if (opener_id == MSG_ROUTING_NONE) {
330 did_show_ = true;
331 CompleteInit(parent_hwnd);
332 }
333
334 host_window_ = parent_hwnd;
[email protected]1c4947f2009-01-15 22:25:11335 modal_dialog_event_.reset(modal_dialog_event);
initial.commit09911bf2008-07-26 23:55:29336
[email protected]bb975362009-01-21 01:00:22337 const CommandLine& command_line = *CommandLine::ForCurrentProcess();
[email protected]81e63782009-02-27 19:35:09338 if (command_line.HasSwitch(switches::kDomAutomationController))
339 enabled_bindings_ |= BindingsPolicy::DOM_AUTOMATION;
initial.commit09911bf2008-07-26 23:55:29340 disable_popup_blocking_ =
341 command_line.HasSwitch(switches::kDisablePopupBlocking);
342
343 debug_message_handler_ = new DebugMessageHandler(this);
[email protected]81a34412009-01-05 19:17:24344 render_thread_->AddFilter(debug_message_handler_);
[email protected]b75b7d072009-04-06 13:47:00345 render_thread_->AddFilter(devtools_agent_filter_);
initial.commit09911bf2008-07-26 23:55:29346}
347
348void RenderView::OnMessageReceived(const IPC::Message& message) {
[email protected]f8b6b6f2009-03-10 16:48:26349 WebFrame* main_frame = webview() ? webview()->GetMainFrame() : NULL;
350 renderer_logging::ScopedActiveRenderingURLSetter url_setter(
351 main_frame ? main_frame->GetURL() : GURL());
[email protected]f8b6b6f2009-03-10 16:48:26352
[email protected]b2abac72009-02-26 12:39:28353 // If this is developer tools renderer intercept tools messages first.
[email protected]e4ac5df2009-03-17 15:33:11354 if (devtools_client_.get() && devtools_client_->OnMessageReceived(message))
[email protected]b2abac72009-02-26 12:39:28355 return;
[email protected]b75b7d072009-04-06 13:47:00356 if (devtools_agent_->OnMessageReceived(message))
357 return;
[email protected]b2abac72009-02-26 12:39:28358
initial.commit09911bf2008-07-26 23:55:29359 IPC_BEGIN_MESSAGE_MAP(RenderView, message)
initial.commit09911bf2008-07-26 23:55:29360 IPC_MESSAGE_HANDLER(ViewMsg_CaptureThumbnail, SendThumbnail)
initial.commit09911bf2008-07-26 23:55:29361 IPC_MESSAGE_HANDLER(ViewMsg_PrintPages, OnPrintPages)
362 IPC_MESSAGE_HANDLER(ViewMsg_Navigate, OnNavigate)
363 IPC_MESSAGE_HANDLER(ViewMsg_Stop, OnStop)
364 IPC_MESSAGE_HANDLER(ViewMsg_LoadAlternateHTMLText, OnLoadAlternateHTMLText)
365 IPC_MESSAGE_HANDLER(ViewMsg_StopFinding, OnStopFinding)
366 IPC_MESSAGE_HANDLER(ViewMsg_Undo, OnUndo)
367 IPC_MESSAGE_HANDLER(ViewMsg_Redo, OnRedo)
368 IPC_MESSAGE_HANDLER(ViewMsg_Cut, OnCut)
369 IPC_MESSAGE_HANDLER(ViewMsg_Copy, OnCopy)
370 IPC_MESSAGE_HANDLER(ViewMsg_Paste, OnPaste)
371 IPC_MESSAGE_HANDLER(ViewMsg_Replace, OnReplace)
[email protected]bbbd545c2008-12-15 20:18:04372 IPC_MESSAGE_HANDLER(ViewMsg_ToggleSpellCheck, OnToggleSpellCheck)
initial.commit09911bf2008-07-26 23:55:29373 IPC_MESSAGE_HANDLER(ViewMsg_Delete, OnDelete)
374 IPC_MESSAGE_HANDLER(ViewMsg_SelectAll, OnSelectAll)
375 IPC_MESSAGE_HANDLER(ViewMsg_CopyImageAt, OnCopyImageAt)
376 IPC_MESSAGE_HANDLER(ViewMsg_Find, OnFind)
[email protected]630e26b2008-10-14 22:55:17377 IPC_MESSAGE_HANDLER(ViewMsg_Zoom, OnZoom)
[email protected]ea8c7452009-04-02 20:47:06378 IPC_MESSAGE_HANDLER(ViewMsg_InsertText, OnInsertText)
initial.commit09911bf2008-07-26 23:55:29379 IPC_MESSAGE_HANDLER(ViewMsg_SetPageEncoding, OnSetPageEncoding)
380 IPC_MESSAGE_HANDLER(ViewMsg_InspectElement, OnInspectElement)
381 IPC_MESSAGE_HANDLER(ViewMsg_ShowJavaScriptConsole, OnShowJavaScriptConsole)
[email protected]b2abac72009-02-26 12:39:28382 IPC_MESSAGE_HANDLER(ViewMsg_SetupDevToolsClient, OnSetupDevToolsClient)
initial.commit09911bf2008-07-26 23:55:29383 IPC_MESSAGE_HANDLER(ViewMsg_DownloadImage, OnDownloadImage)
384 IPC_MESSAGE_HANDLER(ViewMsg_ScriptEvalRequest, OnScriptEvalRequest)
[email protected]1810e132009-03-24 23:35:48385 IPC_MESSAGE_HANDLER(ViewMsg_CSSInsertRequest, OnCSSInsertRequest)
initial.commit09911bf2008-07-26 23:55:29386 IPC_MESSAGE_HANDLER(ViewMsg_AddMessageToConsole, OnAddMessageToConsole)
387 IPC_MESSAGE_HANDLER(ViewMsg_DebugAttach, OnDebugAttach)
[email protected]88010e082008-08-29 11:07:40388 IPC_MESSAGE_HANDLER(ViewMsg_DebugDetach, OnDebugDetach)
initial.commit09911bf2008-07-26 23:55:29389 IPC_MESSAGE_HANDLER(ViewMsg_ReservePageIDRange, OnReservePageIDRange)
390 IPC_MESSAGE_HANDLER(ViewMsg_UploadFile, OnUploadFileRequest)
391 IPC_MESSAGE_HANDLER(ViewMsg_FormFill, OnFormFill)
392 IPC_MESSAGE_HANDLER(ViewMsg_FillPasswordForm, OnFillPasswordForm)
393 IPC_MESSAGE_HANDLER(ViewMsg_DragTargetDragEnter, OnDragTargetDragEnter)
394 IPC_MESSAGE_HANDLER(ViewMsg_DragTargetDragOver, OnDragTargetDragOver)
395 IPC_MESSAGE_HANDLER(ViewMsg_DragTargetDragLeave, OnDragTargetDragLeave)
396 IPC_MESSAGE_HANDLER(ViewMsg_DragTargetDrop, OnDragTargetDrop)
[email protected]18cb2572008-08-21 20:34:45397 IPC_MESSAGE_HANDLER(ViewMsg_AllowBindings, OnAllowBindings)
initial.commit09911bf2008-07-26 23:55:29398 IPC_MESSAGE_HANDLER(ViewMsg_SetDOMUIProperty, OnSetDOMUIProperty)
[email protected]266eb6f2008-09-30 23:56:50399 IPC_MESSAGE_HANDLER(ViewMsg_DragSourceEndedOrMoved,
400 OnDragSourceEndedOrMoved)
initial.commit09911bf2008-07-26 23:55:29401 IPC_MESSAGE_HANDLER(ViewMsg_DragSourceSystemDragEnded,
402 OnDragSourceSystemDragEnded)
403 IPC_MESSAGE_HANDLER(ViewMsg_SetInitialFocus, OnSetInitialFocus)
404 IPC_MESSAGE_HANDLER(ViewMsg_FindReplyACK, OnFindReplyAck)
405 IPC_MESSAGE_HANDLER(ViewMsg_UpdateTargetURL_ACK, OnUpdateTargetURLAck)
406 IPC_MESSAGE_HANDLER(ViewMsg_UpdateWebPreferences, OnUpdateWebPreferences)
407 IPC_MESSAGE_HANDLER(ViewMsg_SetAltErrorPageURL, OnSetAltErrorPageURL)
408 IPC_MESSAGE_HANDLER(ViewMsg_InstallMissingPlugin, OnInstallMissingPlugin)
409 IPC_MESSAGE_HANDLER(ViewMsg_RunFileChooserResponse, OnFileChooserResponse)
410 IPC_MESSAGE_HANDLER(ViewMsg_EnableViewSourceMode, OnEnableViewSourceMode)
411 IPC_MESSAGE_HANDLER(ViewMsg_UpdateBackForwardListCount,
412 OnUpdateBackForwardListCount)
413 IPC_MESSAGE_HANDLER(ViewMsg_GetAllSavableResourceLinksForCurrentPage,
414 OnGetAllSavableResourceLinksForCurrentPage)
[email protected]f09c7182009-03-10 12:54:04415 IPC_MESSAGE_HANDLER(
416 ViewMsg_GetSerializedHtmlDataForCurrentPageWithLocalLinks,
417 OnGetSerializedHtmlDataForCurrentPageWithLocalLinks)
initial.commit09911bf2008-07-26 23:55:29418 IPC_MESSAGE_HANDLER(ViewMsg_GetApplicationInfo, OnGetApplicationInfo)
[email protected]266eb6f2008-09-30 23:56:50419 IPC_MESSAGE_HANDLER(ViewMsg_GetAccessibilityInfo, OnGetAccessibilityInfo)
420 IPC_MESSAGE_HANDLER(ViewMsg_ClearAccessibilityInfo,
421 OnClearAccessibilityInfo)
initial.commit09911bf2008-07-26 23:55:29422 IPC_MESSAGE_HANDLER(ViewMsg_ShouldClose, OnMsgShouldClose)
423 IPC_MESSAGE_HANDLER(ViewMsg_ClosePage, OnClosePage)
424 IPC_MESSAGE_HANDLER(ViewMsg_ThemeChanged, OnThemeChanged)
[email protected]3c17b9c2008-08-26 02:08:00425#ifdef CHROME_PERSONALIZATION
[email protected]1cc879642008-08-26 01:27:35426 IPC_MESSAGE_HANDLER(ViewMsg_PersonalizationEvent, OnPersonalizationEvent)
[email protected]3c17b9c2008-08-26 02:08:00427#endif
[email protected]18cb2572008-08-21 20:34:45428 IPC_MESSAGE_HANDLER(ViewMsg_HandleMessageFromExternalHost,
429 OnMessageFromExternalHost)
[email protected]0aa55312008-10-17 21:53:08430 IPC_MESSAGE_HANDLER(ViewMsg_DisassociateFromPopupCount,
431 OnDisassociateFromPopupCount)
[email protected]0ebf3872008-11-07 21:35:03432 IPC_MESSAGE_HANDLER(ViewMsg_AutofillSuggestions,
433 OnReceivedAutofillSuggestions)
[email protected]634a6f92008-12-01 21:39:31434 IPC_MESSAGE_HANDLER(ViewMsg_PopupNotificationVisiblityChanged,
435 OnPopupNotificationVisiblityChanged)
[email protected]6f56d482009-02-20 05:02:56436 IPC_MESSAGE_HANDLER(ViewMsg_RequestAudioPacket, OnRequestAudioPacket)
437 IPC_MESSAGE_HANDLER(ViewMsg_NotifyAudioStreamCreated, OnAudioStreamCreated)
438 IPC_MESSAGE_HANDLER(ViewMsg_NotifyAudioStreamStateChanged,
439 OnAudioStreamStateChanged)
440 IPC_MESSAGE_HANDLER(ViewMsg_NotifyAudioStreamVolume, OnAudioStreamVolume)
[email protected]30f75e62009-02-25 22:01:00441 IPC_MESSAGE_HANDLER(ViewMsg_MoveOrResizeStarted, OnMoveOrResizeStarted)
[email protected]309d7a282009-03-24 09:18:27442 IPC_MESSAGE_HANDLER(ViewMsg_ExtensionResponse, OnExtensionResponse)
[email protected]2e417c82009-04-02 22:30:26443 IPC_MESSAGE_HANDLER(ViewMsg_RequestSelectionText, OnRequestSelectionText)
[email protected]634a6f92008-12-01 21:39:31444
initial.commit09911bf2008-07-26 23:55:29445 // Have the super handle all other messages.
446 IPC_MESSAGE_UNHANDLED(RenderWidget::OnMessageReceived(message))
447 IPC_END_MESSAGE_MAP()
448}
449
initial.commit09911bf2008-07-26 23:55:29450void RenderView::SendThumbnail() {
451 WebFrame* main_frame = webview()->GetMainFrame();
452 if (!main_frame)
453 return;
454
455 // get the URL for this page
456 GURL url(main_frame->GetURL());
457 if (url.is_empty())
458 return;
459
460 if (size_.IsEmpty())
461 return; // Don't create an empty thumbnail!
462
463 ThumbnailScore score;
464 SkBitmap thumbnail;
[email protected]b6e4bec2008-11-12 01:17:15465 if (!CaptureThumbnail(main_frame, kThumbnailWidth, kThumbnailHeight,
466 &thumbnail, &score))
467 return;
468
initial.commit09911bf2008-07-26 23:55:29469 // send the thumbnail message to the browser process
[email protected]674741932009-02-04 23:44:46470 Send(new ViewHostMsg_Thumbnail(routing_id_, url, score, thumbnail));
initial.commit09911bf2008-07-26 23:55:29471}
472
[email protected]2e417c82009-04-02 22:30:26473void RenderView::OnRequestSelectionText() {
474 Send(new ViewHostMsg_SetSelectionText(routing_id_, selection_text_));
475}
476
initial.commit09911bf2008-07-26 23:55:29477void RenderView::PrintPage(const ViewMsg_PrintPage_Params& params,
[email protected]88a3ecc2009-03-19 17:36:22478 const gfx::Size& canvas_size,
initial.commit09911bf2008-07-26 23:55:29479 WebFrame* frame) {
[email protected]6c8afae52009-01-22 02:24:57480#if defined(OS_WIN)
initial.commit09911bf2008-07-26 23:55:29481 // Generate a memory-based EMF file. The EMF will use the current screen's
482 // DPI.
483 gfx::Emf emf;
484
485 emf.CreateDc(NULL, NULL);
486 HDC hdc = emf.hdc();
487 DCHECK(hdc);
[email protected]21f527e2008-12-17 23:29:40488 skia::PlatformDeviceWin::InitializeDC(hdc);
[email protected]0e92fa32009-03-31 20:39:33489 // Since WebKit extends the page width depending on the magical shrink
[email protected]0dea3ea2009-03-31 23:30:59490 // factor we make sure the canvas covers the worst case scenario
[email protected]0e92fa32009-03-31 20:39:33491 // (x2.0 currently). PrintContext will then set the correct clipping region.
492 int size_x = static_cast<int>(canvas_size.width() * params.params.max_shrink);
493 int size_y = static_cast<int>(canvas_size.height() *
494 params.params.max_shrink);
[email protected]88a3ecc2009-03-19 17:36:22495 // Calculate the dpi adjustment.
496 float shrink = static_cast<float>(canvas_size.width()) /
497 params.params.printable_size.width();
initial.commit09911bf2008-07-26 23:55:29498#if 0
499 // TODO(maruel): This code is kept for testing until the 100% GDI drawing
500 // code is stable. maruels use this code's output as a reference when the
501 // GDI drawing code fails.
502
503 // Mix of Skia and GDI based.
[email protected]88a3ecc2009-03-19 17:36:22504 skia::PlatformCanvasWin canvas(size_x, size_y, true);
initial.commit09911bf2008-07-26 23:55:29505 canvas.drawARGB(255, 255, 255, 255, SkPorterDuff::kSrc_Mode);
[email protected]88a3ecc2009-03-19 17:36:22506 float webkit_shrink = frame->PrintPage(params.page_number, &canvas);
507 if (shrink <= 0) {
initial.commit09911bf2008-07-26 23:55:29508 NOTREACHED() << "Printing page " << params.page_number << " failed.";
[email protected]88a3ecc2009-03-19 17:36:22509 } else {
510 // Update the dpi adjustment with the "page shrink" calculated in webkit.
511 shrink /= webkit_shrink;
initial.commit09911bf2008-07-26 23:55:29512 }
513
514 // Create a BMP v4 header that we can serialize.
515 BITMAPV4HEADER bitmap_header;
[email protected]88a3ecc2009-03-19 17:36:22516 gfx::CreateBitmapV4Header(size_x, size_y, &bitmap_header);
initial.commit09911bf2008-07-26 23:55:29517 const SkBitmap& src_bmp = canvas.getDevice()->accessBitmap(true);
518 SkAutoLockPixels src_lock(src_bmp);
519 int retval = StretchDIBits(hdc,
520 0,
521 0,
[email protected]88a3ecc2009-03-19 17:36:22522 size_x, size_y,
initial.commit09911bf2008-07-26 23:55:29523 0, 0,
[email protected]88a3ecc2009-03-19 17:36:22524 size_x, size_y,
initial.commit09911bf2008-07-26 23:55:29525 src_bmp.getPixels(),
526 reinterpret_cast<BITMAPINFO*>(&bitmap_header),
527 DIB_RGB_COLORS,
528 SRCCOPY);
529 DCHECK(retval != GDI_ERROR);
530#else
531 // 100% GDI based.
[email protected]88a3ecc2009-03-19 17:36:22532 skia::VectorCanvas canvas(hdc, size_x, size_y);
533 float webkit_shrink = frame->PrintPage(params.page_number, &canvas);
534 if (shrink <= 0) {
initial.commit09911bf2008-07-26 23:55:29535 NOTREACHED() << "Printing page " << params.page_number << " failed.";
[email protected]88a3ecc2009-03-19 17:36:22536 } else {
537 // Update the dpi adjustment with the "page shrink" calculated in webkit.
538 shrink /= webkit_shrink;
initial.commit09911bf2008-07-26 23:55:29539 }
540#endif
541
542 // Done printing. Close the device context to retrieve the compiled EMF.
543 if (!emf.CloseDc()) {
544 NOTREACHED() << "EMF failed";
545 }
546
547 // Get the size of the compiled EMF.
548 unsigned buf_size = emf.GetDataSize();
549 DCHECK(buf_size > 128);
550 ViewHostMsg_DidPrintPage_Params page_params;
551 page_params.data_size = 0;
552 page_params.emf_data_handle = NULL;
553 page_params.page_number = params.page_number;
554 page_params.document_cookie = params.params.document_cookie;
555 page_params.actual_shrink = shrink;
[email protected]176aa482008-11-14 03:25:15556 base::SharedMemory shared_buf;
initial.commit09911bf2008-07-26 23:55:29557
558 // http://msdn2.microsoft.com/en-us/library/ms535522.aspx
559 // Windows 2000/XP: When a page in a spooled file exceeds approximately 350
560 // MB, it can fail to print and not send an error message.
561 if (buf_size < 350*1024*1024) {
562 // Allocate a shared memory buffer to hold the generated EMF data.
563 if (shared_buf.Create(L"", false, false, buf_size) &&
564 shared_buf.Map(buf_size)) {
565 // Copy the bits into shared memory.
566 if (emf.GetData(shared_buf.memory(), buf_size)) {
567 page_params.emf_data_handle = shared_buf.handle();
568 page_params.data_size = buf_size;
569 } else {
570 NOTREACHED() << "GetData() failed";
571 }
572 shared_buf.Unmap();
573 } else {
574 NOTREACHED() << "Buffer allocation failed";
575 }
576 } else {
577 NOTREACHED() << "Buffer too large: " << buf_size;
578 }
579 emf.CloseEmf();
580 if (Send(new ViewHostMsg_DuplicateSection(routing_id_,
581 page_params.emf_data_handle,
582 &page_params.emf_data_handle))) {
583 Send(new ViewHostMsg_DidPrintPage(routing_id_, page_params));
584 }
[email protected]6c8afae52009-01-22 02:24:57585#else // defined(OS_WIN)
586 // TODO(port) implement printing
587 NOTIMPLEMENTED();
588#endif
initial.commit09911bf2008-07-26 23:55:29589}
590
[email protected]068637222009-01-29 16:58:07591void RenderView::OnPrintPages() {
initial.commit09911bf2008-07-26 23:55:29592 DCHECK(webview());
[email protected]068637222009-01-29 16:58:07593 if (webview()) {
594 // The renderer own the control flow as if it was a window.print() call.
595 ScriptedPrint(webview()->GetMainFrame());
initial.commit09911bf2008-07-26 23:55:29596 }
initial.commit09911bf2008-07-26 23:55:29597}
598
599void RenderView::PrintPages(const ViewMsg_PrintPages_Params& params,
600 WebFrame* frame) {
[email protected]88a3ecc2009-03-19 17:36:22601 int page_count = 0;
602 gfx::Size canvas_size;
603 canvas_size.set_width(
604 printing::ConvertUnit(params.params.printable_size.width(),
605 static_cast<int>(params.params.dpi),
606 params.params.desired_dpi));
607 canvas_size.set_height(
608 printing::ConvertUnit(params.params.printable_size.height(),
609 static_cast<int>(params.params.dpi),
610 params.params.desired_dpi));
611 frame->BeginPrint(canvas_size, &page_count);
initial.commit09911bf2008-07-26 23:55:29612 Send(new ViewHostMsg_DidGetPrintedPagesCount(routing_id_,
613 params.params.document_cookie,
[email protected]88a3ecc2009-03-19 17:36:22614 page_count));
615 if (page_count) {
initial.commit09911bf2008-07-26 23:55:29616 ViewMsg_PrintPage_Params page_params;
617 page_params.params = params.params;
618 if (params.pages.empty()) {
[email protected]88a3ecc2009-03-19 17:36:22619 for (int i = 0; i < page_count; ++i) {
initial.commit09911bf2008-07-26 23:55:29620 page_params.page_number = i;
[email protected]88a3ecc2009-03-19 17:36:22621 PrintPage(page_params, canvas_size, frame);
initial.commit09911bf2008-07-26 23:55:29622 }
623 } else {
624 for (size_t i = 0; i < params.pages.size(); ++i) {
625 page_params.page_number = params.pages[i];
[email protected]88a3ecc2009-03-19 17:36:22626 PrintPage(page_params, canvas_size, frame);
initial.commit09911bf2008-07-26 23:55:29627 }
628 }
629 }
[email protected]88a3ecc2009-03-19 17:36:22630 frame->EndPrint();
initial.commit09911bf2008-07-26 23:55:29631}
632
633void RenderView::CapturePageInfo(int load_id, bool preliminary_capture) {
634 if (load_id != page_id_)
635 return; // this capture call is no longer relevant due to navigation
636 if (load_id == last_indexed_page_id_)
637 return; // we already indexed this page
638
639 if (!webview())
640 return;
641
642 WebFrame* main_frame = webview()->GetMainFrame();
643 if (!main_frame)
644 return;
645
646 // Don't index/capture pages that are in view source mode.
647 if (main_frame->GetInViewSourceMode())
648 return;
649
650 // Don't index/capture pages that failed to load. This only checks the top
651 // level frame so the thumbnail may contain a frame that failed to load.
652 WebDataSource* ds = main_frame->GetDataSource();
653 if (ds && ds->HasUnreachableURL())
654 return;
655
656 if (!preliminary_capture)
657 last_indexed_page_id_ = load_id;
658
659 // get the URL for this page
660 GURL url(main_frame->GetURL());
661 if (url.is_empty())
662 return;
663
664 // full text
665 std::wstring contents;
666 CaptureText(main_frame, &contents);
667 if (contents.size()) {
668 // Send the text to the browser for indexing.
669 Send(new ViewHostMsg_PageContents(url, load_id, contents));
670 }
671
672 // thumbnail
673 SendThumbnail();
674}
675
676void RenderView::CaptureText(WebFrame* frame, std::wstring* contents) {
677 contents->clear();
678 if (!frame)
679 return;
680
[email protected]0faf0bd92008-09-09 20:53:27681 // Don't index any https pages. People generally don't want their bank
682 // accounts, etc. indexed on their computer, especially since some of these
683 // things are not marked cachable.
684 // TODO(brettw) we may want to consider more elaborate heuristics such as
685 // the cachability of the page. We may also want to consider subframes (this
686 // test will still index subframes if the subframe is SSL).
687 if (frame->GetURL().SchemeIsSecure())
688 return;
689
initial.commit09911bf2008-07-26 23:55:29690#ifdef TIME_TEXT_RETRIEVAL
691 double begin = time_util::GetHighResolutionTimeNow();
692#endif
693
694 // get the contents of the frame
695 frame->GetContentAsPlainText(kMaxIndexChars, contents);
696
697#ifdef TIME_TEXT_RETRIEVAL
698 double end = time_util::GetHighResolutionTimeNow();
699 char buf[128];
700 sprintf_s(buf, "%d chars retrieved for indexing in %gms\n",
701 contents.size(), (end - begin)*1000);
702 OutputDebugStringA(buf);
703#endif
704
705 // When the contents are clipped to the maximum, we don't want to have a
706 // partial word indexed at the end that might have been clipped. Therefore,
707 // terminate the string at the last space to ensure no words are clipped.
708 if (contents->size() == kMaxIndexChars) {
709 size_t last_space_index = contents->find_last_of(kWhitespaceWide);
710 if (last_space_index == std::wstring::npos)
711 return; // don't index if we got a huge block of text with no spaces
712 contents->resize(last_space_index);
713 }
714}
715
[email protected]b6e4bec2008-11-12 01:17:15716bool RenderView::CaptureThumbnail(WebFrame* frame,
initial.commit09911bf2008-07-26 23:55:29717 int w,
718 int h,
719 SkBitmap* thumbnail,
720 ThumbnailScore* score) {
721#ifdef TIME_BITMAP_RETRIEVAL
722 double begin = time_util::GetHighResolutionTimeNow();
723#endif
724
[email protected]21f527e2008-12-17 23:29:40725 scoped_ptr<skia::BitmapPlatformDevice> device;
[email protected]b6e4bec2008-11-12 01:17:15726 if (!frame->CaptureImage(&device, true))
727 return false;
728
729 const SkBitmap& src_bmp = device->accessBitmap(false);
initial.commit09911bf2008-07-26 23:55:29730
731 SkRect dest_rect;
732 dest_rect.set(0, 0, SkIntToScalar(w), SkIntToScalar(h));
733 float dest_aspect = dest_rect.width() / dest_rect.height();
734
735 // Get the src rect so that we can preserve the aspect ratio while filling
736 // the destination.
737 SkIRect src_rect;
738 if (src_bmp.width() < dest_rect.width() ||
739 src_bmp.height() < dest_rect.height()) {
740 // Source image is smaller: we clip the part of source image within the
741 // dest rect, and then stretch it to fill the dest rect. We don't respect
742 // the aspect ratio in this case.
743 src_rect.set(0, 0, static_cast<S16CPU>(dest_rect.width()),
744 static_cast<S16CPU>(dest_rect.height()));
745 score->good_clipping = false;
746 } else {
747 float src_aspect = static_cast<float>(src_bmp.width()) / src_bmp.height();
748 if (src_aspect > dest_aspect) {
749 // Wider than tall, clip horizontally: we center the smaller thumbnail in
750 // the wider screen.
751 S16CPU new_width = static_cast<S16CPU>(src_bmp.height() * dest_aspect);
752 S16CPU x_offset = (src_bmp.width() - new_width) / 2;
753 src_rect.set(x_offset, 0, new_width + x_offset, src_bmp.height());
754 score->good_clipping = false;
755 } else {
756 src_rect.set(0, 0, src_bmp.width(),
757 static_cast<S16CPU>(src_bmp.width() / dest_aspect));
758 score->good_clipping = true;
759 }
760 }
761
762 score->at_top = (frame->ScrollOffset().height() == 0);
763
764 SkBitmap subset;
[email protected]b6e4bec2008-11-12 01:17:15765 device->accessBitmap(false).extractSubset(&subset, src_rect);
initial.commit09911bf2008-07-26 23:55:29766
767 // Resample the subset that we want to get it the right size.
[email protected]465b34b72008-12-12 20:19:14768 *thumbnail = skia::ImageOperations::Resize(
769 subset, skia::ImageOperations::RESIZE_LANCZOS3, w, h);
initial.commit09911bf2008-07-26 23:55:29770
771 score->boring_score = CalculateBoringScore(thumbnail);
772
773#ifdef TIME_BITMAP_RETRIEVAL
774 double end = time_util::GetHighResolutionTimeNow();
775 char buf[128];
776 sprintf_s(buf, "thumbnail in %gms\n", (end - begin) * 1000);
777 OutputDebugStringA(buf);
778#endif
[email protected]b6e4bec2008-11-12 01:17:15779 return true;
initial.commit09911bf2008-07-26 23:55:29780}
781
782double RenderView::CalculateBoringScore(SkBitmap* bitmap) {
783 int histogram[256] = {0};
784 color_utils::BuildLumaHistogram(bitmap, histogram);
785
786 int color_count = *std::max_element(histogram, histogram + 256);
787 int pixel_count = bitmap->width() * bitmap->height();
788 return static_cast<double>(color_count) / pixel_count;
789}
790
791void RenderView::OnNavigate(const ViewMsg_Navigate_Params& params) {
792 if (!webview())
793 return;
794
[email protected]f8b6b6f2009-03-10 16:48:26795 renderer_logging::ScopedActiveRenderingURLSetter url_setter(params.url);
[email protected]f8b6b6f2009-03-10 16:48:26796
initial.commit09911bf2008-07-26 23:55:29797 AboutHandler::MaybeHandle(params.url);
798
799 bool is_reload = params.reload;
800
801 WebFrame* main_frame = webview()->GetMainFrame();
[email protected]606843fa2008-12-02 19:08:56802 if (is_reload && !main_frame->HasCurrentHistoryState()) {
initial.commit09911bf2008-07-26 23:55:29803 // We cannot reload if we do not have any history state. This happens, for
804 // example, when recovering from a crash. Our workaround here is a bit of
805 // a hack since it means that reload after a crashed tab does not cause an
806 // end-to-end cache validation.
807 is_reload = false;
808 }
809
810 WebRequestCachePolicy cache_policy;
811 if (is_reload) {
812 cache_policy = WebRequestReloadIgnoringCacheData;
813 } else if (params.page_id != -1 || main_frame->GetInViewSourceMode()) {
814 cache_policy = WebRequestReturnCacheDataElseLoad;
815 } else {
816 cache_policy = WebRequestUseProtocolCachePolicy;
817 }
818
819 scoped_ptr<WebRequest> request(WebRequest::Create(params.url));
820 request->SetCachePolicy(cache_policy);
821 request->SetExtraData(new RenderViewExtraRequestData(
[email protected]c20210e62009-04-03 21:39:26822 params.page_id, params.transition, params.request_time));
initial.commit09911bf2008-07-26 23:55:29823
824 // If we are reloading, then WebKit will use the state of the current page.
825 // Otherwise, we give it the state to navigate to.
826 if (!is_reload)
827 request->SetHistoryState(params.state);
828
[email protected]4c6f2c92008-10-28 20:26:15829 if (params.referrer.is_valid()) {
[email protected]8e3c1a72008-11-25 01:13:32830 request->SetHttpHeaderValue("Referer",
831 params.referrer.spec());
[email protected]c0588052008-10-27 23:01:50832 }
833
initial.commit09911bf2008-07-26 23:55:29834 main_frame->LoadRequest(request.get());
835}
836
837// Stop loading the current page
838void RenderView::OnStop() {
839 if (webview())
840 webview()->StopLoading();
841}
842
843void RenderView::OnLoadAlternateHTMLText(const std::string& html_contents,
844 bool new_navigation,
845 const GURL& display_url,
846 const std::string& security_info) {
847 if (!webview())
848 return;
849
850 scoped_ptr<WebRequest> request(WebRequest::Create(
851 GURL(kUnreachableWebDataURL)));
852 request->SetSecurityInfo(security_info);
853
854 webview()->GetMainFrame()->LoadAlternateHTMLString(request.get(),
855 html_contents,
856 display_url,
857 !new_navigation);
858}
859
860void RenderView::OnCopyImageAt(int x, int y) {
861 webview()->CopyImageAt(x, y);
862}
863
864void RenderView::OnInspectElement(int x, int y) {
865 webview()->InspectElement(x, y);
866}
867
868void RenderView::OnShowJavaScriptConsole() {
869 webview()->ShowJavaScriptConsole();
870}
871
[email protected]b2abac72009-02-26 12:39:28872void RenderView::OnSetupDevToolsClient() {
[email protected]e4ac5df2009-03-17 15:33:11873 DCHECK(!devtools_client_.get());
874 devtools_client_.reset(new DevToolsClient(this));
[email protected]b2abac72009-02-26 12:39:28875}
876
initial.commit09911bf2008-07-26 23:55:29877void RenderView::OnStopFinding(bool clear_selection) {
878 WebView* view = webview();
879 if (!view)
880 return;
881
882 if (clear_selection)
883 view->GetFocusedFrame()->ClearSelection();
884
885 WebFrame* frame = view->GetMainFrame();
886 while (frame) {
[email protected]65134c432008-09-26 21:47:20887 frame->StopFinding(clear_selection);
initial.commit09911bf2008-07-26 23:55:29888 frame = view->GetNextFrameAfter(frame, false);
889 }
890}
891
892void RenderView::OnFindReplyAck() {
893 // Check if there is any queued up request waiting to be sent.
894 if (queued_find_reply_message_.get()) {
895 // Send the search result over to the browser process.
896 Send(queued_find_reply_message_.get());
897 queued_find_reply_message_.release();
898 }
899}
900
901void RenderView::OnUpdateTargetURLAck() {
902 // Check if there is a targeturl waiting to be sent.
903 if (target_url_status_ == TARGET_PENDING) {
904 Send(new ViewHostMsg_UpdateTargetURL(routing_id_, page_id_,
905 pending_target_url_));
906 }
907
908 target_url_status_ = TARGET_NONE;
909}
910
911void RenderView::OnUndo() {
912 if (!webview())
913 return;
914
915 webview()->GetFocusedFrame()->Undo();
916}
917
918void RenderView::OnRedo() {
919 if (!webview())
920 return;
921
922 webview()->GetFocusedFrame()->Redo();
923}
924
925void RenderView::OnCut() {
926 if (!webview())
927 return;
928
929 webview()->GetFocusedFrame()->Cut();
930}
931
932void RenderView::OnCopy() {
933 if (!webview())
934 return;
935
936 webview()->GetFocusedFrame()->Copy();
937}
938
939void RenderView::OnPaste() {
940 if (!webview())
941 return;
942
943 webview()->GetFocusedFrame()->Paste();
944}
945
946void RenderView::OnReplace(const std::wstring& text) {
947 if (!webview())
948 return;
949
950 webview()->GetFocusedFrame()->Replace(text);
951}
952
[email protected]bbbd545c2008-12-15 20:18:04953void RenderView::OnToggleSpellCheck() {
954 if (!webview())
955 return;
956
957 webview()->GetFocusedFrame()->ToggleSpellCheck();
958}
959
initial.commit09911bf2008-07-26 23:55:29960void RenderView::OnDelete() {
961 if (!webview())
962 return;
963
964 webview()->GetFocusedFrame()->Delete();
965}
966
967void RenderView::OnSelectAll() {
968 if (!webview())
969 return;
970
971 webview()->GetFocusedFrame()->SelectAll();
972}
973
974void RenderView::OnSetInitialFocus(bool reverse) {
975 if (!webview())
976 return;
977 webview()->SetInitialFocus(reverse);
978}
979
980///////////////////////////////////////////////////////////////////////////////
981
982// Tell the embedding application that the URL of the active page has changed
983void RenderView::UpdateURL(WebFrame* frame) {
984 WebDataSource* ds = frame->GetDataSource();
985 DCHECK(ds);
986
987 const WebRequest& request = ds->GetRequest();
988 const WebRequest& initial_request = ds->GetInitialRequest();
989 const WebResponse& response = ds->GetResponse();
990
991 // We don't hold a reference to the extra data. The request's reference will
992 // be sufficient because we won't modify it during our call. MAY BE NULL.
993 RenderViewExtraRequestData* extra_data =
994 static_cast<RenderViewExtraRequestData*>(request.GetExtraData());
995
996 ViewHostMsg_FrameNavigate_Params params;
[email protected]2e39d2e2009-02-19 18:41:31997 params.http_status_code = response.GetHttpStatusCode();
initial.commit09911bf2008-07-26 23:55:29998 params.is_post = false;
999 params.page_id = page_id_;
[email protected]8a3422c92008-09-24 17:42:421000 params.is_content_filtered = response.IsContentFiltered();
initial.commit09911bf2008-07-26 23:55:291001 if (!request.GetSecurityInfo().empty()) {
1002 // SSL state specified in the request takes precedence over the one in the
1003 // response.
1004 // So far this is only intended for error pages that are not expected to be
1005 // over ssl, so we should not get any clash.
1006 DCHECK(response.GetSecurityInfo().empty());
1007 params.security_info = request.GetSecurityInfo();
1008 } else {
1009 params.security_info = response.GetSecurityInfo();
1010 }
1011
1012 // Set the URL to be displayed in the browser UI to the user.
1013 if (ds->HasUnreachableURL()) {
1014 params.url = ds->GetUnreachableURL();
1015 } else {
1016 params.url = request.GetURL();
1017 }
1018
1019 params.redirects = ds->GetRedirectChain();
1020 params.should_update_history = !ds->HasUnreachableURL();
1021
1022 const SearchableFormData* searchable_form_data =
1023 frame->GetDataSource()->GetSearchableFormData();
1024 if (searchable_form_data) {
1025 params.searchable_form_url = searchable_form_data->url();
1026 params.searchable_form_element_name = searchable_form_data->element_name();
1027 params.searchable_form_encoding = searchable_form_data->encoding();
1028 }
1029
1030 const PasswordForm* password_form_data =
1031 frame->GetDataSource()->GetPasswordFormData();
1032 if (password_form_data)
1033 params.password_form = *password_form_data;
1034
1035 params.gesture = navigation_gesture_;
1036 navigation_gesture_ = NavigationGestureUnknown;
1037
1038 if (webview()->GetMainFrame() == frame) {
1039 // Top-level navigation.
1040
1041 // Update contents MIME type for main frame.
[email protected]9d806f52009-03-12 22:50:541042 params.contents_mime_type = ds->GetResponse().GetMimeType();
initial.commit09911bf2008-07-26 23:55:291043
1044 // We assume top level navigations initiated by the renderer are link
1045 // clicks.
1046 params.transition = extra_data ?
1047 extra_data->transition_type : PageTransition::LINK;
1048 if (!PageTransition::IsMainFrame(params.transition)) {
1049 // If the main frame does a load, it should not be reported as a subframe
1050 // navigation. This can occur in the following case:
1051 // 1. You're on a site with frames.
1052 // 2. You do a subframe navigation. This is stored with transition type
1053 // MANUAL_SUBFRAME.
1054 // 3. You navigate to some non-frame site, say, google.com.
1055 // 4. You navigate back to the page from step 2. Since it was initially
1056 // MANUAL_SUBFRAME, it will be that same transition type here.
1057 // We don't want that, because any navigation that changes the toplevel
1058 // frame should be tracked as a toplevel navigation (this allows us to
1059 // update the URL bar, etc).
1060 params.transition = PageTransition::LINK;
1061 }
1062
1063 if (params.transition == PageTransition::LINK &&
1064 frame->GetDataSource()->IsFormSubmit()) {
1065 params.transition = PageTransition::FORM_SUBMIT;
1066 }
1067
1068 // If we have a valid consumed client redirect source,
1069 // the page contained a client redirect (meta refresh, document.loc...),
1070 // so we set the referrer and transition to match.
1071 if (completed_client_redirect_src_.is_valid()) {
[email protected]77e09a92008-08-01 18:11:041072 DCHECK(completed_client_redirect_src_ == params.redirects[0]);
initial.commit09911bf2008-07-26 23:55:291073 params.referrer = completed_client_redirect_src_;
1074 params.transition = static_cast<PageTransition::Type>(
1075 params.transition | PageTransition::CLIENT_REDIRECT);
1076 } else {
1077 // Bug 654101: the referrer will be empty on https->http transitions. It
1078 // would be nice if we could get the real referrer from somewhere.
1079 params.referrer = GURL(initial_request.GetHttpReferrer());
1080 }
1081
[email protected]8e3c1a72008-11-25 01:13:321082 std::string method = request.GetHttpMethod();
1083 if (method == "POST")
initial.commit09911bf2008-07-26 23:55:291084 params.is_post = true;
1085
1086 Send(new ViewHostMsg_FrameNavigate(routing_id_, params));
1087 } else {
1088 // Subframe navigation: the type depends on whether this navigation
1089 // generated a new session history entry. When they do generate a session
1090 // history entry, it means the user initiated the navigation and we should
1091 // mark it as such. This test checks if this is the first time UpdateURL
1092 // has been called since WillNavigateToURL was called to initiate the load.
1093 if (page_id_ > last_page_id_sent_to_browser_)
1094 params.transition = PageTransition::MANUAL_SUBFRAME;
1095 else
1096 params.transition = PageTransition::AUTO_SUBFRAME;
1097
1098 // The browser should never initiate a subframe navigation.
1099 DCHECK(!extra_data);
1100 Send(new ViewHostMsg_FrameNavigate(routing_id_, params));
1101 }
1102
1103 last_page_id_sent_to_browser_ =
1104 std::max(last_page_id_sent_to_browser_, page_id_);
1105
1106 // If we end up reusing this WebRequest (for example, due to a #ref click),
1107 // we don't want the transition type to persist.
1108 if (extra_data)
1109 extra_data->transition_type = PageTransition::LINK; // Just clear it.
[email protected]266eb6f2008-09-30 23:56:501110
[email protected]6c8afae52009-01-22 02:24:571111#if defined(OS_WIN)
[email protected]6a983b42009-03-20 20:12:251112 if (web_accessibility_manager_.get()) {
[email protected]be645db2009-02-06 20:36:331113 // Clear accessibility info cache.
[email protected]6a983b42009-03-20 20:12:251114 web_accessibility_manager_->ClearAccObjMap(-1, true);
[email protected]266eb6f2008-09-30 23:56:501115 }
[email protected]6c8afae52009-01-22 02:24:571116#else
[email protected]7d926f92009-03-03 14:26:541117 // TODO(port): accessibility not yet implemented. See http://crbug.com/8288.
[email protected]6c8afae52009-01-22 02:24:571118#endif
initial.commit09911bf2008-07-26 23:55:291119}
1120
1121// Tell the embedding application that the title of the active page has changed
1122void RenderView::UpdateTitle(WebFrame* frame, const std::wstring& title) {
1123 // Ignore all but top level navigations...
1124 if (webview()->GetMainFrame() == frame)
1125 Send(new ViewHostMsg_UpdateTitle(routing_id_, page_id_, title));
1126}
1127
1128void RenderView::UpdateEncoding(WebFrame* frame,
[email protected]e38f40152008-09-12 23:08:301129 const std::wstring& encoding_name) {
initial.commit09911bf2008-07-26 23:55:291130 // Only update main frame's encoding_name.
1131 if (webview()->GetMainFrame() == frame &&
1132 last_encoding_name_ != encoding_name) {
[email protected]e38f40152008-09-12 23:08:301133 // Save the encoding name for later comparing.
initial.commit09911bf2008-07-26 23:55:291134 last_encoding_name_ = encoding_name;
1135
[email protected]e38f40152008-09-12 23:08:301136 Send(new ViewHostMsg_UpdateEncoding(routing_id_, last_encoding_name_));
initial.commit09911bf2008-07-26 23:55:291137 }
1138}
1139
[email protected]f4d34b52008-11-24 23:05:011140// Sends the previous session history state to the browser so it will be saved
1141// before we navigate to a new page. This must be called *before* the page ID
1142// has been updated so we know what it was.
initial.commit09911bf2008-07-26 23:55:291143void RenderView::UpdateSessionHistory(WebFrame* frame) {
1144 // If we have a valid page ID at this point, then it corresponds to the page
1145 // we are navigating away from. Otherwise, this is the first navigation, so
1146 // there is no past session history to record.
1147 if (page_id_ == -1)
1148 return;
1149
initial.commit09911bf2008-07-26 23:55:291150 std::string state;
[email protected]606843fa2008-12-02 19:08:561151 if (!webview()->GetMainFrame()->GetPreviousHistoryState(&state))
initial.commit09911bf2008-07-26 23:55:291152 return;
[email protected]606843fa2008-12-02 19:08:561153 Send(new ViewHostMsg_UpdateState(routing_id_, page_id_, state));
initial.commit09911bf2008-07-26 23:55:291154}
1155
1156///////////////////////////////////////////////////////////////////////////////
1157// WebViewDelegate
1158
1159void RenderView::DidStartLoading(WebView* webview) {
1160 if (is_loading_) {
1161 DLOG(WARNING) << "DidStartLoading called while loading";
1162 return;
1163 }
1164
1165 is_loading_ = true;
1166 // Clear the pointer so that we can assign it only when there is an unknown
1167 // plugin on a page.
1168 first_default_plugin_ = NULL;
1169
1170 Send(new ViewHostMsg_DidStartLoading(routing_id_, page_id_));
1171}
1172
1173void RenderView::DidStopLoading(WebView* webview) {
1174 if (!is_loading_) {
1175 DLOG(WARNING) << "DidStopLoading called while not loading";
1176 return;
1177 }
1178
1179 is_loading_ = false;
1180
1181 // NOTE: For now we're doing the safest thing, and sending out notification
1182 // when done loading. This currently isn't an issue as the favicon is only
1183 // displayed when done loading. Ideally we would send notification when
1184 // finished parsing the head, but webkit doesn't support that yet.
1185 // The feed discovery code would also benefit from access to the head.
1186 GURL favicon_url(webview->GetMainFrame()->GetFavIconURL());
1187 if (!favicon_url.is_empty())
1188 Send(new ViewHostMsg_UpdateFavIconURL(routing_id_, page_id_, favicon_url));
1189
initial.commit09911bf2008-07-26 23:55:291190 AddGURLSearchProvider(webview->GetMainFrame()->GetOSDDURL(),
1191 true); // autodetected
1192
1193 Send(new ViewHostMsg_DidStopLoading(routing_id_, page_id_));
1194
1195 MessageLoop::current()->PostDelayedTask(FROM_HERE,
1196 method_factory_.NewRunnableMethod(&RenderView::CapturePageInfo, page_id_,
1197 false),
1198 kDelayForCaptureMs);
1199
1200 // The page is loaded. Try to process the file we need to upload if any.
1201 ProcessPendingUpload();
1202
1203 // Since the page is done loading, we are sure we don't need to try
1204 // again.
1205 ResetPendingUpload();
1206}
1207
1208void RenderView::DidStartProvisionalLoadForFrame(
1209 WebView* webview,
1210 WebFrame* frame,
1211 NavigationGesture gesture) {
[email protected]77e09a92008-08-01 18:11:041212 if (webview->GetMainFrame() == frame) {
initial.commit09911bf2008-07-26 23:55:291213 navigation_gesture_ = gesture;
[email protected]266eb6f2008-09-30 23:56:501214
[email protected]77e09a92008-08-01 18:11:041215 // Make sure redirect tracking state is clear for the new load.
1216 completed_client_redirect_src_ = GURL();
1217 }
initial.commit09911bf2008-07-26 23:55:291218
[email protected]c20210e62009-04-03 21:39:261219 WebDataSource* ds = frame->GetProvisionalDataSource();
1220 if (ds) {
1221 const WebRequest& req = ds->GetRequest();
1222 RenderViewExtraRequestData* extra_data =
1223 static_cast<RenderViewExtraRequestData*>(req.GetExtraData());
1224 if (extra_data) {
1225 ds->SetRequestTime(extra_data->request_time);
1226 }
1227 }
initial.commit09911bf2008-07-26 23:55:291228 Send(new ViewHostMsg_DidStartProvisionalLoadForFrame(
1229 routing_id_, webview->GetMainFrame() == frame,
1230 frame->GetProvisionalDataSource()->GetRequest().GetURL()));
1231}
1232
1233bool RenderView::DidLoadResourceFromMemoryCache(WebView* webview,
1234 const WebRequest& request,
1235 const WebResponse& response,
1236 WebFrame* frame) {
1237 // Let the browser know we loaded a resource from the memory cache. This
1238 // message is needed to display the correct SSL indicators.
1239 Send(new ViewHostMsg_DidLoadResourceFromMemoryCache(routing_id_,
[email protected]ffc45862009-03-17 06:11:081240 request.GetURL(), frame->GetSecurityOrigin(),
1241 frame->GetTop()->GetSecurityOrigin(),
1242 response.GetSecurityInfo()));
initial.commit09911bf2008-07-26 23:55:291243
1244 return false;
1245}
1246
1247void RenderView::DidReceiveProvisionalLoadServerRedirect(WebView* webview,
1248 WebFrame* frame) {
1249 if (frame == webview->GetMainFrame()) {
1250 // Received a redirect on the main frame.
1251 WebDataSource* data_source =
1252 webview->GetMainFrame()->GetProvisionalDataSource();
1253 if (!data_source) {
1254 // Should only be invoked when we have a data source.
1255 NOTREACHED();
1256 return;
1257 }
1258 const std::vector<GURL>& redirects = data_source->GetRedirectChain();
1259 if (redirects.size() >= 2) {
1260 Send(new ViewHostMsg_DidRedirectProvisionalLoad(
1261 routing_id_, page_id_, redirects[redirects.size() - 2],
1262 redirects[redirects.size() - 1]));
1263 }
1264 }
1265}
1266
1267void RenderView::DidFailProvisionalLoadWithError(WebView* webview,
1268 const WebError& error,
1269 WebFrame* frame) {
1270 // Notify the browser that we failed a provisional load with an error.
1271 //
1272 // Note: It is important this notification occur before DidStopLoading so the
1273 // SSL manager can react to the provisional load failure before being
1274 // notified the load stopped.
1275 //
1276 WebDataSource* ds = frame->GetProvisionalDataSource();
1277 DCHECK(ds);
1278
1279 const WebRequest& failed_request = ds->GetRequest();
1280
1281 bool show_repost_interstitial =
1282 (error.GetErrorCode() == net::ERR_CACHE_MISS &&
1283 LowerCaseEqualsASCII(failed_request.GetHttpMethod(), "post"));
1284 Send(new ViewHostMsg_DidFailProvisionalLoadWithError(
1285 routing_id_, frame == webview->GetMainFrame(),
1286 error.GetErrorCode(), error.GetFailedURL(),
1287 show_repost_interstitial));
1288
initial.commit09911bf2008-07-26 23:55:291289 // Don't display an error page if this is simply a cancelled load. Aside
1290 // from being dumb, WebCore doesn't expect it and it will cause a crash.
1291 if (error.GetErrorCode() == net::ERR_ABORTED)
1292 return;
1293
1294 // If this is a failed back/forward/reload navigation, then we need to do a
1295 // 'replace' load. This is necessary to avoid messing up session history.
1296 // Otherwise, we do a normal load, which simulates a 'go' navigation as far
1297 // as session history is concerned.
1298 RenderViewExtraRequestData* extra_data =
1299 static_cast<RenderViewExtraRequestData*>(failed_request.GetExtraData());
1300 bool replace = extra_data && !extra_data->is_new_navigation();
1301
[email protected]5df266ac2008-10-15 19:50:131302 // Use the alternate error page service if this is a DNS failure or
1303 // connection failure. ERR_CONNECTION_FAILED can be dropped once we no longer
1304 // use winhttp.
1305 int ec = error.GetErrorCode();
1306 if (ec == net::ERR_NAME_NOT_RESOLVED ||
1307 ec == net::ERR_CONNECTION_FAILED ||
1308 ec == net::ERR_CONNECTION_REFUSED ||
1309 ec == net::ERR_ADDRESS_UNREACHABLE ||
1310 ec == net::ERR_TIMED_OUT) {
1311 const GURL& failed_url = error.GetFailedURL();
1312 const GURL& error_page_url = GetAlternateErrorPageURL(failed_url,
1313 ec == net::ERR_NAME_NOT_RESOLVED ? WebViewDelegate::DNS_ERROR
1314 : WebViewDelegate::CONNECTION_ERROR);
1315 if (error_page_url.is_valid()) {
1316 // Ask the WebFrame to fetch the alternate error page for us.
1317 frame->LoadAlternateHTMLErrorPage(&failed_request, error, error_page_url,
1318 replace, GURL(kUnreachableWebDataURL));
1319 return;
1320 }
initial.commit09911bf2008-07-26 23:55:291321 }
[email protected]5df266ac2008-10-15 19:50:131322
[email protected]be645db2009-02-06 20:36:331323 // Fallback to a local error page.
[email protected]5df266ac2008-10-15 19:50:131324 LoadNavigationErrorPage(frame, &failed_request, error, std::string(),
1325 replace);
initial.commit09911bf2008-07-26 23:55:291326}
1327
1328void RenderView::LoadNavigationErrorPage(WebFrame* frame,
1329 const WebRequest* failed_request,
1330 const WebError& error,
1331 const std::string& html,
1332 bool replace) {
1333 const GURL& failed_url = error.GetFailedURL();
1334
1335 std::string alt_html;
1336 if (html.empty()) {
1337 // Use a local error page.
1338 int resource_id;
1339 DictionaryValue error_strings;
1340 if (error.GetErrorCode() == net::ERR_CACHE_MISS &&
1341 LowerCaseEqualsASCII(failed_request->GetHttpMethod(), "post")) {
1342 GetFormRepostErrorValues(failed_url, &error_strings);
1343 resource_id = IDR_ERROR_NO_DETAILS_HTML;
1344 } else {
1345 GetLocalizedErrorValues(error, &error_strings);
1346 resource_id = IDR_NET_ERROR_HTML;
1347 }
[email protected]8e50b602009-03-03 22:59:431348 error_strings.SetString(L"textdirection",
1349 (l10n_util::GetTextDirection() == l10n_util::RIGHT_TO_LEFT) ?
1350 L"rtl" : L"ltr");
initial.commit09911bf2008-07-26 23:55:291351
1352 alt_html = GetAltHTMLForTemplate(error_strings, resource_id);
1353 } else {
1354 alt_html = html;
1355 }
1356
1357 // Use a data: URL as the site URL to prevent against XSS attacks.
1358 scoped_ptr<WebRequest> request(failed_request->Clone());
1359 request->SetURL(GURL(kUnreachableWebDataURL));
1360
1361 frame->LoadAlternateHTMLString(request.get(), alt_html, failed_url,
1362 replace);
1363}
1364
1365void RenderView::DidCommitLoadForFrame(WebView *webview, WebFrame* frame,
1366 bool is_new_navigation) {
1367 const WebRequest& request =
1368 webview->GetMainFrame()->GetDataSource()->GetRequest();
1369 RenderViewExtraRequestData* extra_data =
1370 static_cast<RenderViewExtraRequestData*>(request.GetExtraData());
1371
1372 if (is_new_navigation) {
1373 // When we perform a new navigation, we need to update the previous session
1374 // history entry with state for the page we are leaving.
1375 UpdateSessionHistory(frame);
1376
1377 // We bump our Page ID to correspond with the new session history entry.
1378 page_id_ = next_page_id_++;
1379
1380 MessageLoop::current()->PostDelayedTask(FROM_HERE,
1381 method_factory_.NewRunnableMethod(&RenderView::CapturePageInfo,
1382 page_id_, true),
1383 kDelayForForcedCaptureMs);
1384 } else {
1385 // Inspect the extra_data on the main frame (set in our Navigate method) to
1386 // see if the navigation corresponds to a session history navigation...
1387 // Note: |frame| may or may not be the toplevel frame, but for the case
1388 // of capturing session history, the first committed frame suffices. We
1389 // keep track of whether we've seen this commit before so that only capture
1390 // session history once per navigation.
[email protected]f4d34b52008-11-24 23:05:011391 //
1392 // Note that we need to check if the page ID changed. In the case of a
1393 // reload, the page ID doesn't change, and UpdateSessionHistory gets the
1394 // previous URL and the current page ID, which would be wrong.
initial.commit09911bf2008-07-26 23:55:291395 if (extra_data && !extra_data->is_new_navigation() &&
[email protected]f4d34b52008-11-24 23:05:011396 !extra_data->request_committed &&
1397 page_id_ != extra_data->pending_page_id()) {
initial.commit09911bf2008-07-26 23:55:291398 // This is a successful session history navigation!
1399 UpdateSessionHistory(frame);
initial.commit09911bf2008-07-26 23:55:291400 page_id_ = extra_data->pending_page_id();
1401 }
1402 }
1403
1404 // Remember that we've already processed this request, so we don't update
1405 // the session history again. We do this regardless of whether this is
1406 // a session history navigation, because if we attempted a session history
1407 // navigation without valid HistoryItem state, WebCore will think it is a
1408 // new navigation.
1409 if (extra_data)
1410 extra_data->request_committed = true;
1411
1412 UpdateURL(frame);
1413
1414 // If this committed load was initiated by a client redirect, we're
1415 // at the last stop now, so clear it.
1416 completed_client_redirect_src_ = GURL();
1417
1418 // Check whether we have new encoding name.
1419 UpdateEncoding(frame, webview->GetMainFrameEncodingName());
1420}
1421
1422void RenderView::DidReceiveTitle(WebView* webview,
1423 const std::wstring& title,
1424 WebFrame* frame) {
1425 UpdateTitle(frame, title);
1426
1427 // Also check whether we have new encoding name.
1428 UpdateEncoding(frame, webview->GetMainFrameEncodingName());
1429}
1430
1431void RenderView::DidFinishLoadForFrame(WebView* webview, WebFrame* frame) {
[email protected]c20210e62009-04-03 21:39:261432 if (webview->GetMainFrame() == frame) {
1433 const GURL& url = frame->GetURL();
1434 if (url.SchemeIs("http") || url.SchemeIs("https"))
1435 DumpLoadHistograms();
1436 }
initial.commit09911bf2008-07-26 23:55:291437}
1438
1439void RenderView::DidFailLoadWithError(WebView* webview,
1440 const WebError& error,
1441 WebFrame* frame) {
1442}
1443
1444void RenderView::DidFinishDocumentLoadForFrame(WebView* webview,
1445 WebFrame* frame) {
1446 // Check whether we have new encoding name.
1447 UpdateEncoding(frame, webview->GetMainFrameEncodingName());
[email protected]1e0f70402008-10-16 23:57:471448
[email protected]8930d472009-02-21 08:05:281449 if (RenderThread::current()) // Will be NULL during unit tests.
1450 RenderThread::current()->user_script_slave()->InjectScripts(
[email protected]0afe8272009-02-14 04:15:161451 frame, UserScript::DOCUMENT_END);
initial.commit09911bf2008-07-26 23:55:291452}
1453
1454void RenderView::DidHandleOnloadEventsForFrame(WebView* webview,
1455 WebFrame* frame) {
1456}
1457
1458void RenderView::DidChangeLocationWithinPageForFrame(WebView* webview,
1459 WebFrame* frame,
1460 bool is_new_navigation) {
1461 DidCommitLoadForFrame(webview, frame, is_new_navigation);
[email protected]9d806f52009-03-12 22:50:541462 const string16& title =
[email protected]de56f3782008-10-01 22:31:351463 webview->GetMainFrame()->GetDataSource()->GetPageTitle();
[email protected]9d806f52009-03-12 22:50:541464 UpdateTitle(frame, UTF16ToWideHack(title));
initial.commit09911bf2008-07-26 23:55:291465}
1466
1467void RenderView::DidReceiveIconForFrame(WebView* webview,
1468 WebFrame* frame) {
1469}
1470
1471void RenderView::WillPerformClientRedirect(WebView* webview,
1472 WebFrame* frame,
1473 const GURL& src_url,
1474 const GURL& dest_url,
1475 unsigned int delay_seconds,
1476 unsigned int fire_date) {
1477}
1478
1479void RenderView::DidCancelClientRedirect(WebView* webview,
1480 WebFrame* frame) {
1481}
1482
[email protected]309d7a282009-03-24 09:18:271483void RenderView::WillCloseFrame(WebView* view, WebFrame* frame) {
1484 // Remove all the pending extension callbacks for this frame.
1485 if (pending_extension_callbacks_.IsEmpty())
1486 return;
1487
1488 std::vector<int> orphaned_callbacks;
1489 for (IDMap<WebFrame>::const_iterator iter =
1490 pending_extension_callbacks_.begin();
1491 iter != pending_extension_callbacks_.end(); ++iter) {
1492 if (iter->second == frame)
1493 orphaned_callbacks.push_back(iter->first);
1494 }
1495
1496 for (std::vector<int>::const_iterator iter = orphaned_callbacks.begin();
1497 iter != orphaned_callbacks.end(); ++iter) {
1498 pending_extension_callbacks_.Remove(*iter);
1499 }
1500}
1501
initial.commit09911bf2008-07-26 23:55:291502void RenderView::DidCompleteClientRedirect(WebView* webview,
1503 WebFrame* frame,
1504 const GURL& source) {
1505 if (webview->GetMainFrame() == frame)
1506 completed_client_redirect_src_ = source;
1507}
1508
[email protected]5b35a6b2009-03-16 19:58:081509void RenderView::WillSendRequest(WebView* webview,
1510 uint32 identifier,
1511 WebRequest* request) {
1512 request->SetRequestorID(routing_id_);
1513}
1514
initial.commit09911bf2008-07-26 23:55:291515void RenderView::BindDOMAutomationController(WebFrame* webframe) {
1516 dom_automation_controller_.set_message_sender(this);
1517 dom_automation_controller_.set_routing_id(routing_id_);
1518 dom_automation_controller_.BindToJavascript(webframe,
1519 L"domAutomationController");
1520}
1521
1522void RenderView::WindowObjectCleared(WebFrame* webframe) {
1523 external_js_object_.set_render_view(this);
1524 external_js_object_.BindToJavascript(webframe, L"external");
[email protected]81e63782009-02-27 19:35:091525 if (BindingsPolicy::is_dom_automation_enabled(enabled_bindings_))
initial.commit09911bf2008-07-26 23:55:291526 BindDOMAutomationController(webframe);
[email protected]81e63782009-02-27 19:35:091527 if (BindingsPolicy::is_dom_ui_enabled(enabled_bindings_)) {
initial.commit09911bf2008-07-26 23:55:291528 dom_ui_bindings_.set_message_sender(this);
1529 dom_ui_bindings_.set_routing_id(routing_id_);
1530 dom_ui_bindings_.BindToJavascript(webframe, L"chrome");
1531 }
[email protected]81e63782009-02-27 19:35:091532 if (BindingsPolicy::is_external_host_enabled(enabled_bindings_)) {
[email protected]18cb2572008-08-21 20:34:451533 external_host_bindings_.set_message_sender(this);
1534 external_host_bindings_.set_routing_id(routing_id_);
1535 external_host_bindings_.BindToJavascript(webframe, L"externalHost");
1536 }
[email protected]9a2051d2008-08-15 20:12:421537
[email protected]3a453fa2008-08-15 18:46:341538#ifdef CHROME_PERSONALIZATION
1539 Personalization::ConfigureRendererPersonalization(personalization_, this,
1540 routing_id_, webframe);
1541#endif
initial.commit09911bf2008-07-26 23:55:291542}
1543
[email protected]0afe8272009-02-14 04:15:161544void RenderView::DocumentElementAvailable(WebFrame* frame) {
[email protected]8930d472009-02-21 08:05:281545 if (RenderThread::current()) // Will be NULL during unit tests.
1546 RenderThread::current()->user_script_slave()->InjectScripts(
[email protected]0afe8272009-02-14 04:15:161547 frame, UserScript::DOCUMENT_START);
1548}
1549
initial.commit09911bf2008-07-26 23:55:291550WindowOpenDisposition RenderView::DispositionForNavigationAction(
1551 WebView* webview,
1552 WebFrame* frame,
1553 const WebRequest* request,
1554 WebNavigationType type,
1555 WindowOpenDisposition disposition,
1556 bool is_redirect) {
1557 // Webkit is asking whether to navigate to a new URL.
1558 // This is fine normally, except if we're showing UI from one security
1559 // context and they're trying to navigate to a different context.
1560 const GURL& url = request->GetURL();
1561 // We only care about navigations that are within the current tab (as opposed
1562 // to, for example, opening a new window).
1563 // But we sometimes navigate to about:blank to clear a tab, and we want to
1564 // still allow that.
[email protected]6de74452009-02-25 18:04:591565 if (disposition == CURRENT_TAB && !(url.SchemeIs(chrome::kAboutScheme))) {
initial.commit09911bf2008-07-26 23:55:291566 // GetExtraData is NULL when we did not issue the request ourselves (see
1567 // OnNavigate), and so such a request may correspond to a link-click,
1568 // script, or drag-n-drop initiated navigation.
1569 if (frame == webview->GetMainFrame() && !request->GetExtraData()) {
1570 // When we received such unsolicited navigations, we sometimes want to
1571 // punt them up to the browser to handle.
[email protected]81e63782009-02-27 19:35:091572 if (BindingsPolicy::is_dom_ui_enabled(enabled_bindings_) ||
initial.commit09911bf2008-07-26 23:55:291573 frame->GetInViewSourceMode() ||
[email protected]6de74452009-02-25 18:04:591574 url.SchemeIs(chrome::kViewSourceScheme)) {
[email protected]c0588052008-10-27 23:01:501575 OpenURL(webview, url, GURL(), disposition);
initial.commit09911bf2008-07-26 23:55:291576 return IGNORE_ACTION; // Suppress the load here.
[email protected]50b691c2008-10-31 19:08:351577 } else if (url.SchemeIs(kBackForwardNavigationScheme)) {
1578 std::string offset_str = url.ExtractFileName();
1579 int offset;
1580 if (StringToInt(offset_str, &offset)) {
[email protected]0c0383772008-11-04 00:48:311581 GoToEntryAtOffset(offset);
[email protected]50b691c2008-10-31 19:08:351582 return IGNORE_ACTION; // The browser process handles this one.
1583 }
initial.commit09911bf2008-07-26 23:55:291584 }
1585 }
1586 }
1587
1588 // Detect when a page is "forking" a new tab that can be safely rendered in
1589 // its own process. This is done by sites like Gmail that try to open links
1590 // in new windows without script connections back to the original page. We
1591 // treat such cases as browser navigations (in which we will create a new
1592 // renderer for a cross-site navigation), rather than WebKit navigations.
1593 //
1594 // We use the following heuristic to decide whether to fork a new page in its
1595 // own process:
1596 // The parent page must open a new tab to about:blank, set the new tab's
1597 // window.opener to null, and then redirect the tab to a cross-site URL using
1598 // JavaScript.
1599 bool is_fork =
1600 // Must start from a tab showing about:blank, which is later redirected.
[email protected]6aad4bd2009-02-26 22:55:171601 frame->GetURL() == GURL("about:blank") &&
initial.commit09911bf2008-07-26 23:55:291602 // Must be the first real navigation of the tab.
1603 GetHistoryBackListCount() < 1 &&
1604 GetHistoryForwardListCount() < 1 &&
1605 // The parent page must have set the child's window.opener to null before
1606 // redirecting to the desired URL.
1607 frame->GetOpener() == NULL &&
1608 // Must be a top-level frame.
1609 frame->GetParent() == NULL &&
1610 // Must not have issued the request from this page. GetExtraData is NULL
1611 // when the navigation is being done by something outside the page.
1612 !request->GetExtraData() &&
1613 // Must be targeted at the current tab.
1614 disposition == CURRENT_TAB &&
1615 // Must be a JavaScript navigation, which appears as "other".
1616 type == WebNavigationTypeOther;
1617 if (is_fork) {
1618 // Open the URL via the browser, not via WebKit.
[email protected]c0588052008-10-27 23:01:501619 OpenURL(webview, url, GURL(), disposition);
initial.commit09911bf2008-07-26 23:55:291620 return IGNORE_ACTION;
1621 }
1622
1623 return disposition;
1624}
1625
[email protected]a455d3812009-03-05 20:18:071626void RenderView::RunJavaScriptAlert(WebFrame* webframe,
initial.commit09911bf2008-07-26 23:55:291627 const std::wstring& message) {
[email protected]2e4bdcdc2009-03-27 23:07:301628 RunJavaScriptMessage(MessageBox::kIsJavascriptAlert,
initial.commit09911bf2008-07-26 23:55:291629 message,
1630 std::wstring(),
[email protected]a455d3812009-03-05 20:18:071631 webframe->GetURL(),
initial.commit09911bf2008-07-26 23:55:291632 NULL);
1633}
1634
[email protected]a455d3812009-03-05 20:18:071635bool RenderView::RunJavaScriptConfirm(WebFrame* webframe,
initial.commit09911bf2008-07-26 23:55:291636 const std::wstring& message) {
[email protected]2e4bdcdc2009-03-27 23:07:301637 return RunJavaScriptMessage(MessageBox::kIsJavascriptConfirm,
initial.commit09911bf2008-07-26 23:55:291638 message,
1639 std::wstring(),
[email protected]a455d3812009-03-05 20:18:071640 webframe->GetURL(),
initial.commit09911bf2008-07-26 23:55:291641 NULL);
1642}
1643
[email protected]a455d3812009-03-05 20:18:071644bool RenderView::RunJavaScriptPrompt(WebFrame* webframe,
initial.commit09911bf2008-07-26 23:55:291645 const std::wstring& message,
1646 const std::wstring& default_value,
1647 std::wstring* result) {
[email protected]2e4bdcdc2009-03-27 23:07:301648 return RunJavaScriptMessage(MessageBox::kIsJavascriptPrompt,
initial.commit09911bf2008-07-26 23:55:291649 message,
1650 default_value,
[email protected]a455d3812009-03-05 20:18:071651 webframe->GetURL(),
initial.commit09911bf2008-07-26 23:55:291652 result);
1653}
1654
1655bool RenderView::RunJavaScriptMessage(int type,
1656 const std::wstring& message,
1657 const std::wstring& default_value,
[email protected]a455d3812009-03-05 20:18:071658 const GURL& frame_url,
initial.commit09911bf2008-07-26 23:55:291659 std::wstring* result) {
1660 bool success = false;
1661 std::wstring result_temp;
1662 if (!result)
1663 result = &result_temp;
1664 IPC::SyncMessage* msg = new ViewHostMsg_RunJavaScriptMessage(
[email protected]a455d3812009-03-05 20:18:071665 routing_id_, message, default_value, frame_url, type, &success, result);
initial.commit09911bf2008-07-26 23:55:291666
[email protected]1c4947f2009-01-15 22:25:111667 msg->set_pump_messages_event(modal_dialog_event_.get());
initial.commit09911bf2008-07-26 23:55:291668 Send(msg);
1669
1670 return success;
1671}
1672
1673void RenderView::AddGURLSearchProvider(const GURL& osd_url, bool autodetected) {
1674 if (!osd_url.is_empty())
1675 Send(new ViewHostMsg_PageHasOSDD(routing_id_, page_id_, osd_url,
1676 autodetected));
1677}
1678
[email protected]4604d1f42009-03-13 21:52:321679void RenderView::UpdateFeedList(scoped_refptr<FeedList> feedlist) {
1680 ViewHostMsg_UpdateFeedList_Params params;
1681 params.page_id = page_id_;
1682 params.feedlist = feedlist;
1683 Send(new ViewHostMsg_UpdateFeedList(routing_id_, params));
1684}
1685
[email protected]a455d3812009-03-05 20:18:071686bool RenderView::RunBeforeUnloadConfirm(WebFrame* webframe,
initial.commit09911bf2008-07-26 23:55:291687 const std::wstring& message) {
1688 bool success = false;
1689 // This is an ignored return value, but is included so we can accept the same
1690 // response as RunJavaScriptMessage.
1691 std::wstring ignored_result;
1692 IPC::SyncMessage* msg = new ViewHostMsg_RunBeforeUnloadConfirm(
[email protected]a455d3812009-03-05 20:18:071693 routing_id_, webframe->GetURL(), message, &success, &ignored_result);
initial.commit09911bf2008-07-26 23:55:291694
[email protected]1c4947f2009-01-15 22:25:111695 msg->set_pump_messages_event(modal_dialog_event_.get());
initial.commit09911bf2008-07-26 23:55:291696 Send(msg);
1697
1698 return success;
1699}
1700
[email protected]0578a502008-11-10 19:34:431701void RenderView::EnableSuddenTermination() {
1702 Send(new ViewHostMsg_UnloadListenerChanged(routing_id_, false));
1703}
1704
1705void RenderView::DisableSuddenTermination() {
1706 Send(new ViewHostMsg_UnloadListenerChanged(routing_id_, true));
initial.commit09911bf2008-07-26 23:55:291707}
1708
[email protected]0ebf3872008-11-07 21:35:031709void RenderView::QueryFormFieldAutofill(const std::wstring& field_name,
1710 const std::wstring& text,
1711 int64 node_id) {
1712 static int message_id_counter = 0;
1713 form_field_autofill_request_id_ = message_id_counter++;
1714 Send(new ViewHostMsg_QueryFormFieldAutofill(routing_id_,
1715 field_name, text,
1716 node_id,
1717 form_field_autofill_request_id_));
1718}
1719
[email protected]4d2b6fb2009-03-20 22:28:171720void RenderView::RemoveStoredAutofillEntry(const std::wstring& name,
1721 const std::wstring& value) {
1722 Send(new ViewHostMsg_RemoveAutofillEntry(routing_id_, name, value));
1723}
1724
[email protected]0ebf3872008-11-07 21:35:031725void RenderView::OnReceivedAutofillSuggestions(
1726 int64 node_id,
1727 int request_id,
[email protected]8d0f15c2008-11-11 01:01:091728 const std::vector<std::wstring>& suggestions,
[email protected]0ebf3872008-11-07 21:35:031729 int default_suggestion_index) {
1730 if (!webview() || request_id != form_field_autofill_request_id_)
1731 return;
1732
1733 webview()->AutofillSuggestionsForNode(node_id, suggestions,
1734 default_suggestion_index);
1735}
1736
[email protected]634a6f92008-12-01 21:39:311737void RenderView::OnPopupNotificationVisiblityChanged(bool visible) {
1738 popup_notification_visible_ = visible;
1739}
1740
initial.commit09911bf2008-07-26 23:55:291741void RenderView::ShowModalHTMLDialog(const GURL& url, int width, int height,
1742 const std::string& json_arguments,
1743 std::string* json_retval) {
1744 IPC::SyncMessage* msg = new ViewHostMsg_ShowModalHTMLDialog(
1745 routing_id_, url, width, height, json_arguments, json_retval);
1746
[email protected]1c4947f2009-01-15 22:25:111747 msg->set_pump_messages_event(modal_dialog_event_.get());
initial.commit09911bf2008-07-26 23:55:291748 Send(msg);
1749}
1750
1751uint32 RenderView::GetCPBrowsingContext() {
1752 uint32 context = 0;
1753 Send(new ViewHostMsg_GetCPBrowsingContext(&context));
1754 return context;
1755}
1756
1757// Tell the browser to display a destination link.
1758void RenderView::UpdateTargetURL(WebView* webview, const GURL& url) {
1759 if (url != target_url_) {
1760 if (target_url_status_ == TARGET_INFLIGHT ||
1761 target_url_status_ == TARGET_PENDING) {
1762 // If we have a request in-flight, save the URL to be sent when we
1763 // receive an ACK to the in-flight request. We can happily overwrite
1764 // any existing pending sends.
1765 pending_target_url_ = url;
1766 target_url_status_ = TARGET_PENDING;
1767 } else {
1768 Send(new ViewHostMsg_UpdateTargetURL(routing_id_, page_id_, url));
1769 target_url_ = url;
1770 target_url_status_ = TARGET_INFLIGHT;
1771 }
1772 }
1773}
1774
[email protected]b62d1a8c2009-01-13 23:54:571775void RenderView::RunFileChooser(bool multi_select,
1776 const std::wstring& title,
1777 const std::wstring& default_filename,
1778 const std::wstring& filter,
initial.commit09911bf2008-07-26 23:55:291779 WebFileChooserCallback* file_chooser) {
1780 if (file_chooser_.get()) {
1781 // TODO(brettw): bug 1235154: This should be a synchronous message to deal
1782 // with the fact that web pages can programatically trigger this. With the
1783 // asnychronous messages, we can get an additional call when one is pending,
1784 // which this test is for. For now, we just ignore the additional file
1785 // chooser request. WebKit doesn't do anything to expect the callback, so
1786 // we can just ignore calling it.
1787 delete file_chooser;
1788 return;
1789 }
1790 file_chooser_.reset(file_chooser);
[email protected]b62d1a8c2009-01-13 23:54:571791 Send(new ViewHostMsg_RunFileChooser(routing_id_, multi_select, title,
1792 default_filename, filter));
initial.commit09911bf2008-07-26 23:55:291793}
1794
1795void RenderView::AddMessageToConsole(WebView* webview,
1796 const std::wstring& message,
1797 unsigned int line_no,
1798 const std::wstring& source_id) {
1799 Send(new ViewHostMsg_AddMessageToConsole(routing_id_, message,
1800 static_cast<int32>(line_no),
1801 source_id));
1802}
1803
1804void RenderView::AddSearchProvider(const std::string& url) {
1805 AddGURLSearchProvider(GURL(url),
1806 false); // not autodetected
1807}
1808
1809void RenderView::DebuggerOutput(const std::wstring& out) {
1810 Send(new ViewHostMsg_DebuggerOutput(routing_id_, out));
1811}
1812
1813WebView* RenderView::CreateWebView(WebView* webview, bool user_gesture) {
[email protected]0aa55312008-10-17 21:53:081814 // Check to make sure we aren't overloading on popups.
1815 if (shared_popup_counter_->data > kMaximumNumberOfUnacknowledgedPopups)
1816 return NULL;
1817
[email protected]634a6f92008-12-01 21:39:311818 // This window can't be closed from a window.close() call until we receive a
1819 // message from the Browser process explicitly allowing it.
1820 popup_notification_visible_ = true;
1821
initial.commit09911bf2008-07-26 23:55:291822 int32 routing_id = MSG_ROUTING_NONE;
[email protected]6c8afae52009-01-22 02:24:571823
[email protected]18bcc3c2009-01-27 21:39:151824 ModalDialogEvent modal_dialog_event;
[email protected]6c8afae52009-01-22 02:24:571825 render_thread_->Send(
[email protected]15787f8f2008-10-17 15:29:031826 new ViewHostMsg_CreateWindow(routing_id_, user_gesture, &routing_id,
1827 &modal_dialog_event));
initial.commit09911bf2008-07-26 23:55:291828 if (routing_id == MSG_ROUTING_NONE) {
initial.commit09911bf2008-07-26 23:55:291829 return NULL;
1830 }
1831
1832 // The WebView holds a reference to this new RenderView
1833 const WebPreferences& prefs = webview->GetPreferences();
[email protected]6c8afae52009-01-22 02:24:571834 base::WaitableEvent* waitable_event = new base::WaitableEvent
1835#if defined(OS_WIN)
[email protected]18bcc3c2009-01-27 21:39:151836 (modal_dialog_event.event);
[email protected]6c8afae52009-01-22 02:24:571837#else
1838 (true, false);
1839#endif
[email protected]81a34412009-01-05 19:17:241840 RenderView* view = RenderView::Create(render_thread_,
[email protected]1c4947f2009-01-15 22:25:111841 NULL, waitable_event, routing_id_,
[email protected]0aa55312008-10-17 21:53:081842 prefs, shared_popup_counter_,
1843 routing_id);
initial.commit09911bf2008-07-26 23:55:291844 view->set_opened_by_user_gesture(user_gesture);
1845
1846 // Copy over the alternate error page URL so we can have alt error pages in
1847 // the new render view (we don't need the browser to send the URL back down).
1848 view->alternate_error_page_url_ = alternate_error_page_url_;
1849
1850 return view->webview();
1851}
1852
[email protected]0ebf3872008-11-07 21:35:031853WebWidget* RenderView::CreatePopupWidget(WebView* webview,
[email protected]cfd727f2009-01-09 20:21:111854 bool activatable) {
[email protected]8085dbc82008-09-26 22:53:441855 RenderWidget* widget = RenderWidget::Create(routing_id_,
[email protected]81a34412009-01-05 19:17:241856 render_thread_,
[email protected]cfd727f2009-01-09 20:21:111857 activatable);
initial.commit09911bf2008-07-26 23:55:291858 return widget->webwidget();
1859}
1860
1861WebPluginDelegate* RenderView::CreatePluginDelegate(
1862 WebView* webview,
1863 const GURL& url,
1864 const std::string& mime_type,
1865 const std::string& clsid,
1866 std::string* actual_mime_type) {
[email protected]6c8afae52009-01-22 02:24:571867#if defined(OS_WIN)
[email protected]88a1fb47a2009-03-13 00:18:061868 if (RenderProcess::current()->in_process_plugins()) {
[email protected]690a99c2009-01-06 16:48:451869 FilePath path;
[email protected]81a34412009-01-05 19:17:241870 render_thread_->Send(
initial.commit09911bf2008-07-26 23:55:291871 new ViewHostMsg_GetPluginPath(url, mime_type, clsid, &path,
1872 actual_mime_type));
[email protected]690a99c2009-01-06 16:48:451873 if (path.value().empty())
initial.commit09911bf2008-07-26 23:55:291874 return NULL;
1875
1876 std::string mime_type_to_use;
1877 if (actual_mime_type && !actual_mime_type->empty())
1878 mime_type_to_use = *actual_mime_type;
1879 else
1880 mime_type_to_use = mime_type;
1881
[email protected]b94d3322009-02-12 19:49:041882 return WebPluginDelegate::Create(path,
1883 mime_type_to_use,
1884 gfx::NativeViewFromId(host_window_));
initial.commit09911bf2008-07-26 23:55:291885 }
1886
1887 WebPluginDelegateProxy* proxy =
1888 WebPluginDelegateProxy::Create(url, mime_type, clsid, this);
1889 if (!proxy)
1890 return NULL;
1891
1892 // We hold onto the proxy so we can poke it when we are painting. See our
1893 // DidPaint implementation below.
1894 plugin_delegates_.push_back(proxy);
1895
1896 return proxy;
[email protected]6c8afae52009-01-22 02:24:571897#else
1898 // TODO(port): Plugins currently not supported
1899 NOTIMPLEMENTED();
1900 return NULL;
1901#endif
initial.commit09911bf2008-07-26 23:55:291902}
1903
[email protected]ec9212f2008-12-18 21:40:361904webkit_glue::WebMediaPlayerDelegate* RenderView::CreateMediaPlayerDelegate() {
[email protected]be645db2009-02-06 20:36:331905#if defined(OS_WIN)
[email protected]d43ed912009-02-03 04:52:531906 return new WebMediaPlayerDelegateImpl(this);
[email protected]be645db2009-02-06 20:36:331907#else
1908 // TODO(port)
1909 NOTIMPLEMENTED();
1910 return NULL;
1911#endif
[email protected]ec9212f2008-12-18 21:40:361912}
1913
initial.commit09911bf2008-07-26 23:55:291914void RenderView::OnMissingPluginStatus(WebPluginDelegate* delegate,
1915 int status) {
[email protected]6c8afae52009-01-22 02:24:571916#if defined(OS_WIN)
initial.commit09911bf2008-07-26 23:55:291917 if (first_default_plugin_ == NULL) {
1918 // Show the InfoBar for the first available plugin.
1919 if (status == default_plugin::MISSING_PLUGIN_AVAILABLE) {
1920 first_default_plugin_ = delegate;
1921 Send(new ViewHostMsg_MissingPluginStatus(routing_id_, status));
1922 }
1923 } else {
1924 // Closes the InfoBar if user clicks on the plugin (instead of the InfoBar)
1925 // to start the download/install.
1926 if (status == default_plugin::MISSING_PLUGIN_USER_STARTED_DOWNLOAD) {
1927 Send(new ViewHostMsg_MissingPluginStatus(routing_id_, status));
1928 }
1929 }
[email protected]6c8afae52009-01-22 02:24:571930#else
1931 // TODO(port): plugins current not supported
1932 NOTIMPLEMENTED();
1933#endif
initial.commit09911bf2008-07-26 23:55:291934}
1935
[email protected]eb47a132009-03-04 00:39:561936WebWorker* RenderView::CreateWebWorker(WebWorkerClient* client) {
1937#if defined(OS_WIN)
[email protected]fd0995032009-03-24 02:01:111938 return new WebWorkerProxy(client, routing_id_);
[email protected]eb47a132009-03-04 00:39:561939#else
1940 // TODO(port): out of process workers
1941 NOTIMPLEMENTED();
1942 return NULL;
1943#endif
1944}
1945
initial.commit09911bf2008-07-26 23:55:291946void RenderView::OpenURL(WebView* webview, const GURL& url,
[email protected]c0588052008-10-27 23:01:501947 const GURL& referrer,
initial.commit09911bf2008-07-26 23:55:291948 WindowOpenDisposition disposition) {
[email protected]c0588052008-10-27 23:01:501949 Send(new ViewHostMsg_OpenURL(routing_id_, url, referrer, disposition));
initial.commit09911bf2008-07-26 23:55:291950}
1951
[email protected]1d522202009-04-04 01:56:421952void RenderView::DidContentsSizeChange(WebWidget* webwidget,
1953 int new_width,
1954 int new_height) {
1955 // TODO(rafaelw): This is a temporary solution. Only the ExtensionView wants
1956 // this notification at the moment. It isn't clean to test for ExtensionView
1957 // by examining the enabled_bindings. This needs to be generalized as it
1958 // becomes clear what extension toolbars need.
1959 if (BindingsPolicy::is_extension_enabled(enabled_bindings_)) {
1960 int width = webview()->GetMainFrame()->GetContentsPreferredWidth();
1961 Send(new ViewHostMsg_DidContentsPreferredWidthChange(routing_id_, width));
1962 }
1963}
1964
initial.commit09911bf2008-07-26 23:55:291965// We are supposed to get a single call to Show for a newly created RenderView
1966// that was created via RenderView::CreateWebView. So, we wait until this
1967// point to dispatch the ShowView message.
1968//
1969// This method provides us with the information about how to display the newly
1970// created RenderView (i.e., as a constrained popup or as a new tab).
1971//
1972void RenderView::Show(WebWidget* webwidget, WindowOpenDisposition disposition) {
1973 DCHECK(!did_show_) << "received extraneous Show call";
1974 DCHECK(opener_id_ != MSG_ROUTING_NONE);
1975
1976 if (did_show_)
1977 return;
1978 did_show_ = true;
1979
1980 // NOTE: initial_pos_ may still have its default values at this point, but
1981 // that's okay. It'll be ignored if disposition is not NEW_POPUP, or the
1982 // browser process will impose a default position otherwise.
1983 Send(new ViewHostMsg_ShowView(
1984 opener_id_, routing_id_, disposition, initial_pos_,
1985 WasOpenedByUserGestureHelper()));
1986}
1987
[email protected]634a6f92008-12-01 21:39:311988void RenderView::CloseWidgetSoon(WebWidget* webwidget) {
1989 if (popup_notification_visible_ == false)
1990 RenderWidget::CloseWidgetSoon(webwidget);
1991}
1992
initial.commit09911bf2008-07-26 23:55:291993void RenderView::RunModal(WebWidget* webwidget) {
1994 DCHECK(did_show_) << "should already have shown the view";
1995
1996 IPC::SyncMessage* msg = new ViewHostMsg_RunModal(routing_id_);
1997
[email protected]1c4947f2009-01-15 22:25:111998 msg->set_pump_messages_event(modal_dialog_event_.get());
initial.commit09911bf2008-07-26 23:55:291999 Send(msg);
2000}
2001
2002void RenderView::SyncNavigationState() {
2003 if (!webview())
2004 return;
2005
initial.commit09911bf2008-07-26 23:55:292006 std::string state;
[email protected]606843fa2008-12-02 19:08:562007 if (!webview()->GetMainFrame()->GetCurrentHistoryState(&state))
initial.commit09911bf2008-07-26 23:55:292008 return;
[email protected]606843fa2008-12-02 19:08:562009 Send(new ViewHostMsg_UpdateState(routing_id_, page_id_, state));
initial.commit09911bf2008-07-26 23:55:292010}
2011
2012void RenderView::ShowContextMenu(WebView* webview,
[email protected]124646932009-01-28 18:39:022013 ContextNode node,
initial.commit09911bf2008-07-26 23:55:292014 int x,
2015 int y,
2016 const GURL& link_url,
2017 const GURL& image_url,
2018 const GURL& page_url,
2019 const GURL& frame_url,
2020 const std::wstring& selection_text,
2021 const std::wstring& misspelled_word,
[email protected]6aa376b2008-09-23 18:49:522022 int edit_flags,
2023 const std::string& security_info) {
[email protected]e09ba552009-02-05 03:26:292024 ContextMenuParams params;
[email protected]124646932009-01-28 18:39:022025 params.node = node;
initial.commit09911bf2008-07-26 23:55:292026 params.x = x;
2027 params.y = y;
2028 params.image_url = image_url;
2029 params.link_url = link_url;
2030 params.page_url = page_url;
2031 params.frame_url = frame_url;
2032 params.selection_text = selection_text;
2033 params.misspelled_word = misspelled_word;
[email protected]be645db2009-02-06 20:36:332034 params.spellcheck_enabled =
[email protected]bbbd545c2008-12-15 20:18:042035 webview->GetFocusedFrame()->SpellCheckEnabled();
initial.commit09911bf2008-07-26 23:55:292036 params.edit_flags = edit_flags;
[email protected]6aa376b2008-09-23 18:49:522037 params.security_info = security_info;
initial.commit09911bf2008-07-26 23:55:292038 Send(new ViewHostMsg_ContextMenu(routing_id_, params));
2039}
2040
[email protected]e80c73b2009-04-07 23:24:582041void RenderView::StartDragging(WebView* webview,
2042 const WebDragData& drag_data) {
2043 Send(new ViewHostMsg_StartDragging(routing_id_, WebDropData(drag_data)));
initial.commit09911bf2008-07-26 23:55:292044}
2045
2046void RenderView::TakeFocus(WebView* webview, bool reverse) {
2047 Send(new ViewHostMsg_TakeFocus(routing_id_, reverse));
2048}
2049
2050void RenderView::DidDownloadImage(int id,
2051 const GURL& image_url,
2052 bool errored,
2053 const SkBitmap& image) {
2054 Send(new ViewHostMsg_DidDownloadImage(routing_id_, id, image_url, errored,
2055 image));
2056}
2057
2058
2059void RenderView::OnDownloadImage(int id,
2060 const GURL& image_url,
2061 int image_size) {
2062 if (!webview()->DownloadImage(id, image_url, image_size))
2063 Send(new ViewHostMsg_DidDownloadImage(routing_id_, id, image_url, true,
2064 SkBitmap()));
2065}
2066
2067void RenderView::OnGetApplicationInfo(int page_id) {
2068 webkit_glue::WebApplicationInfo app_info;
2069 if (page_id == page_id_)
2070 webkit_glue::GetApplicationInfo(webview(), &app_info);
2071
2072 // Prune out any data URLs in the set of icons. The browser process expects
2073 // any icon with a data URL to have originated from a favicon. We don't want
2074 // to decode arbitrary data URLs in the browser process. See
2075 // http://b/issue?id=1162972
2076 for (size_t i = 0; i < app_info.icons.size(); ++i) {
[email protected]6de74452009-02-25 18:04:592077 if (app_info.icons[i].url.SchemeIs(chrome::kDataScheme)) {
initial.commit09911bf2008-07-26 23:55:292078 app_info.icons.erase(app_info.icons.begin() + i);
2079 --i;
2080 }
2081 }
2082
2083 Send(new ViewHostMsg_DidGetApplicationInfo(routing_id_, page_id, app_info));
2084}
2085
2086GURL RenderView::GetAlternateErrorPageURL(const GURL& failedURL,
2087 ErrorPageType error_type) {
2088 if (failedURL.SchemeIsSecure()) {
2089 // If the URL that failed was secure, then the embedding web page was not
2090 // expecting a network attacker to be able to manipulate its contents. As
2091 // we fetch alternate error pages over HTTP, we would be allowing a network
2092 // attacker to manipulate the contents of the response if we tried to use
2093 // the link doctor here.
2094 return GURL::EmptyGURL();
2095 }
2096
2097 // Grab the base URL from the browser process.
2098 if (!alternate_error_page_url_.is_valid())
2099 return GURL::EmptyGURL();
2100
2101 // Strip query params from the failed URL.
2102 GURL::Replacements remove_params;
2103 remove_params.ClearUsername();
2104 remove_params.ClearPassword();
2105 remove_params.ClearQuery();
2106 remove_params.ClearRef();
2107 const GURL url_to_send = failedURL.ReplaceComponents(remove_params);
2108
2109 // Construct the query params to send to link doctor.
2110 std::string params(alternate_error_page_url_.query());
2111 params.append("&url=");
2112 params.append(EscapeQueryParamValue(url_to_send.spec()));
2113 params.append("&sourceid=chrome");
2114 params.append("&error=");
2115 switch (error_type) {
2116 case DNS_ERROR:
2117 params.append("dnserror");
2118 break;
2119
2120 case HTTP_404:
2121 params.append("http404");
2122 break;
2123
[email protected]5df266ac2008-10-15 19:50:132124 case CONNECTION_ERROR:
[email protected]e1f934b2009-01-26 20:41:332125 params.append("connectionfailure");
[email protected]5df266ac2008-10-15 19:50:132126 break;
2127
initial.commit09911bf2008-07-26 23:55:292128 default:
2129 NOTREACHED() << "unknown ErrorPageType";
2130 }
2131
2132 // OK, build the final url to return.
2133 GURL::Replacements link_doctor_params;
2134 link_doctor_params.SetQueryStr(params);
2135 GURL url = alternate_error_page_url_.ReplaceComponents(link_doctor_params);
2136 return url;
2137}
2138
[email protected]7ea066a2009-04-06 20:21:592139void RenderView::OnFind(int request_id,
2140 const string16& search_text,
2141 const WebKit::WebFindOptions& options) {
initial.commit09911bf2008-07-26 23:55:292142 WebFrame* main_frame = webview()->GetMainFrame();
2143 WebFrame* frame_after_main = webview()->GetNextFrameAfter(main_frame, true);
2144 WebFrame* focused_frame = webview()->GetFocusedFrame();
2145 WebFrame* search_frame = focused_frame; // start searching focused frame.
2146
2147 bool multi_frame = (frame_after_main != main_frame);
2148
2149 // If we have multiple frames, we don't want to wrap the search within the
2150 // frame, so we check here if we only have main_frame in the chain.
2151 bool wrap_within_frame = !multi_frame;
2152
2153 gfx::Rect selection_rect;
2154 bool result = false;
2155
2156 do {
[email protected]7ea066a2009-04-06 20:21:592157 result = search_frame->Find(
2158 request_id, search_text, options, wrap_within_frame, &selection_rect);
initial.commit09911bf2008-07-26 23:55:292159
2160 if (!result) {
2161 // don't leave text selected as you move to the next frame.
2162 search_frame->ClearSelection();
2163
2164 // Find the next frame, but skip the invisible ones.
2165 do {
2166 // What is the next frame to search? (we might be going backwards). Note
2167 // that we specify wrap=true so that search_frame never becomes NULL.
[email protected]7ea066a2009-04-06 20:21:592168 search_frame = options.forward ?
initial.commit09911bf2008-07-26 23:55:292169 webview()->GetNextFrameAfter(search_frame, true) :
2170 webview()->GetPreviousFrameBefore(search_frame, true);
2171 } while (!search_frame->Visible() && search_frame != focused_frame);
2172
[email protected]884db412008-11-24 23:46:502173 // Make sure selection doesn't affect the search operation in new frame.
initial.commit09911bf2008-07-26 23:55:292174 search_frame->ClearSelection();
2175
2176 // If we have multiple frames and we have wrapped back around to the
2177 // focused frame, we need to search it once more allowing wrap within
2178 // the frame, otherwise it will report 'no match' if the focused frame has
2179 // reported matches, but no frames after the focused_frame contain a
2180 // match for the search word(s).
2181 if (multi_frame && search_frame == focused_frame) {
[email protected]7ea066a2009-04-06 20:21:592182 result = search_frame->Find(
2183 request_id, search_text, options, true, // Force wrapping.
2184 &selection_rect);
initial.commit09911bf2008-07-26 23:55:292185 }
2186 }
2187
2188 // TODO(jcampan): http://b/issue?id=1157486 Remove StoreForFocus call once
2189 // we have the fix for 792423.
2190 search_frame->GetView()->StoreFocusForFrame(search_frame);
2191 webview()->SetFocusedFrame(search_frame);
2192 } while (!result && search_frame != focused_frame);
2193
2194 // Make sure we don't leave any frame focused or the focus won't be restored
2195 // properly in WebViewImpl::SetFocus(). Note that we are talking here about
2196 // focused on the SelectionController, not FocusController.
2197 // webview()->GetFocusedFrame() will still return the last focused frame (as
2198 // it queries the FocusController).
2199 // TODO(jcampan): http://b/issue?id=1157486 Remove next line once we have the
2200 // fix for 792423.
2201 webview()->SetFocusedFrame(NULL);
2202
[email protected]7ea066a2009-04-06 20:21:592203 if (options.findNext) {
[email protected]4f3dc372009-02-24 00:10:292204 // Force the main_frame to report the actual count.
[email protected]7ea066a2009-04-06 20:21:592205 main_frame->IncreaseMatchCount(0, request_id);
[email protected]4f3dc372009-02-24 00:10:292206 } else {
2207 // If nothing is found, set result to "0 of 0", otherwise, set it to
2208 // "-1 of 1" to indicate that we found at least one item, but we don't know
2209 // yet what is active.
2210 int ordinal = result ? -1 : 0; // -1 here means, we might know more later.
2211 int match_count = result ? 1 : 0; // 1 here means possibly more coming.
initial.commit09911bf2008-07-26 23:55:292212
[email protected]4f3dc372009-02-24 00:10:292213 // If we find no matches then this will be our last status update.
2214 // Otherwise the scoping effort will send more results.
2215 bool final_status_update = !result;
initial.commit09911bf2008-07-26 23:55:292216
[email protected]4f3dc372009-02-24 00:10:292217 // Send the search result over to the browser process.
[email protected]4f999132009-03-31 18:08:402218 Send(new ViewHostMsg_Find_Reply(routing_id_,
[email protected]7ea066a2009-04-06 20:21:592219 request_id,
[email protected]4f3dc372009-02-24 00:10:292220 match_count,
2221 selection_rect,
2222 ordinal,
2223 final_status_update));
initial.commit09911bf2008-07-26 23:55:292224
initial.commit09911bf2008-07-26 23:55:292225 // Scoping effort begins, starting with the mainframe.
2226 search_frame = main_frame;
2227
2228 main_frame->ResetMatchCount();
2229
2230 do {
2231 // Cancel all old scoping requests before starting a new one.
2232 search_frame->CancelPendingScopingEffort();
2233
2234 // We don't start another scoping effort unless at least one match has
2235 // been found.
2236 if (result) {
2237 // Start new scoping request. If the scoping function determines that it
2238 // needs to scope, it will defer until later.
[email protected]7ea066a2009-04-06 20:21:592239 search_frame->ScopeStringMatches(request_id,
2240 search_text,
2241 options,
initial.commit09911bf2008-07-26 23:55:292242 true); // reset the tickmarks
2243 }
2244
2245 // Iterate to the next frame. The frame will not necessarily scope, for
2246 // example if it is not visible.
2247 search_frame = webview()->GetNextFrameAfter(search_frame, true);
2248 } while (search_frame != main_frame);
2249 }
2250}
2251
2252void RenderView::ReportFindInPageMatchCount(int count, int request_id,
2253 bool final_update) {
2254 // If we have a message that has been queued up, then we should just replace
2255 // it. The ACK from the browser will make sure it gets sent when the browser
2256 // wants it.
2257 if (queued_find_reply_message_.get()) {
2258 IPC::Message* msg = new ViewHostMsg_Find_Reply(
2259 routing_id_,
2260 request_id,
2261 count,
2262 gfx::Rect(0, 0, 0, 0),
2263 -1, // Don't update active match ordinal.
2264 final_update);
2265 queued_find_reply_message_.reset(msg);
2266 } else {
2267 // Send the search result over to the browser process.
2268 Send(new ViewHostMsg_Find_Reply(
2269 routing_id_,
2270 request_id,
2271 count,
2272 gfx::Rect(0, 0, 0, 0),
2273 -1, // // Don't update active match ordinal.
2274 final_update));
2275 }
2276}
2277
2278void RenderView::ReportFindInPageSelection(int request_id,
2279 int active_match_ordinal,
2280 const gfx::Rect& selection_rect) {
2281 // Send the search result over to the browser process.
2282 Send(new ViewHostMsg_Find_Reply(routing_id_,
2283 request_id,
2284 -1,
2285 selection_rect,
2286 active_match_ordinal,
2287 false));
2288}
2289
2290bool RenderView::WasOpenedByUserGesture(WebView* webview) const {
2291 return WasOpenedByUserGestureHelper();
2292}
2293
2294bool RenderView::WasOpenedByUserGestureHelper() const {
2295 // If pop-up blocking has been disabled, then treat all new windows as if
2296 // they were opened by a user gesture. This will prevent them from being
2297 // blocked. This is a bit of a hack, there should be a more straightforward
2298 // way to disable pop-up blocking.
2299 if (disable_popup_blocking_)
2300 return true;
2301
2302 return opened_by_user_gesture_;
2303}
2304
2305void RenderView::SpellCheck(const std::wstring& word, int& misspell_location,
2306 int& misspell_length) {
2307 Send(new ViewHostMsg_SpellCheck(routing_id_, word, &misspell_location,
2308 &misspell_length));
2309}
2310
2311void RenderView::SetInputMethodState(bool enabled) {
2312 // Save the updated IME status and mark the input focus has been updated.
2313 // The IME status is to be sent to a browser process next time when
2314 // the input caret is rendered.
[email protected]9f23f592008-11-17 08:36:342315 if (!ime_control_busy_) {
2316 ime_control_updated_ = true;
2317 ime_control_new_state_ = enabled;
2318 }
initial.commit09911bf2008-07-26 23:55:292319}
2320
2321void RenderView::ScriptedPrint(WebFrame* frame) {
[email protected]6c8afae52009-01-22 02:24:572322#if defined(OS_WIN)
initial.commit09911bf2008-07-26 23:55:292323 // Retrieve the default print settings to calculate the expected number of
2324 // pages.
2325 ViewMsg_Print_Params default_settings;
2326 IPC::SyncMessage* msg =
2327 new ViewHostMsg_GetDefaultPrintSettings(routing_id_, &default_settings);
2328 if (Send(msg)) {
2329 msg = NULL;
2330 // Continue only if the settings are valid.
2331 if (default_settings.dpi && default_settings.document_cookie) {
[email protected]88a3ecc2009-03-19 17:36:222332 int expected_pages_count = 0;
2333 gfx::Size canvas_size;
2334 canvas_size.set_width(
2335 printing::ConvertUnit(default_settings.printable_size.width(),
2336 static_cast<int>(default_settings.dpi),
2337 default_settings.desired_dpi));
2338 canvas_size.set_height(
2339 printing::ConvertUnit(default_settings.printable_size.height(),
2340 static_cast<int>(default_settings.dpi),
2341 default_settings.desired_dpi));
2342 frame->BeginPrint(canvas_size, &expected_pages_count);
initial.commit09911bf2008-07-26 23:55:292343 DCHECK(expected_pages_count);
[email protected]88a3ecc2009-03-19 17:36:222344 frame->EndPrint();
initial.commit09911bf2008-07-26 23:55:292345
2346 // Ask the browser to show UI to retrieve the final print settings.
2347 ViewMsg_PrintPages_Params print_settings;
2348 // host_window_ may be NULL at this point if the current window is a popup
2349 // and the print() command has been issued from the parent. The receiver
2350 // of this message has to deal with this.
2351 msg = new ViewHostMsg_ScriptedPrint(routing_id_,
2352 host_window_,
2353 default_settings.document_cookie,
2354 expected_pages_count,
2355 &print_settings);
2356 if (Send(msg)) {
2357 msg = NULL;
2358
2359 // If the settings are invalid, early quit.
2360 if (print_settings.params.dpi &&
2361 print_settings.params.document_cookie) {
2362 // Render the printed pages. It will implicitly revert the document to
2363 // display CSS media type.
2364 PrintPages(print_settings, frame);
2365 // All went well.
2366 return;
2367 } else {
2368 // The user cancelled.
2369 }
2370 } else {
2371 // Send() failed.
2372 NOTREACHED();
2373 }
2374 } else {
2375 // The user cancelled.
2376 }
2377 } else {
2378 // Send() failed.
2379 NOTREACHED();
2380 }
2381 // TODO(maruel): bug 1123882 Alert the user that printing failed.
[email protected]6c8afae52009-01-22 02:24:572382#else // defined(OS_WIN)
2383 // TODO(port): print not implemented
2384 NOTIMPLEMENTED();
2385#endif
initial.commit09911bf2008-07-26 23:55:292386}
2387
2388void RenderView::WebInspectorOpened(int num_resources) {
2389 Send(new ViewHostMsg_InspectElement_Reply(routing_id_, num_resources));
2390}
2391
2392void RenderView::UserMetricsRecordAction(const std::wstring& action) {
2393 Send(new ViewHostMsg_UserMetricsRecordAction(routing_id_, action));
2394}
2395
2396void RenderView::DnsPrefetch(const std::vector<std::string>& host_names) {
2397 Send(new ViewHostMsg_DnsPrefetch(host_names));
2398}
2399
[email protected]630e26b2008-10-14 22:55:172400void RenderView::OnZoom(int function) {
2401 static const bool kZoomIsTextOnly = false;
2402 switch (function) {
2403 case PageZoom::SMALLER:
2404 webview()->ZoomOut(kZoomIsTextOnly);
initial.commit09911bf2008-07-26 23:55:292405 break;
[email protected]630e26b2008-10-14 22:55:172406 case PageZoom::STANDARD:
2407 webview()->ResetZoom();
initial.commit09911bf2008-07-26 23:55:292408 break;
[email protected]630e26b2008-10-14 22:55:172409 case PageZoom::LARGER:
2410 webview()->ZoomIn(kZoomIsTextOnly);
initial.commit09911bf2008-07-26 23:55:292411 break;
2412 default:
2413 NOTREACHED();
2414 }
2415}
2416
[email protected]ea8c7452009-04-02 20:47:062417void RenderView::OnInsertText(const string16& text) {
2418 webview()->InsertText(text);
2419}
2420
[email protected]e38f40152008-09-12 23:08:302421void RenderView::OnSetPageEncoding(const std::wstring& encoding_name) {
initial.commit09911bf2008-07-26 23:55:292422 webview()->SetPageEncoding(encoding_name);
2423}
2424
2425void RenderView::OnPasswordFormsSeen(WebView* webview,
2426 const std::vector<PasswordForm>& forms) {
2427 Send(new ViewHostMsg_PasswordFormsSeen(routing_id_, forms));
2428}
2429
[email protected]8d0f15c2008-11-11 01:01:092430void RenderView::OnAutofillFormSubmitted(WebView* webview,
2431 const AutofillForm& form) {
2432 Send(new ViewHostMsg_AutofillFormSubmitted(routing_id_, form));
2433}
2434
initial.commit09911bf2008-07-26 23:55:292435WebHistoryItem* RenderView::GetHistoryEntryAtOffset(int offset) {
[email protected]50b691c2008-10-31 19:08:352436 // Our history list is kept in the browser process on the UI thread. Since
2437 // we can't make a sync IPC call to that thread without risking deadlock,
2438 // we use a trick: construct a fake history item of the form:
2439 // history://go/OFFSET
2440 // When WebCore tells us to navigate to it, we tell the browser process to
2441 // do a back/forward navigation instead.
2442
2443 GURL url(StringPrintf("%s://go/%d", kBackForwardNavigationScheme, offset));
2444 history_navigation_item_ = WebHistoryItem::Create(url, L"", "", NULL);
2445 return history_navigation_item_.get();
initial.commit09911bf2008-07-26 23:55:292446}
2447
[email protected]0c0383772008-11-04 00:48:312448void RenderView::GoToEntryAtOffset(int offset) {
[email protected]f46aff62008-10-16 07:58:052449 history_back_list_count_ += offset;
2450 history_forward_list_count_ -= offset;
2451
initial.commit09911bf2008-07-26 23:55:292452 Send(new ViewHostMsg_GoToEntryAtOffset(routing_id_, offset));
2453}
2454
2455int RenderView::GetHistoryBackListCount() {
2456 return history_back_list_count_;
2457}
2458
2459int RenderView::GetHistoryForwardListCount() {
2460 return history_forward_list_count_;
2461}
2462
2463void RenderView::OnNavStateChanged(WebView* webview) {
[email protected]81a34412009-01-05 19:17:242464 if (!nav_state_sync_timer_.IsRunning()) {
2465 nav_state_sync_timer_.Start(
2466 TimeDelta::FromSeconds(delay_seconds_for_form_state_sync_), this,
2467 &RenderView::SyncNavigationState);
2468 }
initial.commit09911bf2008-07-26 23:55:292469}
2470
2471void RenderView::SetTooltipText(WebView* webview,
2472 const std::wstring& tooltip_text) {
2473 Send(new ViewHostMsg_SetTooltipText(routing_id_, tooltip_text));
2474}
2475
[email protected]2e417c82009-04-02 22:30:262476void RenderView::DidChangeSelection(bool is_empty_selection) {
2477#if defined(OS_LINUX)
2478 if (!is_empty_selection) {
2479 // TODO(estade): find a way to incrementally update the selection text.
2480 selection_text_ = webview()->GetMainFrame()->GetSelection(false);
2481 Send(new ViewHostMsg_SelectionChanged(routing_id_));
2482 }
2483#endif
2484}
2485
2486
initial.commit09911bf2008-07-26 23:55:292487void RenderView::DownloadUrl(const GURL& url, const GURL& referrer) {
2488 Send(new ViewHostMsg_DownloadUrl(routing_id_, url, referrer));
2489}
2490
[email protected]611cad42009-03-16 18:51:342491WebDevToolsAgentDelegate* RenderView::GetWebDevToolsAgentDelegate() {
[email protected]b75b7d072009-04-06 13:47:002492 return devtools_agent_.get();
[email protected]611cad42009-03-16 18:51:342493}
2494
[email protected]ea8c7452009-04-02 20:47:062495void RenderView::PasteFromSelectionClipboard() {
2496 Send(new ViewHostMsg_PasteFromSelectionClipboard(routing_id_));
2497}
2498
initial.commit09911bf2008-07-26 23:55:292499WebFrame* RenderView::GetChildFrame(const std::wstring& frame_xpath) const {
2500 WebFrame* web_frame;
2501 if (frame_xpath.empty()) {
2502 web_frame = webview()->GetMainFrame();
2503 } else {
2504 web_frame = webview()->GetMainFrame()->GetChildFrame(frame_xpath);
2505 }
2506
2507 return web_frame;
2508}
2509
[email protected]f29acf52008-11-03 20:08:332510void RenderView::EvaluateScript(const std::wstring& frame_xpath,
2511 const std::wstring& script) {
initial.commit09911bf2008-07-26 23:55:292512 WebFrame* web_frame = GetChildFrame(frame_xpath);
2513 if (!web_frame)
2514 return;
2515
[email protected]4f999132009-03-31 18:08:402516 web_frame->ExecuteScript(WebScriptSource(WideToUTF16Hack(script)));
initial.commit09911bf2008-07-26 23:55:292517}
2518
[email protected]1810e132009-03-24 23:35:482519void RenderView::InsertCSS(const std::wstring& frame_xpath,
2520 const std::string& css) {
2521 WebFrame* web_frame = GetChildFrame(frame_xpath);
2522 if (!web_frame)
2523 return;
2524
2525 web_frame->InsertCSSStyles(css);
2526}
2527
initial.commit09911bf2008-07-26 23:55:292528void RenderView::OnScriptEvalRequest(const std::wstring& frame_xpath,
2529 const std::wstring& jscript) {
[email protected]f29acf52008-11-03 20:08:332530 EvaluateScript(frame_xpath, jscript);
initial.commit09911bf2008-07-26 23:55:292531}
2532
[email protected]1810e132009-03-24 23:35:482533void RenderView::OnCSSInsertRequest(const std::wstring& frame_xpath,
2534 const std::string& css) {
2535 InsertCSS(frame_xpath, css);
2536}
2537
[email protected]7ea066a2009-04-06 20:21:592538void RenderView::OnAddMessageToConsole(
2539 const string16& frame_xpath,
2540 const string16& message,
2541 const WebConsoleMessage::Level& level) {
2542 WebFrame* web_frame = GetChildFrame(UTF16ToWideHack(frame_xpath));
[email protected]0dea3ea2009-03-31 23:30:592543 if (web_frame)
[email protected]7ea066a2009-04-06 20:21:592544 web_frame->AddMessageToConsole(WebConsoleMessage(level, message));
initial.commit09911bf2008-07-26 23:55:292545}
2546
[email protected]6c8afae52009-01-22 02:24:572547#if defined(OS_WIN)
initial.commit09911bf2008-07-26 23:55:292548void RenderView::OnDebugAttach() {
initial.commit09911bf2008-07-26 23:55:292549 Send(new ViewHostMsg_DidDebugAttach(routing_id_));
2550 // Tell the plugin host to stop accepting messages in order to avoid
2551 // hangs while the renderer is paused.
2552 // TODO(1243929): It might be an improvement to add more plumbing to do this
2553 // when the renderer is actually paused vs. just the debugger being attached.
2554 PluginChannelHost::SetListening(false);
2555}
2556
2557void RenderView::OnDebugDetach() {
2558 // Tell the plugin host to start accepting plugin messages again.
2559 PluginChannelHost::SetListening(true);
2560}
[email protected]6c8afae52009-01-22 02:24:572561#else // defined(OS_WIN)
2562// TODO(port): plugins not yet supported
2563void RenderView::OnDebugAttach() { NOTIMPLEMENTED(); }
2564void RenderView::OnDebugDetach() { NOTIMPLEMENTED(); }
2565#endif
initial.commit09911bf2008-07-26 23:55:292566
[email protected]81e63782009-02-27 19:35:092567void RenderView::OnAllowBindings(int enabled_bindings_flags) {
2568 enabled_bindings_ |= enabled_bindings_flags;
initial.commit09911bf2008-07-26 23:55:292569}
2570
2571void RenderView::OnSetDOMUIProperty(const std::string& name,
2572 const std::string& value) {
[email protected]81e63782009-02-27 19:35:092573 DCHECK(BindingsPolicy::is_dom_ui_enabled(enabled_bindings_));
initial.commit09911bf2008-07-26 23:55:292574 dom_ui_bindings_.SetProperty(name, value);
2575}
2576
2577void RenderView::OnReservePageIDRange(int size_of_range) {
2578 next_page_id_ += size_of_range + 1;
2579}
2580
[email protected]e80c73b2009-04-07 23:24:582581void RenderView::OnDragSourceEndedOrMoved(const gfx::Point& client_point,
2582 const gfx::Point& screen_point,
initial.commit09911bf2008-07-26 23:55:292583 bool ended) {
2584 if (ended)
[email protected]e80c73b2009-04-07 23:24:582585 webview()->DragSourceEndedAt(client_point, screen_point);
initial.commit09911bf2008-07-26 23:55:292586 else
[email protected]e80c73b2009-04-07 23:24:582587 webview()->DragSourceMovedTo(client_point, screen_point);
initial.commit09911bf2008-07-26 23:55:292588}
2589
2590void RenderView::OnDragSourceSystemDragEnded() {
2591 webview()->DragSourceSystemDragEnded();
2592}
2593
2594void RenderView::OnUploadFileRequest(const ViewMsg_UploadFile_Params& p) {
2595 webkit_glue::FileUploadData* f = new webkit_glue::FileUploadData;
2596 f->file_path = p.file_path;
2597 f->form_name = p.form;
2598 f->file_name = p.file;
2599 f->submit_name = p.submit;
2600
2601 // Build the other form values map.
2602 if (!p.other_values.empty()) {
2603 std::vector<std::wstring> e;
2604 std::vector<std::wstring> kvp;
2605 std::vector<std::wstring>::iterator i;
2606
2607 SplitString(p.other_values, L'\n', &e);
2608 for (i = e.begin(); i != e.end(); ++i) {
2609 SplitString(*i, L'=', &kvp);
2610 if (kvp.size() == 2)
2611 f->other_form_values[kvp[0]] = kvp[1];
2612 kvp.clear();
2613 }
2614 }
2615
2616 pending_upload_data_.reset(f);
2617 ProcessPendingUpload();
2618}
2619
2620void RenderView::ProcessPendingUpload() {
2621 webkit_glue::FileUploadData* f = pending_upload_data_.get();
2622 if (f && webview() && webkit_glue::FillFormToUploadFile(webview(), *f))
2623 ResetPendingUpload();
2624}
2625
2626void RenderView::ResetPendingUpload() {
2627 pending_upload_data_.reset();
2628}
2629
2630void RenderView::OnFormFill(const FormData& form) {
2631 webkit_glue::FillForm(this->webview(), form);
2632}
2633
2634void RenderView::OnFillPasswordForm(
2635 const PasswordFormDomManager::FillData& form_data) {
2636 webkit_glue::FillPasswordForm(this->webview(), form_data);
2637}
2638
2639void RenderView::OnDragTargetDragEnter(const WebDropData& drop_data,
[email protected]e80c73b2009-04-07 23:24:582640 const gfx::Point& client_point,
2641 const gfx::Point& screen_point) {
2642 bool is_drop_target = webview()->DragTargetDragEnter(
2643 drop_data.ToDragData(),
2644 drop_data.identity,
2645 client_point,
2646 screen_point);
initial.commit09911bf2008-07-26 23:55:292647
2648 Send(new ViewHostMsg_UpdateDragCursor(routing_id_, is_drop_target));
2649}
2650
[email protected]e80c73b2009-04-07 23:24:582651void RenderView::OnDragTargetDragOver(const gfx::Point& client_point,
2652 const gfx::Point& screen_point) {
2653 bool is_drop_target =
2654 webview()->DragTargetDragOver(client_point, screen_point);
initial.commit09911bf2008-07-26 23:55:292655
2656 Send(new ViewHostMsg_UpdateDragCursor(routing_id_, is_drop_target));
2657}
2658
2659void RenderView::OnDragTargetDragLeave() {
2660 webview()->DragTargetDragLeave();
2661}
2662
[email protected]e80c73b2009-04-07 23:24:582663void RenderView::OnDragTargetDrop(const gfx::Point& client_point,
2664 const gfx::Point& screen_point) {
2665 webview()->DragTargetDrop(client_point, screen_point);
initial.commit09911bf2008-07-26 23:55:292666}
2667
2668void RenderView::OnUpdateWebPreferences(const WebPreferences& prefs) {
2669 webview()->SetPreferences(prefs);
2670}
2671
2672void RenderView::OnSetAltErrorPageURL(const GURL& url) {
2673 alternate_error_page_url_ = url;
2674}
2675
2676void RenderView::DidPaint() {
2677 PluginDelegateList::iterator it = plugin_delegates_.begin();
2678 while (it != plugin_delegates_.end()) {
2679 (*it)->FlushGeometryUpdates();
2680 ++it;
2681 }
2682}
2683
2684void RenderView::OnInstallMissingPlugin() {
2685 // This could happen when the first default plugin is deleted.
2686 if (first_default_plugin_ == NULL)
2687 return;
2688 first_default_plugin_->InstallMissingPlugin();
2689}
2690
[email protected]b62d1a8c2009-01-13 23:54:572691void RenderView::OnFileChooserResponse(
[email protected]561abe62009-04-06 18:08:342692 const std::vector<FilePath>& file_names) {
[email protected]8029f5672009-03-20 22:33:362693 // This could happen if we navigated to a different page before the user
2694 // closed the chooser.
2695 if (!file_chooser_.get())
2696 return;
2697
[email protected]b62d1a8c2009-01-13 23:54:572698 file_chooser_->OnFileChoose(file_names);
initial.commit09911bf2008-07-26 23:55:292699 file_chooser_.reset();
2700}
2701
2702void RenderView::OnEnableViewSourceMode() {
2703 if (!webview())
2704 return;
2705 WebFrame* main_frame = webview()->GetMainFrame();
2706 if (!main_frame)
2707 return;
2708
2709 main_frame->SetInViewSourceMode(true);
2710}
2711
2712void RenderView::OnUpdateBackForwardListCount(int back_list_count,
2713 int forward_list_count) {
2714 history_back_list_count_ = back_list_count;
2715 history_forward_list_count_ = forward_list_count;
2716}
2717
[email protected]266eb6f2008-09-30 23:56:502718void RenderView::OnGetAccessibilityInfo(
[email protected]6a983b42009-03-20 20:12:252719 const webkit_glue::WebAccessibility::InParams& in_params,
2720 webkit_glue::WebAccessibility::OutParams* out_params) {
[email protected]6c8afae52009-01-22 02:24:572721#if defined(OS_WIN)
[email protected]6a983b42009-03-20 20:12:252722 if (!web_accessibility_manager_.get()) {
2723 web_accessibility_manager_.reset(
2724 webkit_glue::WebAccessibilityManager::Create());
2725 }
[email protected]266eb6f2008-09-30 23:56:502726
[email protected]6a983b42009-03-20 20:12:252727 if (!web_accessibility_manager_->GetAccObjInfo(webview(), in_params,
2728 out_params)) {
[email protected]266eb6f2008-09-30 23:56:502729 return;
2730 }
[email protected]6c8afae52009-01-22 02:24:572731#else // defined(OS_WIN)
2732 // TODO(port): accessibility not yet implemented
2733 NOTIMPLEMENTED();
2734#endif
[email protected]266eb6f2008-09-30 23:56:502735}
2736
[email protected]6a983b42009-03-20 20:12:252737void RenderView::OnClearAccessibilityInfo(int acc_obj_id, bool clear_all) {
[email protected]6c8afae52009-01-22 02:24:572738#if defined(OS_WIN)
[email protected]6a983b42009-03-20 20:12:252739 if (!web_accessibility_manager_.get()) {
[email protected]266eb6f2008-09-30 23:56:502740 // If accessibility is not activated, ignore clearing message.
2741 return;
2742 }
[email protected]6a983b42009-03-20 20:12:252743 if (!web_accessibility_manager_->ClearAccObjMap(acc_obj_id, clear_all))
[email protected]266eb6f2008-09-30 23:56:502744 return;
[email protected]6c8afae52009-01-22 02:24:572745#else // defined(OS_WIN)
2746 // TODO(port): accessibility not yet implemented
2747 NOTIMPLEMENTED();
2748#endif
[email protected]266eb6f2008-09-30 23:56:502749}
2750
initial.commit09911bf2008-07-26 23:55:292751void RenderView::OnGetAllSavableResourceLinksForCurrentPage(
2752 const GURL& page_url) {
2753 // Prepare list to storage all savable resource links.
2754 std::vector<GURL> resources_list;
2755 std::vector<GURL> referrers_list;
2756 std::vector<GURL> frames_list;
2757 webkit_glue::SavableResourcesResult result(&resources_list,
2758 &referrers_list,
2759 &frames_list);
2760
2761 if (!webkit_glue::GetAllSavableResourceLinksForCurrentPage(webview(),
2762 page_url,
2763 &result)) {
2764 // If something is wrong when collecting all savable resource links,
2765 // send empty list to embedder(browser) to tell it failed.
2766 referrers_list.clear();
2767 resources_list.clear();
2768 frames_list.clear();
2769 }
2770
2771 // Send result of all savable resource links to embedder.
2772 Send(new ViewHostMsg_SendCurrentPageAllSavableResourceLinks(routing_id_,
2773 resources_list,
2774 referrers_list,
2775 frames_list));
2776}
2777
2778void RenderView::OnGetSerializedHtmlDataForCurrentPageWithLocalLinks(
[email protected]f6b48532009-02-12 01:56:322779 const std::vector<GURL>& links,
[email protected]fde6714d12009-02-18 22:39:312780 const std::vector<FilePath>& local_paths,
2781 const FilePath& local_directory_name) {
initial.commit09911bf2008-07-26 23:55:292782 webkit_glue::DomSerializer dom_serializer(webview()->GetMainFrame(),
2783 true,
2784 this,
2785 links,
2786 local_paths,
2787 local_directory_name);
2788 dom_serializer.SerializeDom();
2789}
2790
2791void RenderView::DidSerializeDataForFrame(const GURL& frame_url,
2792 const std::string& data, PageSavingSerializationStatus status) {
2793 Send(new ViewHostMsg_SendSerializedHtmlData(routing_id_,
2794 frame_url, data, static_cast<int32>(status)));
2795}
2796
[email protected]04b4a6c2008-08-02 00:44:472797void RenderView::OnMsgShouldClose() {
initial.commit09911bf2008-07-26 23:55:292798 bool should_close = webview()->ShouldClose();
[email protected]04b4a6c2008-08-02 00:44:472799 Send(new ViewHostMsg_ShouldClose_ACK(routing_id_, should_close));
initial.commit09911bf2008-07-26 23:55:292800}
2801
2802void RenderView::OnClosePage(int new_render_process_host_id,
[email protected]04b4a6c2008-08-02 00:44:472803 int new_request_id) {
initial.commit09911bf2008-07-26 23:55:292804 // TODO(creis): We'd rather use webview()->Close() here, but that currently
2805 // sets the WebView's delegate_ to NULL, preventing any JavaScript dialogs
2806 // in the onunload handler from appearing. For now, we're bypassing that and
2807 // calling the FrameLoader's CloseURL method directly. This should be
2808 // revisited to avoid having two ways to close a page. Having a single way
2809 // to close that can run onunload is also useful for fixing
2810 // http://b/issue?id=753080.
2811 WebFrame* main_frame = webview()->GetMainFrame();
2812 if (main_frame)
2813 main_frame->ClosePage();
2814
2815 Send(new ViewHostMsg_ClosePage_ACK(routing_id_,
2816 new_render_process_host_id,
[email protected]04b4a6c2008-08-02 00:44:472817 new_request_id));
initial.commit09911bf2008-07-26 23:55:292818}
2819
2820void RenderView::OnThemeChanged() {
[email protected]6c8afae52009-01-22 02:24:572821#if defined(OS_WIN)
initial.commit09911bf2008-07-26 23:55:292822 gfx::NativeTheme::instance()->CloseHandles();
2823 gfx::Rect view_rect(0, 0, size_.width(), size_.height());
2824 DidInvalidateRect(webwidget_, view_rect);
[email protected]6c8afae52009-01-22 02:24:572825#else // defined(OS_WIN)
2826 // TODO(port): we don't support theming on non-Windows platforms yet
2827 NOTIMPLEMENTED();
2828#endif
initial.commit09911bf2008-07-26 23:55:292829}
2830
[email protected]f386cca792008-08-26 02:02:182831#ifdef CHROME_PERSONALIZATION
[email protected]1cc879642008-08-26 01:27:352832void RenderView::OnPersonalizationEvent(std::string event_name,
2833 std::string event_args) {
2834 Personalization::HandleViewMsgPersonalizationEvent(personalization_,
2835 webview(),
2836 event_name,
2837 event_args);
2838}
[email protected]f386cca792008-08-26 02:02:182839#endif
[email protected]1cc879642008-08-26 01:27:352840
2841void RenderView::TransitionToCommittedForNewPage() {
[email protected]f386cca792008-08-26 02:02:182842#ifdef CHROME_PERSONALIZATION
[email protected]1cc879642008-08-26 01:27:352843 Personalization::HandleTransitionToCommittedForNewPage(personalization_);
[email protected]f386cca792008-08-26 02:02:182844#endif
[email protected]1cc879642008-08-26 01:27:352845}
2846
[email protected]f46aff62008-10-16 07:58:052847void RenderView::DidAddHistoryItem() {
[email protected]f8901082008-10-31 23:34:032848 // We don't want to update the history length for the start page
2849 // navigation.
2850 WebFrame* main_frame = webview()->GetMainFrame();
2851 DCHECK(main_frame != NULL);
2852
2853 WebDataSource* ds = main_frame->GetDataSource();
2854 DCHECK(ds != NULL);
2855
2856 const WebRequest& request = ds->GetRequest();
2857 RenderViewExtraRequestData* extra_data =
2858 static_cast<RenderViewExtraRequestData*>(request.GetExtraData());
2859
2860 if (extra_data && extra_data->transition_type == PageTransition::START_PAGE)
2861 return;
2862
[email protected]f46aff62008-10-16 07:58:052863 history_back_list_count_++;
2864 history_forward_list_count_ = 0;
2865}
2866
[email protected]28790922009-03-09 19:48:372867void RenderView::OnMessageFromExternalHost(const std::string& message,
2868 const std::string& origin,
2869 const std::string& target) {
[email protected]3ac14a052008-08-15 21:22:152870 if (message.empty())
2871 return;
2872
[email protected]28790922009-03-09 19:48:372873 external_host_bindings_.ForwardMessageFromExternalHost(message, origin,
2874 target);
[email protected]3ac14a052008-08-15 21:22:152875}
2876
[email protected]0aa55312008-10-17 21:53:082877void RenderView::OnDisassociateFromPopupCount() {
2878 if (decrement_shared_popup_at_destruction_)
2879 shared_popup_counter_->data--;
2880 shared_popup_counter_ = new SharedRenderViewCounter(0);
2881 decrement_shared_popup_at_destruction_ = false;
2882}
2883
initial.commit09911bf2008-07-26 23:55:292884std::string RenderView::GetAltHTMLForTemplate(
2885 const DictionaryValue& error_strings, int template_resource_id) const {
2886 const StringPiece template_html(
2887 ResourceBundle::GetSharedInstance().GetRawDataResource(
2888 template_resource_id));
2889
2890 if (template_html.empty()) {
2891 NOTREACHED() << "unable to load template. ID: " << template_resource_id;
2892 return "";
2893 }
2894 // "t" is the id of the templates root node.
2895 return jstemplate_builder::GetTemplateHtml(
2896 template_html, &error_strings, "t");
2897}
[email protected]0e79b9e2009-02-13 04:20:482898
2899MessageLoop* RenderView::GetMessageLoopForIO() {
2900 // Assume that we have only one RenderThread in the process and the owner loop
2901 // of RenderThread is an IO message loop.
[email protected]8930d472009-02-21 08:05:282902 if (RenderThread::current())
2903 return RenderThread::current()->owner_loop();
[email protected]0e79b9e2009-02-13 04:20:482904 return NULL;
2905}
[email protected]6f56d482009-02-20 05:02:562906
2907void RenderView::OnRequestAudioPacket(int stream_id) {
2908 AudioRendererImpl* audio_renderer = audio_renderers_.Lookup(stream_id);
[email protected]4f3dc372009-02-24 00:10:292909 if (!audio_renderer) {
[email protected]cdb0835b2009-04-07 00:56:262910 // It is possible that AudioRendererImpl is un-registered but we still
2911 // receives packet requests here, because of closing a stream is not a
2912 // synchronous operation with the browser process.
[email protected]6f56d482009-02-20 05:02:562913 return;
2914 }
2915 audio_renderer->OnRequestPacket();
2916}
2917
2918void RenderView::OnAudioStreamCreated(
2919 int stream_id, base::SharedMemoryHandle handle, int length) {
2920 AudioRendererImpl* audio_renderer = audio_renderers_.Lookup(stream_id);
[email protected]4f3dc372009-02-24 00:10:292921 if (!audio_renderer) {
[email protected]6f56d482009-02-20 05:02:562922 return;
2923 }
2924 audio_renderer->OnCreated(handle, length);
2925}
2926
2927void RenderView::OnAudioStreamStateChanged(
2928 int stream_id, AudioOutputStream::State state, int info) {
2929 AudioRendererImpl* audio_renderer = audio_renderers_.Lookup(stream_id);
[email protected]4f3dc372009-02-24 00:10:292930 if (!audio_renderer) {
[email protected]6f56d482009-02-20 05:02:562931 return;
2932 }
2933 audio_renderer->OnStateChanged(state, info);
2934}
2935
2936void RenderView::OnAudioStreamVolume(int stream_id, double left, double right) {
2937 AudioRendererImpl* audio_renderer = audio_renderers_.Lookup(stream_id);
[email protected]4f3dc372009-02-24 00:10:292938 if (!audio_renderer) {
[email protected]6f56d482009-02-20 05:02:562939 return;
2940 }
2941 audio_renderer->OnVolume(left, right);
2942}
2943
[email protected]30f75e62009-02-25 22:01:002944void RenderView::OnMoveOrResizeStarted() {
2945 if (webview())
2946 webview()->HideAutofillPopup();
2947}
2948
[email protected]6f56d482009-02-20 05:02:562949int32 RenderView::CreateAudioStream(AudioRendererImpl* audio_renderer,
2950 AudioManager::Format format, int channels,
2951 int sample_rate, int bits_per_sample,
2952 size_t packet_size) {
[email protected]8db216e2009-03-10 22:40:312953 DCHECK(RenderThread::current()->message_loop() == MessageLoop::current());
[email protected]6f56d482009-02-20 05:02:562954 // Loop through the map and make sure there's no renderer already in the map.
2955 for (IDMap<AudioRendererImpl>::const_iterator iter = audio_renderers_.begin();
2956 iter != audio_renderers_.end(); ++iter) {
2957 DCHECK(iter->second != audio_renderer);
2958 }
2959
2960 // Add to map and send the IPC to browser process.
2961 int32 stream_id = audio_renderers_.Add(audio_renderer);
2962 ViewHostMsg_Audio_CreateStream params;
2963 params.format = format;
2964 params.channels = channels;
2965 params.sample_rate = sample_rate;
2966 params.bits_per_sample = bits_per_sample;
2967 params.packet_size = packet_size;
2968 Send(new ViewHostMsg_CreateAudioStream(routing_id_, stream_id, params));
2969 return stream_id;
2970}
2971
2972void RenderView::StartAudioStream(int stream_id) {
[email protected]8db216e2009-03-10 22:40:312973 DCHECK(RenderThread::current()->message_loop() == MessageLoop::current());
[email protected]6f56d482009-02-20 05:02:562974 DCHECK(audio_renderers_.Lookup(stream_id) != NULL);
2975 Send(new ViewHostMsg_StartAudioStream(routing_id_, stream_id));
2976}
2977
2978void RenderView::CloseAudioStream(int stream_id) {
[email protected]8db216e2009-03-10 22:40:312979 DCHECK(RenderThread::current()->message_loop() == MessageLoop::current());
[email protected]d1f17392009-04-03 23:05:302980 if (audio_renderers_.Lookup(stream_id) != NULL) {
2981 // Remove the entry from the map and send a close message to browser
2982 // process, we won't be getting anything back from browser even if there's
2983 // an error.
2984 audio_renderers_.Remove(stream_id);
2985 Send(new ViewHostMsg_CloseAudioStream(routing_id_, stream_id));
2986 }
[email protected]6f56d482009-02-20 05:02:562987}
2988
[email protected]2ee2329e2009-02-27 23:51:162989void RenderView::NotifyAudioPacketReady(int stream_id, size_t size) {
[email protected]8db216e2009-03-10 22:40:312990 DCHECK(RenderThread::current()->message_loop() == MessageLoop::current());
[email protected]6f56d482009-02-20 05:02:562991 DCHECK(audio_renderers_.Lookup(stream_id) != NULL);
[email protected]2ee2329e2009-02-27 23:51:162992 Send(new ViewHostMsg_NotifyAudioPacketReady(routing_id_, stream_id, size));
[email protected]6f56d482009-02-20 05:02:562993}
2994
2995void RenderView::GetAudioVolume(int stream_id) {
[email protected]8db216e2009-03-10 22:40:312996 DCHECK(RenderThread::current()->message_loop() == MessageLoop::current());
[email protected]6f56d482009-02-20 05:02:562997 DCHECK(audio_renderers_.Lookup(stream_id) != NULL);
2998 Send(new ViewHostMsg_GetAudioVolume(routing_id_, stream_id));
2999}
3000
3001void RenderView::SetAudioVolume(int stream_id, double left, double right) {
[email protected]8db216e2009-03-10 22:40:313002 DCHECK(RenderThread::current()->message_loop() == MessageLoop::current());
[email protected]6f56d482009-02-20 05:02:563003 DCHECK(audio_renderers_.Lookup(stream_id) != NULL);
3004 Send(new ViewHostMsg_SetAudioVolume(routing_id_, stream_id, left, right));
3005}
[email protected]30f75e62009-02-25 22:01:003006
3007void RenderView::OnResize(const gfx::Size& new_size,
3008 const gfx::Rect& resizer_rect) {
3009 if (webview())
3010 webview()->HideAutofillPopup();
3011 RenderWidget::OnResize(new_size, resizer_rect);
3012}
[email protected]0aa477bd2009-03-23 22:21:433013
[email protected]309d7a282009-03-24 09:18:273014void RenderView::SendExtensionRequest(const std::string& name,
3015 const std::string& args,
3016 int callback_id,
3017 WebFrame* callback_frame) {
3018 DCHECK(RenderThread::current()->message_loop() == MessageLoop::current());
3019
3020 if (callback_id != -1) {
3021 DCHECK(callback_frame) << "Callback specified without frame";
3022 pending_extension_callbacks_.AddWithID(callback_frame, callback_id);
3023 }
3024
3025 Send(new ViewHostMsg_ExtensionRequest(routing_id_, name, args, callback_id));
3026}
3027
3028void RenderView::OnExtensionResponse(int callback_id,
3029 const std::string& response) {
3030 WebFrame* web_frame = pending_extension_callbacks_.Lookup(callback_id);
3031 if (!web_frame)
3032 return; // The frame went away.
3033
3034 extensions_v8::ExtensionProcessBindings::ExecuteCallbackInFrame(
3035 web_frame, callback_id, response);
3036 pending_extension_callbacks_.Remove(callback_id);
3037}
[email protected]c20210e62009-04-03 21:39:263038
3039// Dump all load time histograms. We create 2 sets time based histograms,
3040// one that is specific to the navigation type and one that aggregates all
3041// navigation types
3042//
3043// Each set contains 5 histograms measuring various times.
3044// The time points we keep are
3045// request: time document was requested by user
3046// start: time load of document started
3047// finishDoc: main document loaded, before onload()
3048// finish: after onload() and all resources are loaded
3049// finish_document_load_time and finish_load_time.
3050// The times that we histogram are
3051// requestToStart,
3052// startToFinishDoc,
3053// finishDocToFinish,
3054// startToFinish,
3055// requestToFinish,
3056//
3057void RenderView::DumpLoadHistograms() const {
3058 WebFrame* main_frame = webview()->GetMainFrame();
3059 WebDataSource* ds = main_frame->GetDataSource();
3060 WebNavigationType nav_type = ds->GetNavigationType();
3061 Time request_time = ds->GetRequestTime();
3062 Time start_load_time = ds->GetStartLoadTime();
3063 Time finish_document_load_time = ds->GetFinishDocumentLoadTime();
3064 Time finish_load_time = ds->GetFinishLoadTime();
3065 TimeDelta request_to_start = start_load_time - request_time;
3066 TimeDelta start_to_finish_doc = finish_document_load_time - start_load_time;
3067 TimeDelta finish_doc_to_finish = finish_load_time - finish_document_load_time;
3068 TimeDelta start_to_finish = finish_load_time - start_load_time;
3069 TimeDelta request_to_finish = finish_load_time - start_load_time;
3070
3071 UMA_HISTOGRAM_TIMES("Renderer.All.RequestToStart", request_to_start);
3072 UMA_HISTOGRAM_TIMES("Renderer.All.StartToFinishDoc", start_to_finish_doc);
3073 UMA_HISTOGRAM_TIMES("Renderer.All.FinishDocToFinish", finish_doc_to_finish);
3074 UMA_HISTOGRAM_TIMES("Renderer.All.StartToFinish", start_to_finish);
3075 UMA_HISTOGRAM_TIMES("Renderer.All.RequestToFinish", request_to_finish);
3076 switch (nav_type) {
3077 case WebNavigationTypeLinkClicked:
3078 UMA_HISTOGRAM_TIMES(
3079 "Renderer.LinkClicked.RequestToStart", request_to_start);
3080 UMA_HISTOGRAM_TIMES(
3081 "Renderer.LinkClicked.StartToFinishDoc", start_to_finish_doc);
3082 UMA_HISTOGRAM_TIMES(
3083 "Renderer.LinkClicked.FinishDocToFinish", finish_doc_to_finish);
3084 UMA_HISTOGRAM_TIMES(
3085 "Renderer.LinkClicked.RequestToFinish", request_to_finish);
3086 UMA_HISTOGRAM_TIMES(
3087 "Renderer.LinkClicked.StartToFinish", start_to_finish);
3088 break;
3089 case WebNavigationTypeFormSubmitted:
3090 UMA_HISTOGRAM_TIMES(
3091 "Renderer.FormSubmitted.RequestToStart", request_to_start);
3092 UMA_HISTOGRAM_TIMES(
3093 "Renderer.FormSubmitted.StartToFinishDoc", start_to_finish_doc);
3094 UMA_HISTOGRAM_TIMES(
3095 "Renderer.FormSubmitted.FinishDocToFinish", finish_doc_to_finish);
3096 UMA_HISTOGRAM_TIMES(
3097 "Renderer.FormSubmitted.RequestToFinish", request_to_finish);
3098 UMA_HISTOGRAM_TIMES(
3099 "Renderer.FormSubmitted.StartToFinish", start_to_finish);
3100 break;
3101 case WebNavigationTypeBackForward:
3102 UMA_HISTOGRAM_TIMES(
3103 "Renderer.BackForward.RequestToStart", request_to_start);
3104 UMA_HISTOGRAM_TIMES(
3105 "Renderer.BackForward.StartToFinishDoc", start_to_finish_doc);
3106 UMA_HISTOGRAM_TIMES(
3107 "Renderer.BackForward.FinishDocToFinish", finish_doc_to_finish);
3108 UMA_HISTOGRAM_TIMES(
3109 "Renderer.BackForward.RequestToFinish", request_to_finish);
3110 UMA_HISTOGRAM_TIMES(
3111 "Renderer.BackForward.StartToFinish", start_to_finish);
3112 break;
3113 case WebNavigationTypeReload:
3114 UMA_HISTOGRAM_TIMES(
3115 "Renderer.Reload.RequestToStart", request_to_start);
3116 UMA_HISTOGRAM_TIMES(
3117 "Renderer.Reload.StartToFinishDoc", start_to_finish_doc);
3118 UMA_HISTOGRAM_TIMES(
3119 "Renderer.Reload.FinishDocToFinish", finish_doc_to_finish);
3120 UMA_HISTOGRAM_TIMES(
3121 "Renderer.Reload.RequestToFinish", request_to_finish);
3122 UMA_HISTOGRAM_TIMES(
3123 "Renderer.Reload.StartToFinish", start_to_finish);
3124 break;
3125 case WebNavigationTypeFormResubmitted:
3126 UMA_HISTOGRAM_TIMES(
3127 "Renderer.FormResubmitted.RequestToStart", request_to_start);
3128 UMA_HISTOGRAM_TIMES(
3129 "Renderer.FormResubmitted.StartToFinishDoc", start_to_finish_doc);
3130 UMA_HISTOGRAM_TIMES(
3131 "Renderer.FormResubmitted.FinishDocToFinish", finish_doc_to_finish);
3132 UMA_HISTOGRAM_TIMES(
3133 "Renderer.FormResubmitted.RequestToFinish", request_to_finish);
3134 UMA_HISTOGRAM_TIMES(
3135 "Renderer.FormResubmitted.StartToFinish", start_to_finish);
3136 break;
3137 case WebNavigationTypeOther:
3138 UMA_HISTOGRAM_TIMES(
3139 "Renderer.Other.RequestToStart", request_to_start);
3140 UMA_HISTOGRAM_TIMES(
3141 "Renderer.Other.StartToFinishDoc", start_to_finish_doc);
3142 UMA_HISTOGRAM_TIMES(
3143 "Renderer.Other.FinishDocToFinish", finish_doc_to_finish);
3144 UMA_HISTOGRAM_TIMES(
3145 "Renderer.Other.RequestToFinish", request_to_finish);
3146 UMA_HISTOGRAM_TIMES(
3147 "Renderer.Other.StartToFinish", start_to_finish);
3148 break;
3149 }
3150}