blob: 54305eeaab5387d0828fcf0cecc9990aea2162e9 [file] [log] [blame]
[email protected]05d478752009-04-08 23:38:161// Copyright (c) 2009 The Chromium Authors. All rights reserved.
license.botbf09a502008-08-24 00:55:552// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
initial.commit09911bf2008-07-26 23:55:294
5#include "chrome/renderer/render_view.h"
6
7#include <algorithm>
8#include <string>
9#include <vector>
10
[email protected]91e81ae2009-05-08 22:14:3811#include "app/gfx/color_utils.h"
[email protected]37126212009-05-06 02:23:3112#include "app/gfx/favicon_size.h"
[email protected]a92b8642009-05-05 23:38:5613#include "app/l10n_util.h"
[email protected]37126212009-05-06 02:23:3114#include "app/message_box_flags.h"
[email protected]9929da92009-05-05 02:05:1115#include "app/resource_bundle.h"
initial.commit09911bf2008-07-26 23:55:2916#include "base/command_line.h"
[email protected]bb063b72009-03-27 23:18:5017#include "base/compiler_specific.h"
[email protected]4646f292009-05-20 03:49:0518#include "base/field_trial.h"
initial.commit09911bf2008-07-26 23:55:2919#include "base/gfx/png_encoder.h"
[email protected]18bcc3c2009-01-27 21:39:1520#include "base/gfx/native_widget_types.h"
[email protected]8380c092009-06-25 17:45:5121#include "base/process_util.h"
initial.commit09911bf2008-07-26 23:55:2922#include "base/string_piece.h"
23#include "base/string_util.h"
[email protected]6c8afae52009-01-22 02:24:5724#include "build/build_config.h"
[email protected]81e63782009-02-27 19:35:0925#include "chrome/common/bindings_policy.h"
[email protected]ef916272009-07-08 21:40:5526#include "chrome/common/child_process_logging.h"
initial.commit09911bf2008-07-26 23:55:2927#include "chrome/common/chrome_switches.h"
[email protected]f0af6a72009-05-30 05:25:1728#include "chrome/common/chrome_constants.h"
initial.commit09911bf2008-07-26 23:55:2929#include "chrome/common/jstemplate_builder.h"
[email protected]630e26b2008-10-14 22:55:1730#include "chrome/common/page_zoom.h"
[email protected]e09ba552009-02-05 03:26:2931#include "chrome/common/render_messages.h"
[email protected]9b6f40e2009-06-11 15:54:2632#include "chrome/common/renderer_preferences.h"
initial.commit09911bf2008-07-26 23:55:2933#include "chrome/common/thumbnail_score.h"
[email protected]6de74452009-02-25 18:04:5934#include "chrome/common/url_constants.h"
initial.commit09911bf2008-07-26 23:55:2935#include "chrome/renderer/about_handler.h"
[email protected]5fb88962009-04-16 19:03:2536#include "chrome/renderer/audio_message_filter.h"
[email protected]e4ac5df2009-03-17 15:33:1137#include "chrome/renderer/devtools_agent.h"
38#include "chrome/renderer/devtools_client.h"
[email protected]f816c012009-06-26 21:48:3239#include "chrome/renderer/extensions/event_bindings.h"
[email protected]0f6053962009-07-09 19:26:3540#include "chrome/renderer/extensions/extension_process_bindings.h"
[email protected]7120f132009-07-20 21:05:3741#include "chrome/renderer/extensions/renderer_extension_bindings.h"
initial.commit09911bf2008-07-26 23:55:2942#include "chrome/renderer/localized_error.h"
[email protected]6f56d482009-02-20 05:02:5643#include "chrome/renderer/media/audio_renderer_impl.h"
[email protected]ed3fb032009-06-16 19:50:5644#include "chrome/renderer/navigation_state.h"
[email protected]d81c1e52009-06-03 22:09:5045#include "chrome/renderer/print_web_view_helper.h"
[email protected]39008c02009-02-11 23:59:2546#include "chrome/renderer/render_process.h"
[email protected]0938d3c2009-01-09 20:37:3547#include "chrome/renderer/user_script_slave.h"
initial.commit09911bf2008-07-26 23:55:2948#include "chrome/renderer/visitedlink_slave.h"
[email protected]ba4b17f2009-02-11 21:32:2949#include "chrome/renderer/webplugin_delegate_proxy.h"
[email protected]eb47a132009-03-04 00:39:5650#include "chrome/renderer/webworker_proxy.h"
[email protected]34ac8f32009-02-22 23:03:2751#include "grit/generated_resources.h"
52#include "grit/renderer_resources.h"
[email protected]f11ca0732009-04-11 00:09:3453#include "net/base/data_url.h"
initial.commit09911bf2008-07-26 23:55:2954#include "net/base/escape.h"
55#include "net/base/net_errors.h"
[email protected]c399a8a2008-11-22 19:38:0056#include "skia/ext/bitmap_platform_device.h"
[email protected]83c9e6552008-12-03 16:22:1057#include "skia/ext/image_operations.h"
[email protected]726985e22009-06-18 21:09:2858#include "webkit/api/public/WebDataSource.h"
[email protected]afdcf5c2009-05-10 20:30:4159#include "webkit/api/public/WebDragData.h"
[email protected]daa8c58e2009-06-15 17:21:1060#include "webkit/api/public/WebForm.h"
[email protected]ca948a22009-06-25 19:36:1761#include "webkit/api/public/WebHistoryItem.h"
[email protected]581b87eb2009-07-23 23:06:5662#include "webkit/api/public/WebNode.h"
[email protected]afdcf5c2009-05-10 20:30:4163#include "webkit/api/public/WebPoint.h"
64#include "webkit/api/public/WebRect.h"
65#include "webkit/api/public/WebScriptSource.h"
66#include "webkit/api/public/WebSize.h"
[email protected]726985e22009-06-18 21:09:2867#include "webkit/api/public/WebURL.h"
68#include "webkit/api/public/WebURLError.h"
69#include "webkit/api/public/WebURLRequest.h"
70#include "webkit/api/public/WebURLResponse.h"
71#include "webkit/api/public/WebVector.h"
[email protected]ba4b17f2009-02-11 21:32:2972#include "webkit/default_plugin/default_plugin_shared.h"
[email protected]ca948a22009-06-25 19:36:1773#include "webkit/glue/glue_serialize.h"
initial.commit09911bf2008-07-26 23:55:2974#include "webkit/glue/dom_operations.h"
75#include "webkit/glue/dom_serializer.h"
[email protected]f11ca0732009-04-11 00:09:3476#include "webkit/glue/image_decoder.h"
[email protected]8e296bbd2009-07-22 21:37:1777#include "webkit/glue/media/buffered_data_source.h"
[email protected]8380c092009-06-25 17:45:5178#include "webkit/glue/media/simple_data_source.h"
initial.commit09911bf2008-07-26 23:55:2979#include "webkit/glue/password_form.h"
[email protected]ba4b17f2009-02-11 21:32:2980#include "webkit/glue/plugins/plugin_list.h"
initial.commit09911bf2008-07-26 23:55:2981#include "webkit/glue/searchable_form_data.h"
[email protected]6a983b42009-03-20 20:12:2582#include "webkit/glue/webaccessibilitymanager_impl.h"
[email protected]611cad42009-03-16 18:51:3483#include "webkit/glue/webdevtoolsagent_delegate.h"
initial.commit09911bf2008-07-26 23:55:2984#include "webkit/glue/webdropdata.h"
initial.commit09911bf2008-07-26 23:55:2985#include "webkit/glue/webframe.h"
initial.commit09911bf2008-07-26 23:55:2986#include "webkit/glue/webkit_glue.h"
[email protected]add51772009-06-11 18:25:1787#include "webkit/glue/webmediaplayer_impl.h"
initial.commit09911bf2008-07-26 23:55:2988#include "webkit/glue/webpreferences.h"
[email protected]b94d3322009-02-12 19:49:0489#include "webkit/glue/webplugin_delegate.h"
[email protected]00d7e622009-04-21 23:06:0590#include "webkit/glue/webtextinput.h"
initial.commit09911bf2008-07-26 23:55:2991#include "webkit/glue/webview.h"
initial.commit09911bf2008-07-26 23:55:2992
[email protected]6c8afae52009-01-22 02:24:5793#if defined(OS_WIN)
94// TODO(port): these files are currently Windows only because they concern:
[email protected]6c8afae52009-01-22 02:24:5795// * theming
[email protected]6c8afae52009-01-22 02:24:5796#include "base/gfx/native_theme.h"
[email protected]6c8afae52009-01-22 02:24:5797#endif
98
[email protected]c20210e62009-04-03 21:39:2699using base::Time;
[email protected]e1acf6f2008-10-27 20:43:33100using base::TimeDelta;
[email protected]15d79e12009-08-02 19:23:45101using webkit_glue::AltErrorPageResourceFetcher;
[email protected]daa8c58e2009-06-15 17:21:10102using webkit_glue::AutofillForm;
[email protected]ed3fb032009-06-16 19:50:56103using webkit_glue::PasswordForm;
[email protected]daa8c58e2009-06-15 17:21:10104using webkit_glue::PasswordFormDomManager;
105using webkit_glue::SearchableFormData;
[email protected]0dea3ea2009-03-31 23:30:59106using WebKit::WebConsoleMessage;
[email protected]e6f546c32009-07-01 17:12:55107using WebKit::WebData;
[email protected]726985e22009-06-18 21:09:28108using WebKit::WebDataSource;
[email protected]e80c73b2009-04-07 23:24:58109using WebKit::WebDragData;
[email protected]daa8c58e2009-06-15 17:21:10110using WebKit::WebForm;
[email protected]ca948a22009-06-25 19:36:17111using WebKit::WebHistoryItem;
[email protected]4873c7d2009-07-16 06:36:28112using WebKit::WebNavigationPolicy;
[email protected]726985e22009-06-18 21:09:28113using WebKit::WebNavigationType;
[email protected]88efb7ec2009-07-14 16:32:59114using WebKit::WebPopupMenuInfo;
[email protected]b3f2b912009-04-09 16:18:52115using WebKit::WebRect;
[email protected]4f999132009-03-31 18:08:40116using WebKit::WebScriptSource;
[email protected]8649fb32009-06-26 17:51:02117using WebKit::WebSize;
[email protected]726985e22009-06-18 21:09:28118using WebKit::WebString;
[email protected]de570ef2009-07-29 18:27:52119using WebKit::WebTextDirection;
[email protected]726985e22009-06-18 21:09:28120using WebKit::WebURL;
121using WebKit::WebURLError;
122using WebKit::WebURLRequest;
123using WebKit::WebURLResponse;
[email protected]4873c7d2009-07-16 06:36:28124using WebKit::WebVector;
125using WebKit::WebWidget;
[email protected]27ba8532009-04-24 20:22:43126using WebKit::WebWorker;
127using WebKit::WebWorkerClient;
[email protected]e1acf6f2008-10-27 20:43:33128
initial.commit09911bf2008-07-26 23:55:29129//-----------------------------------------------------------------------------
130
131// define to write the time necessary for thumbnail/DOM text retrieval,
132// respectively, into the system debug log
133// #define TIME_BITMAP_RETRIEVAL
134// #define TIME_TEXT_RETRIEVAL
135
136// maximum number of characters in the document to index, any text beyond this
137// point will be clipped
[email protected]6c8afae52009-01-22 02:24:57138static const size_t kMaxIndexChars = 65535;
initial.commit09911bf2008-07-26 23:55:29139
140// Size of the thumbnails that we'll generate
141static const int kThumbnailWidth = 196;
142static const int kThumbnailHeight = 136;
143
144// Delay in milliseconds that we'll wait before capturing the page contents
145// and thumbnail.
146static const int kDelayForCaptureMs = 500;
147
148// Typically, we capture the page data once the page is loaded.
149// Sometimes, the page never finishes to load, preventing the page capture
150// To workaround this problem, we always perform a capture after the following
151// delay.
152static const int kDelayForForcedCaptureMs = 6000;
153
[email protected]81a34412009-01-05 19:17:24154// The default value for RenderView.delay_seconds_for_form_state_sync_, see
155// that variable for more.
156const int kDefaultDelaySecondsForFormStateSync = 5;
initial.commit09911bf2008-07-26 23:55:29157
158// The next available page ID to use. This ensures that the page IDs are
159// globally unique in the renderer.
160static int32 next_page_id_ = 1;
161
[email protected]0aa55312008-10-17 21:53:08162// The maximum number of popups that can be spawned from one page.
163static const int kMaximumNumberOfUnacknowledgedPopups = 25;
164
initial.commit09911bf2008-07-26 23:55:29165static const char* const kUnreachableWebDataURL =
[email protected]60e448982009-05-06 04:21:16166 "chrome://chromewebdata/";
initial.commit09911bf2008-07-26 23:55:29167
[email protected]50b691c2008-10-31 19:08:35168static const char* const kBackForwardNavigationScheme = "history";
169
[email protected]726985e22009-06-18 21:09:28170static void GetRedirectChain(WebDataSource* ds, std::vector<GURL>* result) {
171 WebVector<WebURL> urls;
172 ds->redirectChain(urls);
173 result->reserve(urls.size());
174 for (size_t i = 0; i < urls.size(); ++i)
175 result->push_back(urls[i]);
176}
177
initial.commit09911bf2008-07-26 23:55:29178///////////////////////////////////////////////////////////////////////////////
179
[email protected]81a34412009-01-05 19:17:24180RenderView::RenderView(RenderThreadBase* render_thread)
181 : RenderWidget(render_thread, true),
[email protected]81e63782009-02-27 19:35:09182 enabled_bindings_(0),
[email protected]e75cb49e2009-01-05 23:13:21183 target_url_status_(TARGET_NONE),
[email protected]81a34412009-01-05 19:17:24184 is_loading_(false),
[email protected]e75cb49e2009-01-05 23:13:21185 navigation_gesture_(NavigationGestureUnknown),
[email protected]81a34412009-01-05 19:17:24186 page_id_(-1),
187 last_page_id_sent_to_browser_(-1),
188 last_indexed_page_id_(-1),
[email protected]81a34412009-01-05 19:17:24189 opened_by_user_gesture_(true),
[email protected]bb063b72009-03-27 23:18:50190 ALLOW_THIS_IN_INITIALIZER_LIST(method_factory_(this)),
[email protected]81a34412009-01-05 19:17:24191 first_default_plugin_(NULL),
[email protected]e4ac5df2009-03-17 15:33:11192 devtools_agent_(NULL),
193 devtools_client_(NULL),
[email protected]81a34412009-01-05 19:17:24194 history_back_list_count_(0),
195 history_forward_list_count_(0),
[email protected]81a34412009-01-05 19:17:24196 has_unload_listener_(false),
197 decrement_shared_popup_at_destruction_(false),
[email protected]81a34412009-01-05 19:17:24198 form_field_autofill_request_id_(0),
199 popup_notification_visible_(false),
[email protected]0666aef2009-05-13 19:48:08200 delay_seconds_for_form_state_sync_(kDefaultDelaySecondsForFormStateSync),
201 preferred_width_(0),
[email protected]5c4266922009-07-10 16:41:27202 send_preferred_width_changes_(false),
[email protected]5f450e52009-07-28 13:28:11203 determine_page_text_after_loading_stops_(false),
204 last_top_level_navigation_page_id_(-1) {
initial.commit09911bf2008-07-26 23:55:29205}
206
207RenderView::~RenderView() {
[email protected]0aa55312008-10-17 21:53:08208 if (decrement_shared_popup_at_destruction_)
209 shared_popup_counter_->data--;
210
initial.commit09911bf2008-07-26 23:55:29211 // Clear any back-pointers that might still be held by plugins.
212 PluginDelegateList::iterator it = plugin_delegates_.begin();
213 while (it != plugin_delegates_.end()) {
214 (*it)->DropRenderView();
215 it = plugin_delegates_.erase(it);
216 }
217
[email protected]5fb88962009-04-16 19:03:25218 render_thread_->RemoveFilter(audio_message_filter_);
initial.commit09911bf2008-07-26 23:55:29219}
220
221/*static*/
[email protected]0aa55312008-10-17 21:53:08222RenderView* RenderView::Create(
[email protected]81a34412009-01-05 19:17:24223 RenderThreadBase* render_thread,
[email protected]18bcc3c2009-01-27 21:39:15224 gfx::NativeViewId parent_hwnd,
[email protected]1c4947f2009-01-15 22:25:11225 base::WaitableEvent* modal_dialog_event,
[email protected]0aa55312008-10-17 21:53:08226 int32 opener_id,
[email protected]80d96fa2009-06-10 22:34:51227 const RendererPreferences& renderer_prefs,
[email protected]0aa55312008-10-17 21:53:08228 const WebPreferences& webkit_prefs,
229 SharedRenderViewCounter* counter,
230 int32 routing_id) {
initial.commit09911bf2008-07-26 23:55:29231 DCHECK(routing_id != MSG_ROUTING_NONE);
[email protected]81a34412009-01-05 19:17:24232 scoped_refptr<RenderView> view = new RenderView(render_thread);
initial.commit09911bf2008-07-26 23:55:29233 view->Init(parent_hwnd,
234 modal_dialog_event,
235 opener_id,
[email protected]80d96fa2009-06-10 22:34:51236 renderer_prefs,
initial.commit09911bf2008-07-26 23:55:29237 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!
[email protected]4646f292009-05-20 03:49:05247 DCHECK_EQ(next_page_id_, 1);
initial.commit09911bf2008-07-26 23:55:29248 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.
261 if (proxy == first_default_plugin_)
262 first_default_plugin_ = NULL;
263}
264
[email protected]fb466342009-07-15 00:43:08265void RenderView::PluginCrashed(base::ProcessId pid,
266 const FilePath& plugin_path) {
267 Send(new ViewHostMsg_CrashedPlugin(routing_id_, pid, plugin_path));
initial.commit09911bf2008-07-26 23:55:29268}
269
270
271void RenderView::JSOutOfMemory() {
272 Send(new ViewHostMsg_JSOutOfMemory(routing_id_));
273}
274
[email protected]18bcc3c2009-01-27 21:39:15275void RenderView::Init(gfx::NativeViewId parent_hwnd,
[email protected]1c4947f2009-01-15 22:25:11276 base::WaitableEvent* modal_dialog_event,
initial.commit09911bf2008-07-26 23:55:29277 int32 opener_id,
[email protected]80d96fa2009-06-10 22:34:51278 const RendererPreferences& renderer_prefs,
initial.commit09911bf2008-07-26 23:55:29279 const WebPreferences& webkit_prefs,
[email protected]0aa55312008-10-17 21:53:08280 SharedRenderViewCounter* counter,
initial.commit09911bf2008-07-26 23:55:29281 int32 routing_id) {
282 DCHECK(!webview());
283
284 if (opener_id != MSG_ROUTING_NONE)
285 opener_id_ = opener_id;
286
[email protected]0aa55312008-10-17 21:53:08287 if (counter) {
288 shared_popup_counter_ = counter;
289 shared_popup_counter_->data++;
290 decrement_shared_popup_at_destruction_ = true;
291 } else {
292 shared_popup_counter_ = new SharedRenderViewCounter(0);
293 decrement_shared_popup_at_destruction_ = false;
294 }
295
[email protected]80d96fa2009-06-10 22:34:51296 OnSetRendererPrefs(renderer_prefs);
297
[email protected]58bfc6b2009-06-24 09:45:02298 devtools_agent_.reset(new DevToolsAgent(routing_id, this));
[email protected]9b9d7282009-04-08 14:13:04299
[email protected]c5b3b5e2009-02-13 06:41:11300 webwidget_ = WebView::Create(this, webkit_prefs);
initial.commit09911bf2008-07-26 23:55:29301
[email protected]2e417c82009-04-02 22:30:26302#if defined(OS_LINUX)
303 // We have to enable ourselves as the editor delegate on linux so we can copy
304 // text selections to the X clipboard.
305 webview()->SetUseEditorDelegate(true);
306#endif
307
initial.commit09911bf2008-07-26 23:55:29308 // Don't let WebCore keep a B/F list - we have our own.
309 // We let it keep 1 entry because FrameLoader::goToItem expects an item in the
310 // backForwardList, which is used only in ASSERTs.
311 webview()->SetBackForwardListSize(1);
312
313 routing_id_ = routing_id;
[email protected]81a34412009-01-05 19:17:24314 render_thread_->AddRoute(routing_id_, this);
initial.commit09911bf2008-07-26 23:55:29315 // Take a reference on behalf of the RenderThread. This will be balanced
316 // when we receive ViewMsg_Close.
317 AddRef();
318
319 // If this is a popup, we must wait for the CreatingNew_ACK message before
320 // completing initialization. Otherwise, we can finish it now.
321 if (opener_id == MSG_ROUTING_NONE) {
322 did_show_ = true;
323 CompleteInit(parent_hwnd);
324 }
325
326 host_window_ = parent_hwnd;
[email protected]1c4947f2009-01-15 22:25:11327 modal_dialog_event_.reset(modal_dialog_event);
initial.commit09911bf2008-07-26 23:55:29328
[email protected]58bfc6b2009-06-24 09:45:02329 const CommandLine& command_line = *CommandLine::ForCurrentProcess();
[email protected]81e63782009-02-27 19:35:09330 if (command_line.HasSwitch(switches::kDomAutomationController))
331 enabled_bindings_ |= BindingsPolicy::DOM_AUTOMATION;
initial.commit09911bf2008-07-26 23:55:29332
[email protected]5fb88962009-04-16 19:03:25333 audio_message_filter_ = new AudioMessageFilter(routing_id_);
334 render_thread_->AddFilter(audio_message_filter_);
initial.commit09911bf2008-07-26 23:55:29335}
336
337void RenderView::OnMessageReceived(const IPC::Message& message) {
[email protected]f8b6b6f2009-03-10 16:48:26338 WebFrame* main_frame = webview() ? webview()->GetMainFrame() : NULL;
[email protected]ef916272009-07-08 21:40:55339 child_process_logging::ScopedActiveURLSetter url_setter(
[email protected]f8b6b6f2009-03-10 16:48:26340 main_frame ? main_frame->GetURL() : GURL());
[email protected]f8b6b6f2009-03-10 16:48:26341
[email protected]b2abac72009-02-26 12:39:28342 // If this is developer tools renderer intercept tools messages first.
[email protected]e4ac5df2009-03-17 15:33:11343 if (devtools_client_.get() && devtools_client_->OnMessageReceived(message))
[email protected]b2abac72009-02-26 12:39:28344 return;
[email protected]b4b967e2009-04-22 11:33:05345 if (devtools_agent_.get() && devtools_agent_->OnMessageReceived(message))
346 return;
[email protected]b2abac72009-02-26 12:39:28347
initial.commit09911bf2008-07-26 23:55:29348 IPC_BEGIN_MESSAGE_MAP(RenderView, message)
initial.commit09911bf2008-07-26 23:55:29349 IPC_MESSAGE_HANDLER(ViewMsg_CaptureThumbnail, SendThumbnail)
initial.commit09911bf2008-07-26 23:55:29350 IPC_MESSAGE_HANDLER(ViewMsg_PrintPages, OnPrintPages)
[email protected]82270452009-06-19 15:58:01351 IPC_MESSAGE_HANDLER(ViewMsg_PrintingDone, OnPrintingDone)
initial.commit09911bf2008-07-26 23:55:29352 IPC_MESSAGE_HANDLER(ViewMsg_Navigate, OnNavigate)
353 IPC_MESSAGE_HANDLER(ViewMsg_Stop, OnStop)
354 IPC_MESSAGE_HANDLER(ViewMsg_LoadAlternateHTMLText, OnLoadAlternateHTMLText)
355 IPC_MESSAGE_HANDLER(ViewMsg_StopFinding, OnStopFinding)
356 IPC_MESSAGE_HANDLER(ViewMsg_Undo, OnUndo)
357 IPC_MESSAGE_HANDLER(ViewMsg_Redo, OnRedo)
358 IPC_MESSAGE_HANDLER(ViewMsg_Cut, OnCut)
359 IPC_MESSAGE_HANDLER(ViewMsg_Copy, OnCopy)
360 IPC_MESSAGE_HANDLER(ViewMsg_Paste, OnPaste)
361 IPC_MESSAGE_HANDLER(ViewMsg_Replace, OnReplace)
[email protected]bbbd545c2008-12-15 20:18:04362 IPC_MESSAGE_HANDLER(ViewMsg_ToggleSpellCheck, OnToggleSpellCheck)
initial.commit09911bf2008-07-26 23:55:29363 IPC_MESSAGE_HANDLER(ViewMsg_Delete, OnDelete)
364 IPC_MESSAGE_HANDLER(ViewMsg_SelectAll, OnSelectAll)
365 IPC_MESSAGE_HANDLER(ViewMsg_CopyImageAt, OnCopyImageAt)
[email protected]4b59ae602009-06-23 20:58:15366 IPC_MESSAGE_HANDLER(ViewMsg_ExecuteEditCommand, OnExecuteEditCommand)
initial.commit09911bf2008-07-26 23:55:29367 IPC_MESSAGE_HANDLER(ViewMsg_Find, OnFind)
[email protected]5c4266922009-07-10 16:41:27368 IPC_MESSAGE_HANDLER(ViewMsg_DeterminePageText, OnDeterminePageText)
[email protected]630e26b2008-10-14 22:55:17369 IPC_MESSAGE_HANDLER(ViewMsg_Zoom, OnZoom)
[email protected]ea8c7452009-04-02 20:47:06370 IPC_MESSAGE_HANDLER(ViewMsg_InsertText, OnInsertText)
initial.commit09911bf2008-07-26 23:55:29371 IPC_MESSAGE_HANDLER(ViewMsg_SetPageEncoding, OnSetPageEncoding)
[email protected]b2abac72009-02-26 12:39:28372 IPC_MESSAGE_HANDLER(ViewMsg_SetupDevToolsClient, OnSetupDevToolsClient)
[email protected]bf5c2ff392009-07-08 16:24:33373 IPC_MESSAGE_HANDLER(ViewMsg_DownloadFavIcon, OnDownloadFavIcon)
initial.commit09911bf2008-07-26 23:55:29374 IPC_MESSAGE_HANDLER(ViewMsg_ScriptEvalRequest, OnScriptEvalRequest)
[email protected]1810e132009-03-24 23:35:48375 IPC_MESSAGE_HANDLER(ViewMsg_CSSInsertRequest, OnCSSInsertRequest)
initial.commit09911bf2008-07-26 23:55:29376 IPC_MESSAGE_HANDLER(ViewMsg_AddMessageToConsole, OnAddMessageToConsole)
initial.commit09911bf2008-07-26 23:55:29377 IPC_MESSAGE_HANDLER(ViewMsg_ReservePageIDRange, OnReservePageIDRange)
378 IPC_MESSAGE_HANDLER(ViewMsg_UploadFile, OnUploadFileRequest)
379 IPC_MESSAGE_HANDLER(ViewMsg_FormFill, OnFormFill)
380 IPC_MESSAGE_HANDLER(ViewMsg_FillPasswordForm, OnFillPasswordForm)
381 IPC_MESSAGE_HANDLER(ViewMsg_DragTargetDragEnter, OnDragTargetDragEnter)
382 IPC_MESSAGE_HANDLER(ViewMsg_DragTargetDragOver, OnDragTargetDragOver)
383 IPC_MESSAGE_HANDLER(ViewMsg_DragTargetDragLeave, OnDragTargetDragLeave)
384 IPC_MESSAGE_HANDLER(ViewMsg_DragTargetDrop, OnDragTargetDrop)
[email protected]18cb2572008-08-21 20:34:45385 IPC_MESSAGE_HANDLER(ViewMsg_AllowBindings, OnAllowBindings)
initial.commit09911bf2008-07-26 23:55:29386 IPC_MESSAGE_HANDLER(ViewMsg_SetDOMUIProperty, OnSetDOMUIProperty)
[email protected]266eb6f2008-09-30 23:56:50387 IPC_MESSAGE_HANDLER(ViewMsg_DragSourceEndedOrMoved,
388 OnDragSourceEndedOrMoved)
initial.commit09911bf2008-07-26 23:55:29389 IPC_MESSAGE_HANDLER(ViewMsg_DragSourceSystemDragEnded,
390 OnDragSourceSystemDragEnded)
391 IPC_MESSAGE_HANDLER(ViewMsg_SetInitialFocus, OnSetInitialFocus)
392 IPC_MESSAGE_HANDLER(ViewMsg_FindReplyACK, OnFindReplyAck)
393 IPC_MESSAGE_HANDLER(ViewMsg_UpdateTargetURL_ACK, OnUpdateTargetURLAck)
394 IPC_MESSAGE_HANDLER(ViewMsg_UpdateWebPreferences, OnUpdateWebPreferences)
395 IPC_MESSAGE_HANDLER(ViewMsg_SetAltErrorPageURL, OnSetAltErrorPageURL)
396 IPC_MESSAGE_HANDLER(ViewMsg_InstallMissingPlugin, OnInstallMissingPlugin)
397 IPC_MESSAGE_HANDLER(ViewMsg_RunFileChooserResponse, OnFileChooserResponse)
398 IPC_MESSAGE_HANDLER(ViewMsg_EnableViewSourceMode, OnEnableViewSourceMode)
399 IPC_MESSAGE_HANDLER(ViewMsg_UpdateBackForwardListCount,
400 OnUpdateBackForwardListCount)
401 IPC_MESSAGE_HANDLER(ViewMsg_GetAllSavableResourceLinksForCurrentPage,
402 OnGetAllSavableResourceLinksForCurrentPage)
[email protected]f09c7182009-03-10 12:54:04403 IPC_MESSAGE_HANDLER(
404 ViewMsg_GetSerializedHtmlDataForCurrentPageWithLocalLinks,
405 OnGetSerializedHtmlDataForCurrentPageWithLocalLinks)
initial.commit09911bf2008-07-26 23:55:29406 IPC_MESSAGE_HANDLER(ViewMsg_GetApplicationInfo, OnGetApplicationInfo)
[email protected]266eb6f2008-09-30 23:56:50407 IPC_MESSAGE_HANDLER(ViewMsg_GetAccessibilityInfo, OnGetAccessibilityInfo)
408 IPC_MESSAGE_HANDLER(ViewMsg_ClearAccessibilityInfo,
409 OnClearAccessibilityInfo)
initial.commit09911bf2008-07-26 23:55:29410 IPC_MESSAGE_HANDLER(ViewMsg_ShouldClose, OnMsgShouldClose)
411 IPC_MESSAGE_HANDLER(ViewMsg_ClosePage, OnClosePage)
412 IPC_MESSAGE_HANDLER(ViewMsg_ThemeChanged, OnThemeChanged)
[email protected]18cb2572008-08-21 20:34:45413 IPC_MESSAGE_HANDLER(ViewMsg_HandleMessageFromExternalHost,
414 OnMessageFromExternalHost)
[email protected]0aa55312008-10-17 21:53:08415 IPC_MESSAGE_HANDLER(ViewMsg_DisassociateFromPopupCount,
416 OnDisassociateFromPopupCount)
[email protected]0ebf3872008-11-07 21:35:03417 IPC_MESSAGE_HANDLER(ViewMsg_AutofillSuggestions,
418 OnReceivedAutofillSuggestions)
[email protected]2c4410d2009-05-06 23:46:22419 IPC_MESSAGE_HANDLER(ViewMsg_PopupNotificationVisibilityChanged,
420 OnPopupNotificationVisibilityChanged)
[email protected]30f75e62009-02-25 22:01:00421 IPC_MESSAGE_HANDLER(ViewMsg_MoveOrResizeStarted, OnMoveOrResizeStarted)
[email protected]309d7a282009-03-24 09:18:27422 IPC_MESSAGE_HANDLER(ViewMsg_ExtensionResponse, OnExtensionResponse)
[email protected]7120f132009-07-20 21:05:37423 IPC_MESSAGE_HANDLER(ViewMsg_ExtensionMessageInvoke,
424 OnExtensionMessageInvoke)
[email protected]05d478752009-04-08 23:38:16425 IPC_MESSAGE_HANDLER(ViewMsg_ClearFocusedNode, OnClearFocusedNode)
[email protected]699ab0d2009-04-23 23:19:14426 IPC_MESSAGE_HANDLER(ViewMsg_SetBackground, OnSetBackground)
[email protected]0666aef2009-05-13 19:48:08427 IPC_MESSAGE_HANDLER(ViewMsg_EnableIntrinsicWidthChangedMode,
428 OnEnableIntrinsicWidthChangedMode)
[email protected]80d96fa2009-06-10 22:34:51429 IPC_MESSAGE_HANDLER(ViewMsg_SetRendererPrefs, OnSetRendererPrefs)
[email protected]581b87eb2009-07-23 23:06:56430 IPC_MESSAGE_HANDLER(ViewMsg_MediaPlayerActionAt, OnMediaPlayerActionAt)
[email protected]8c66c5a2009-07-22 17:26:34431 IPC_MESSAGE_HANDLER(ViewMsg_SetActive, OnSetActive)
[email protected]634a6f92008-12-01 21:39:31432
initial.commit09911bf2008-07-26 23:55:29433 // Have the super handle all other messages.
434 IPC_MESSAGE_UNHANDLED(RenderWidget::OnMessageReceived(message))
435 IPC_END_MESSAGE_MAP()
436}
437
initial.commit09911bf2008-07-26 23:55:29438void RenderView::SendThumbnail() {
439 WebFrame* main_frame = webview()->GetMainFrame();
440 if (!main_frame)
441 return;
442
443 // get the URL for this page
444 GURL url(main_frame->GetURL());
445 if (url.is_empty())
446 return;
447
448 if (size_.IsEmpty())
449 return; // Don't create an empty thumbnail!
450
451 ThumbnailScore score;
452 SkBitmap thumbnail;
[email protected]8649fb32009-06-26 17:51:02453 if (!CaptureThumbnail(webview(), kThumbnailWidth, kThumbnailHeight,
[email protected]b6e4bec2008-11-12 01:17:15454 &thumbnail, &score))
455 return;
456
initial.commit09911bf2008-07-26 23:55:29457 // send the thumbnail message to the browser process
[email protected]674741932009-02-04 23:44:46458 Send(new ViewHostMsg_Thumbnail(routing_id_, url, score, thumbnail));
initial.commit09911bf2008-07-26 23:55:29459}
460
[email protected]068637222009-01-29 16:58:07461void RenderView::OnPrintPages() {
initial.commit09911bf2008-07-26 23:55:29462 DCHECK(webview());
[email protected]aa82249f2009-07-16 17:23:58463 if (webview()) {
464 // If the user has selected text in the currently focused frame we print
465 // only that frame (this makes print selection work for multiple frames).
466 if (webview()->GetFocusedFrame()->HasSelection())
467 Print(webview()->GetFocusedFrame(), false);
468 else
469 Print(webview()->GetMainFrame(), false);
470 }
initial.commit09911bf2008-07-26 23:55:29471}
472
[email protected]82270452009-06-19 15:58:01473void RenderView::OnPrintingDone(int document_cookie, bool success) {
474 // Ignoring document cookie here since only one print job can be outstanding
475 // per renderer and document_cookie is 0 when printing is successful.
476 DCHECK(print_helper_.get());
477 if (print_helper_.get() != NULL) {
478 print_helper_->DidFinishPrinting(success);
479 }
480}
481
initial.commit09911bf2008-07-26 23:55:29482void RenderView::CapturePageInfo(int load_id, bool preliminary_capture) {
483 if (load_id != page_id_)
484 return; // this capture call is no longer relevant due to navigation
485 if (load_id == last_indexed_page_id_)
486 return; // we already indexed this page
487
488 if (!webview())
489 return;
490
491 WebFrame* main_frame = webview()->GetMainFrame();
492 if (!main_frame)
493 return;
494
495 // Don't index/capture pages that are in view source mode.
496 if (main_frame->GetInViewSourceMode())
497 return;
498
499 // Don't index/capture pages that failed to load. This only checks the top
500 // level frame so the thumbnail may contain a frame that failed to load.
501 WebDataSource* ds = main_frame->GetDataSource();
[email protected]726985e22009-06-18 21:09:28502 if (ds && ds->hasUnreachableURL())
initial.commit09911bf2008-07-26 23:55:29503 return;
504
505 if (!preliminary_capture)
506 last_indexed_page_id_ = load_id;
507
508 // get the URL for this page
509 GURL url(main_frame->GetURL());
510 if (url.is_empty())
511 return;
512
513 // full text
514 std::wstring contents;
515 CaptureText(main_frame, &contents);
516 if (contents.size()) {
517 // Send the text to the browser for indexing.
518 Send(new ViewHostMsg_PageContents(url, load_id, contents));
519 }
520
[email protected]5c4266922009-07-10 16:41:27521 // Send over text content of this page to the browser.
522 if (determine_page_text_after_loading_stops_) {
523 determine_page_text_after_loading_stops_ = false;
524 Send(new ViewMsg_DeterminePageText_Reply(routing_id_, contents));
525 }
526
initial.commit09911bf2008-07-26 23:55:29527 // thumbnail
528 SendThumbnail();
529}
530
531void RenderView::CaptureText(WebFrame* frame, std::wstring* contents) {
532 contents->clear();
533 if (!frame)
534 return;
535
[email protected]0faf0bd92008-09-09 20:53:27536 // Don't index any https pages. People generally don't want their bank
537 // accounts, etc. indexed on their computer, especially since some of these
538 // things are not marked cachable.
539 // TODO(brettw) we may want to consider more elaborate heuristics such as
540 // the cachability of the page. We may also want to consider subframes (this
541 // test will still index subframes if the subframe is SSL).
542 if (frame->GetURL().SchemeIsSecure())
543 return;
544
initial.commit09911bf2008-07-26 23:55:29545#ifdef TIME_TEXT_RETRIEVAL
546 double begin = time_util::GetHighResolutionTimeNow();
547#endif
548
549 // get the contents of the frame
550 frame->GetContentAsPlainText(kMaxIndexChars, contents);
551
552#ifdef TIME_TEXT_RETRIEVAL
553 double end = time_util::GetHighResolutionTimeNow();
554 char buf[128];
555 sprintf_s(buf, "%d chars retrieved for indexing in %gms\n",
556 contents.size(), (end - begin)*1000);
557 OutputDebugStringA(buf);
558#endif
559
560 // When the contents are clipped to the maximum, we don't want to have a
561 // partial word indexed at the end that might have been clipped. Therefore,
562 // terminate the string at the last space to ensure no words are clipped.
563 if (contents->size() == kMaxIndexChars) {
564 size_t last_space_index = contents->find_last_of(kWhitespaceWide);
565 if (last_space_index == std::wstring::npos)
566 return; // don't index if we got a huge block of text with no spaces
567 contents->resize(last_space_index);
568 }
569}
570
[email protected]8649fb32009-06-26 17:51:02571bool RenderView::CaptureThumbnail(WebView* view,
initial.commit09911bf2008-07-26 23:55:29572 int w,
573 int h,
574 SkBitmap* thumbnail,
575 ThumbnailScore* score) {
576#ifdef TIME_BITMAP_RETRIEVAL
577 double begin = time_util::GetHighResolutionTimeNow();
578#endif
579
[email protected]4873c7d2009-07-16 06:36:28580 view->layout();
581 const WebSize& size = view->size();
[email protected]b6e4bec2008-11-12 01:17:15582
[email protected]8649fb32009-06-26 17:51:02583 skia::PlatformCanvas canvas;
584 if (!canvas.initialize(size.width, size.height, true))
585 return false;
[email protected]4873c7d2009-07-16 06:36:28586 view->paint(&canvas, WebRect(0, 0, size.width, size.height));
[email protected]8649fb32009-06-26 17:51:02587
588 skia::BitmapPlatformDevice& device =
589 static_cast<skia::BitmapPlatformDevice&>(canvas.getTopPlatformDevice());
590
591 const SkBitmap& src_bmp = device.accessBitmap(false);
initial.commit09911bf2008-07-26 23:55:29592
593 SkRect dest_rect;
594 dest_rect.set(0, 0, SkIntToScalar(w), SkIntToScalar(h));
595 float dest_aspect = dest_rect.width() / dest_rect.height();
596
597 // Get the src rect so that we can preserve the aspect ratio while filling
598 // the destination.
599 SkIRect src_rect;
600 if (src_bmp.width() < dest_rect.width() ||
601 src_bmp.height() < dest_rect.height()) {
602 // Source image is smaller: we clip the part of source image within the
603 // dest rect, and then stretch it to fill the dest rect. We don't respect
604 // the aspect ratio in this case.
605 src_rect.set(0, 0, static_cast<S16CPU>(dest_rect.width()),
606 static_cast<S16CPU>(dest_rect.height()));
607 score->good_clipping = false;
608 } else {
609 float src_aspect = static_cast<float>(src_bmp.width()) / src_bmp.height();
610 if (src_aspect > dest_aspect) {
611 // Wider than tall, clip horizontally: we center the smaller thumbnail in
612 // the wider screen.
613 S16CPU new_width = static_cast<S16CPU>(src_bmp.height() * dest_aspect);
614 S16CPU x_offset = (src_bmp.width() - new_width) / 2;
615 src_rect.set(x_offset, 0, new_width + x_offset, src_bmp.height());
616 score->good_clipping = false;
617 } else {
618 src_rect.set(0, 0, src_bmp.width(),
619 static_cast<S16CPU>(src_bmp.width() / dest_aspect));
620 score->good_clipping = true;
621 }
622 }
623
[email protected]8649fb32009-06-26 17:51:02624 score->at_top = (view->GetMainFrame()->ScrollOffset().height == 0);
initial.commit09911bf2008-07-26 23:55:29625
626 SkBitmap subset;
[email protected]8649fb32009-06-26 17:51:02627 device.accessBitmap(false).extractSubset(&subset, src_rect);
initial.commit09911bf2008-07-26 23:55:29628
629 // Resample the subset that we want to get it the right size.
[email protected]465b34b72008-12-12 20:19:14630 *thumbnail = skia::ImageOperations::Resize(
631 subset, skia::ImageOperations::RESIZE_LANCZOS3, w, h);
initial.commit09911bf2008-07-26 23:55:29632
633 score->boring_score = CalculateBoringScore(thumbnail);
634
635#ifdef TIME_BITMAP_RETRIEVAL
636 double end = time_util::GetHighResolutionTimeNow();
637 char buf[128];
638 sprintf_s(buf, "thumbnail in %gms\n", (end - begin) * 1000);
639 OutputDebugStringA(buf);
640#endif
[email protected]b6e4bec2008-11-12 01:17:15641 return true;
initial.commit09911bf2008-07-26 23:55:29642}
643
644double RenderView::CalculateBoringScore(SkBitmap* bitmap) {
645 int histogram[256] = {0};
646 color_utils::BuildLumaHistogram(bitmap, histogram);
647
648 int color_count = *std::max_element(histogram, histogram + 256);
649 int pixel_count = bitmap->width() * bitmap->height();
650 return static_cast<double>(color_count) / pixel_count;
651}
652
653void RenderView::OnNavigate(const ViewMsg_Navigate_Params& params) {
654 if (!webview())
655 return;
656
[email protected]8c785c62009-07-13 14:20:15657 if (devtools_agent_.get())
658 devtools_agent_->OnNavigate();
659
[email protected]ef916272009-07-08 21:40:55660 child_process_logging::ScopedActiveURLSetter url_setter(params.url);
[email protected]f8b6b6f2009-03-10 16:48:26661
initial.commit09911bf2008-07-26 23:55:29662 AboutHandler::MaybeHandle(params.url);
663
664 bool is_reload = params.reload;
665
666 WebFrame* main_frame = webview()->GetMainFrame();
[email protected]ca948a22009-06-25 19:36:17667 if (is_reload && main_frame->GetCurrentHistoryItem().isNull()) {
initial.commit09911bf2008-07-26 23:55:29668 // We cannot reload if we do not have any history state. This happens, for
669 // example, when recovering from a crash. Our workaround here is a bit of
670 // a hack since it means that reload after a crashed tab does not cause an
671 // end-to-end cache validation.
672 is_reload = false;
673 }
674
[email protected]77f17a82009-05-21 04:42:54675 // A navigation resulting from loading a javascript URL should not be treated
676 // as a browser initiated event. Instead, we want it to look as if the page
677 // initiated any load resulting from JS execution.
678 if (!params.url.SchemeIs(chrome::kJavaScriptScheme)) {
[email protected]daa8c58e2009-06-15 17:21:10679 pending_navigation_state_.reset(NavigationState::CreateBrowserInitiated(
[email protected]77f17a82009-05-21 04:42:54680 params.page_id, params.transition, params.request_time));
681 }
initial.commit09911bf2008-07-26 23:55:29682
[email protected]04d3c6e2009-05-22 17:00:13683 // If we are reloading, then WebKit will use the history state of the current
684 // page, so we should just ignore any given history state. Otherwise, if we
685 // have history state, then we need to navigate to it, which corresponds to a
686 // back/forward navigation event.
[email protected]e6f546c32009-07-01 17:12:55687 if (is_reload) {
688 main_frame->Reload();
689 } else if (!params.state.empty()) {
[email protected]04d3c6e2009-05-22 17:00:13690 // We must know the page ID of the page we are navigating back to.
[email protected]f929f2f22009-06-12 16:56:58691 DCHECK_NE(params.page_id, -1);
[email protected]ca948a22009-06-25 19:36:17692 main_frame->LoadHistoryItem(
693 webkit_glue::HistoryItemFromString(params.state));
[email protected]04d3c6e2009-05-22 17:00:13694 } else {
695 // Navigate to the given URL.
[email protected]726985e22009-06-18 21:09:28696 WebURLRequest request(params.url);
initial.commit09911bf2008-07-26 23:55:29697
[email protected]e6f546c32009-07-01 17:12:55698 // A session history navigation should have been accompanied by state.
699 DCHECK_EQ(params.page_id, -1);
[email protected]04d3c6e2009-05-22 17:00:13700
[email protected]e6f546c32009-07-01 17:12:55701 if (main_frame->GetInViewSourceMode())
702 request.setCachePolicy(WebURLRequest::ReturnCacheDataElseLoad);
[email protected]04d3c6e2009-05-22 17:00:13703
[email protected]726985e22009-06-18 21:09:28704 if (params.referrer.is_valid()) {
705 request.setHTTPHeaderField(WebString::fromUTF8("Referer"),
706 WebString::fromUTF8(params.referrer.spec()));
707 }
[email protected]04d3c6e2009-05-22 17:00:13708
[email protected]726985e22009-06-18 21:09:28709 main_frame->LoadRequest(request);
[email protected]c0588052008-10-27 23:01:50710 }
711
[email protected]77f17a82009-05-21 04:42:54712 // In case LoadRequest failed before DidCreateDataSource was called.
713 pending_navigation_state_.reset();
initial.commit09911bf2008-07-26 23:55:29714}
715
716// Stop loading the current page
717void RenderView::OnStop() {
718 if (webview())
719 webview()->StopLoading();
720}
721
[email protected]e6f546c32009-07-01 17:12:55722void RenderView::OnLoadAlternateHTMLText(const std::string& html,
initial.commit09911bf2008-07-26 23:55:29723 bool new_navigation,
724 const GURL& display_url,
725 const std::string& security_info) {
726 if (!webview())
727 return;
728
[email protected]e6f546c32009-07-01 17:12:55729 pending_navigation_state_.reset(NavigationState::CreateBrowserInitiated(
730 new_navigation ? -1 : page_id_, PageTransition::LINK, Time::Now()));
731 pending_navigation_state_->set_security_info(security_info);
initial.commit09911bf2008-07-26 23:55:29732
[email protected]e6f546c32009-07-01 17:12:55733 webview()->GetMainFrame()->LoadHTMLString(html,
734 GURL(kUnreachableWebDataURL),
735 display_url,
736 !new_navigation);
737
738 pending_navigation_state_.reset();
initial.commit09911bf2008-07-26 23:55:29739}
740
741void RenderView::OnCopyImageAt(int x, int y) {
742 webview()->CopyImageAt(x, y);
743}
744
[email protected]68b1e922009-06-23 16:00:25745void RenderView::OnExecuteEditCommand(const std::string& name,
746 const std::string& value) {
747 if (!webview() || !webview()->GetFocusedFrame())
748 return;
749
[email protected]4b59ae602009-06-23 20:58:15750 webview()->GetFocusedFrame()->ExecuteEditCommandByName(name, value);
[email protected]68b1e922009-06-23 16:00:25751}
752
[email protected]b2abac72009-02-26 12:39:28753void RenderView::OnSetupDevToolsClient() {
[email protected]e4ac5df2009-03-17 15:33:11754 DCHECK(!devtools_client_.get());
755 devtools_client_.reset(new DevToolsClient(this));
[email protected]b2abac72009-02-26 12:39:28756}
757
initial.commit09911bf2008-07-26 23:55:29758void RenderView::OnStopFinding(bool clear_selection) {
759 WebView* view = webview();
760 if (!view)
761 return;
762
763 if (clear_selection)
764 view->GetFocusedFrame()->ClearSelection();
765
766 WebFrame* frame = view->GetMainFrame();
767 while (frame) {
[email protected]65134c432008-09-26 21:47:20768 frame->StopFinding(clear_selection);
initial.commit09911bf2008-07-26 23:55:29769 frame = view->GetNextFrameAfter(frame, false);
770 }
771}
772
773void RenderView::OnFindReplyAck() {
774 // Check if there is any queued up request waiting to be sent.
775 if (queued_find_reply_message_.get()) {
776 // Send the search result over to the browser process.
777 Send(queued_find_reply_message_.get());
778 queued_find_reply_message_.release();
779 }
780}
781
782void RenderView::OnUpdateTargetURLAck() {
783 // Check if there is a targeturl waiting to be sent.
784 if (target_url_status_ == TARGET_PENDING) {
785 Send(new ViewHostMsg_UpdateTargetURL(routing_id_, page_id_,
786 pending_target_url_));
787 }
788
789 target_url_status_ = TARGET_NONE;
790}
791
792void RenderView::OnUndo() {
793 if (!webview())
794 return;
795
796 webview()->GetFocusedFrame()->Undo();
797}
798
799void RenderView::OnRedo() {
800 if (!webview())
801 return;
802
803 webview()->GetFocusedFrame()->Redo();
804}
805
806void RenderView::OnCut() {
807 if (!webview())
808 return;
809
810 webview()->GetFocusedFrame()->Cut();
811}
812
813void RenderView::OnCopy() {
814 if (!webview())
815 return;
816
817 webview()->GetFocusedFrame()->Copy();
818}
819
820void RenderView::OnPaste() {
821 if (!webview())
822 return;
823
824 webview()->GetFocusedFrame()->Paste();
825}
826
827void RenderView::OnReplace(const std::wstring& text) {
828 if (!webview())
829 return;
830
831 webview()->GetFocusedFrame()->Replace(text);
832}
833
[email protected]bbbd545c2008-12-15 20:18:04834void RenderView::OnToggleSpellCheck() {
835 if (!webview())
836 return;
837
838 webview()->GetFocusedFrame()->ToggleSpellCheck();
839}
840
initial.commit09911bf2008-07-26 23:55:29841void RenderView::OnDelete() {
842 if (!webview())
843 return;
844
845 webview()->GetFocusedFrame()->Delete();
846}
847
848void RenderView::OnSelectAll() {
849 if (!webview())
850 return;
851
852 webview()->GetFocusedFrame()->SelectAll();
853}
854
855void RenderView::OnSetInitialFocus(bool reverse) {
856 if (!webview())
857 return;
858 webview()->SetInitialFocus(reverse);
859}
860
861///////////////////////////////////////////////////////////////////////////////
862
863// Tell the embedding application that the URL of the active page has changed
864void RenderView::UpdateURL(WebFrame* frame) {
865 WebDataSource* ds = frame->GetDataSource();
866 DCHECK(ds);
867
[email protected]726985e22009-06-18 21:09:28868 const WebURLRequest& request = ds->request();
869 const WebURLRequest& original_request = ds->originalRequest();
870 const WebURLResponse& response = ds->response();
initial.commit09911bf2008-07-26 23:55:29871
[email protected]daa8c58e2009-06-15 17:21:10872 NavigationState* navigation_state = NavigationState::FromDataSource(ds);
873 DCHECK(navigation_state);
initial.commit09911bf2008-07-26 23:55:29874
875 ViewHostMsg_FrameNavigate_Params params;
[email protected]726985e22009-06-18 21:09:28876 params.http_status_code = response.httpStatusCode();
initial.commit09911bf2008-07-26 23:55:29877 params.is_post = false;
878 params.page_id = page_id_;
[email protected]726985e22009-06-18 21:09:28879 params.is_content_filtered = response.isContentFiltered();
[email protected]e6f546c32009-07-01 17:12:55880 if (!navigation_state->security_info().empty()) {
initial.commit09911bf2008-07-26 23:55:29881 // SSL state specified in the request takes precedence over the one in the
882 // response.
883 // So far this is only intended for error pages that are not expected to be
884 // over ssl, so we should not get any clash.
[email protected]726985e22009-06-18 21:09:28885 DCHECK(response.securityInfo().isEmpty());
[email protected]e6f546c32009-07-01 17:12:55886 params.security_info = navigation_state->security_info();
initial.commit09911bf2008-07-26 23:55:29887 } else {
[email protected]726985e22009-06-18 21:09:28888 params.security_info = response.securityInfo();
initial.commit09911bf2008-07-26 23:55:29889 }
890
891 // Set the URL to be displayed in the browser UI to the user.
[email protected]726985e22009-06-18 21:09:28892 if (ds->hasUnreachableURL()) {
893 params.url = ds->unreachableURL();
initial.commit09911bf2008-07-26 23:55:29894 } else {
[email protected]726985e22009-06-18 21:09:28895 params.url = request.url();
initial.commit09911bf2008-07-26 23:55:29896 }
897
[email protected]726985e22009-06-18 21:09:28898 GetRedirectChain(ds, &params.redirects);
899 params.should_update_history = !ds->hasUnreachableURL();
initial.commit09911bf2008-07-26 23:55:29900
901 const SearchableFormData* searchable_form_data =
[email protected]daa8c58e2009-06-15 17:21:10902 navigation_state->searchable_form_data();
initial.commit09911bf2008-07-26 23:55:29903 if (searchable_form_data) {
904 params.searchable_form_url = searchable_form_data->url();
905 params.searchable_form_element_name = searchable_form_data->element_name();
906 params.searchable_form_encoding = searchable_form_data->encoding();
907 }
908
909 const PasswordForm* password_form_data =
[email protected]daa8c58e2009-06-15 17:21:10910 navigation_state->password_form_data();
initial.commit09911bf2008-07-26 23:55:29911 if (password_form_data)
912 params.password_form = *password_form_data;
913
914 params.gesture = navigation_gesture_;
915 navigation_gesture_ = NavigationGestureUnknown;
916
[email protected]77f17a82009-05-21 04:42:54917 if (!frame->GetParent()) {
initial.commit09911bf2008-07-26 23:55:29918 // Top-level navigation.
919
920 // Update contents MIME type for main frame.
[email protected]726985e22009-06-18 21:09:28921 params.contents_mime_type = UTF16ToUTF8(ds->response().mimeType());
initial.commit09911bf2008-07-26 23:55:29922
[email protected]daa8c58e2009-06-15 17:21:10923 params.transition = navigation_state->transition_type();
initial.commit09911bf2008-07-26 23:55:29924 if (!PageTransition::IsMainFrame(params.transition)) {
925 // If the main frame does a load, it should not be reported as a subframe
926 // navigation. This can occur in the following case:
927 // 1. You're on a site with frames.
928 // 2. You do a subframe navigation. This is stored with transition type
929 // MANUAL_SUBFRAME.
930 // 3. You navigate to some non-frame site, say, google.com.
931 // 4. You navigate back to the page from step 2. Since it was initially
932 // MANUAL_SUBFRAME, it will be that same transition type here.
933 // We don't want that, because any navigation that changes the toplevel
934 // frame should be tracked as a toplevel navigation (this allows us to
935 // update the URL bar, etc).
936 params.transition = PageTransition::LINK;
937 }
938
initial.commit09911bf2008-07-26 23:55:29939 // If we have a valid consumed client redirect source,
940 // the page contained a client redirect (meta refresh, document.loc...),
941 // so we set the referrer and transition to match.
942 if (completed_client_redirect_src_.is_valid()) {
[email protected]77e09a92008-08-01 18:11:04943 DCHECK(completed_client_redirect_src_ == params.redirects[0]);
initial.commit09911bf2008-07-26 23:55:29944 params.referrer = completed_client_redirect_src_;
945 params.transition = static_cast<PageTransition::Type>(
946 params.transition | PageTransition::CLIENT_REDIRECT);
947 } else {
948 // Bug 654101: the referrer will be empty on https->http transitions. It
949 // would be nice if we could get the real referrer from somewhere.
[email protected]726985e22009-06-18 21:09:28950 params.referrer = GURL(
951 original_request.httpHeaderField(WebString::fromUTF8("Referer")));
initial.commit09911bf2008-07-26 23:55:29952 }
953
[email protected]726985e22009-06-18 21:09:28954 string16 method = request.httpMethod();
955 if (EqualsASCII(method, "POST"))
initial.commit09911bf2008-07-26 23:55:29956 params.is_post = true;
957
958 Send(new ViewHostMsg_FrameNavigate(routing_id_, params));
959 } else {
960 // Subframe navigation: the type depends on whether this navigation
961 // generated a new session history entry. When they do generate a session
962 // history entry, it means the user initiated the navigation and we should
963 // mark it as such. This test checks if this is the first time UpdateURL
964 // has been called since WillNavigateToURL was called to initiate the load.
965 if (page_id_ > last_page_id_sent_to_browser_)
966 params.transition = PageTransition::MANUAL_SUBFRAME;
967 else
968 params.transition = PageTransition::AUTO_SUBFRAME;
969
initial.commit09911bf2008-07-26 23:55:29970 Send(new ViewHostMsg_FrameNavigate(routing_id_, params));
971 }
972
973 last_page_id_sent_to_browser_ =
974 std::max(last_page_id_sent_to_browser_, page_id_);
975
976 // If we end up reusing this WebRequest (for example, due to a #ref click),
[email protected]daa8c58e2009-06-15 17:21:10977 // we don't want the transition type to persist. Just clear it.
978 navigation_state->set_transition_type(PageTransition::LINK);
[email protected]266eb6f2008-09-30 23:56:50979
[email protected]6c8afae52009-01-22 02:24:57980#if defined(OS_WIN)
[email protected]6a983b42009-03-20 20:12:25981 if (web_accessibility_manager_.get()) {
[email protected]be645db2009-02-06 20:36:33982 // Clear accessibility info cache.
[email protected]6a983b42009-03-20 20:12:25983 web_accessibility_manager_->ClearAccObjMap(-1, true);
[email protected]266eb6f2008-09-30 23:56:50984 }
[email protected]6c8afae52009-01-22 02:24:57985#else
[email protected]7d926f92009-03-03 14:26:54986 // TODO(port): accessibility not yet implemented. See http://crbug.com/8288.
[email protected]6c8afae52009-01-22 02:24:57987#endif
initial.commit09911bf2008-07-26 23:55:29988}
989
990// Tell the embedding application that the title of the active page has changed
991void RenderView::UpdateTitle(WebFrame* frame, const std::wstring& title) {
992 // Ignore all but top level navigations...
[email protected]f0af6a72009-05-30 05:25:17993 if (webview()->GetMainFrame() == frame) {
994 Send(new ViewHostMsg_UpdateTitle(
995 routing_id_,
996 page_id_,
997 title.length() > chrome::kMaxTitleChars ?
998 title.substr(0, chrome::kMaxTitleChars) : title));
999 }
initial.commit09911bf2008-07-26 23:55:291000}
1001
1002void RenderView::UpdateEncoding(WebFrame* frame,
[email protected]e38f40152008-09-12 23:08:301003 const std::wstring& encoding_name) {
initial.commit09911bf2008-07-26 23:55:291004 // Only update main frame's encoding_name.
1005 if (webview()->GetMainFrame() == frame &&
1006 last_encoding_name_ != encoding_name) {
[email protected]e38f40152008-09-12 23:08:301007 // Save the encoding name for later comparing.
initial.commit09911bf2008-07-26 23:55:291008 last_encoding_name_ = encoding_name;
1009
[email protected]e38f40152008-09-12 23:08:301010 Send(new ViewHostMsg_UpdateEncoding(routing_id_, last_encoding_name_));
initial.commit09911bf2008-07-26 23:55:291011 }
1012}
1013
[email protected]f4d34b52008-11-24 23:05:011014// Sends the previous session history state to the browser so it will be saved
1015// before we navigate to a new page. This must be called *before* the page ID
1016// has been updated so we know what it was.
initial.commit09911bf2008-07-26 23:55:291017void RenderView::UpdateSessionHistory(WebFrame* frame) {
1018 // If we have a valid page ID at this point, then it corresponds to the page
1019 // we are navigating away from. Otherwise, this is the first navigation, so
1020 // there is no past session history to record.
1021 if (page_id_ == -1)
1022 return;
1023
[email protected]ca948a22009-06-25 19:36:171024 const WebHistoryItem& item =
1025 webview()->GetMainFrame()->GetPreviousHistoryItem();
1026 if (item.isNull())
initial.commit09911bf2008-07-26 23:55:291027 return;
[email protected]ca948a22009-06-25 19:36:171028
1029 Send(new ViewHostMsg_UpdateState(
1030 routing_id_, page_id_, webkit_glue::HistoryItemToString(item)));
initial.commit09911bf2008-07-26 23:55:291031}
1032
1033///////////////////////////////////////////////////////////////////////////////
1034// WebViewDelegate
1035
[email protected]80d96fa2009-06-10 22:34:511036bool RenderView::CanAcceptLoadDrops() const {
1037 return renderer_preferences_.can_accept_load_drops;
1038}
1039
initial.commit09911bf2008-07-26 23:55:291040void RenderView::DidStartLoading(WebView* webview) {
1041 if (is_loading_) {
1042 DLOG(WARNING) << "DidStartLoading called while loading";
1043 return;
1044 }
1045
1046 is_loading_ = true;
1047 // Clear the pointer so that we can assign it only when there is an unknown
1048 // plugin on a page.
1049 first_default_plugin_ = NULL;
1050
[email protected]329581b2009-04-28 06:52:351051 Send(new ViewHostMsg_DidStartLoading(routing_id_));
initial.commit09911bf2008-07-26 23:55:291052}
1053
1054void RenderView::DidStopLoading(WebView* webview) {
1055 if (!is_loading_) {
1056 DLOG(WARNING) << "DidStopLoading called while not loading";
1057 return;
1058 }
1059
1060 is_loading_ = false;
1061
1062 // NOTE: For now we're doing the safest thing, and sending out notification
1063 // when done loading. This currently isn't an issue as the favicon is only
1064 // displayed when done loading. Ideally we would send notification when
1065 // finished parsing the head, but webkit doesn't support that yet.
1066 // The feed discovery code would also benefit from access to the head.
1067 GURL favicon_url(webview->GetMainFrame()->GetFavIconURL());
1068 if (!favicon_url.is_empty())
1069 Send(new ViewHostMsg_UpdateFavIconURL(routing_id_, page_id_, favicon_url));
1070
1071 AddGURLSearchProvider(webview->GetMainFrame()->GetOSDDURL(),
1072 true); // autodetected
1073
[email protected]329581b2009-04-28 06:52:351074 Send(new ViewHostMsg_DidStopLoading(routing_id_));
initial.commit09911bf2008-07-26 23:55:291075
1076 MessageLoop::current()->PostDelayedTask(FROM_HERE,
1077 method_factory_.NewRunnableMethod(&RenderView::CapturePageInfo, page_id_,
1078 false),
1079 kDelayForCaptureMs);
1080
1081 // The page is loaded. Try to process the file we need to upload if any.
1082 ProcessPendingUpload();
1083
1084 // Since the page is done loading, we are sure we don't need to try
1085 // again.
1086 ResetPendingUpload();
1087}
1088
[email protected]77f17a82009-05-21 04:42:541089void RenderView::DidCreateDataSource(WebFrame* frame, WebDataSource* ds) {
[email protected]daa8c58e2009-06-15 17:21:101090 // The rest of RenderView assumes that a WebDataSource will always have a
1091 // non-null NavigationState.
1092 if (pending_navigation_state_.get()) {
[email protected]726985e22009-06-18 21:09:281093 ds->setExtraData(pending_navigation_state_.release());
[email protected]daa8c58e2009-06-15 17:21:101094 } else {
[email protected]726985e22009-06-18 21:09:281095 ds->setExtraData(NavigationState::CreateContentInitiated());
[email protected]daa8c58e2009-06-15 17:21:101096 }
[email protected]77f17a82009-05-21 04:42:541097}
1098
[email protected]a2f6bc112009-06-27 16:27:251099void RenderView::DidPaint() {
1100 WebFrame* main_frame = webview()->GetMainFrame();
1101
1102 if (main_frame->GetProvisionalDataSource()) {
1103 // If we have a provisional frame we are between the start
1104 // and commit stages of loading...ignore this paint.
1105 return;
1106 }
1107
1108 WebDataSource* ds = main_frame->GetDataSource();
1109 NavigationState* navigation_state = NavigationState::FromDataSource(ds);
[email protected]78a3a6f2009-07-02 16:15:011110 DCHECK(navigation_state);
1111
1112 Time now = Time::Now();
1113 if (navigation_state->first_paint_time().is_null()) {
1114 navigation_state->set_first_paint_time(now);
1115 }
1116 if (navigation_state->first_paint_after_load_time().is_null() &&
1117 !navigation_state->finish_load_time().is_null()) {
1118 navigation_state->set_first_paint_after_load_time(now);
[email protected]a2f6bc112009-06-27 16:27:251119 }
1120}
1121
initial.commit09911bf2008-07-26 23:55:291122void RenderView::DidStartProvisionalLoadForFrame(
1123 WebView* webview,
1124 WebFrame* frame,
1125 NavigationGesture gesture) {
[email protected]ed3fb032009-06-16 19:50:561126 WebDataSource* ds = frame->GetProvisionalDataSource();
1127 NavigationState* navigation_state = NavigationState::FromDataSource(ds);
1128
1129 navigation_state->set_start_load_time(Time::Now());
1130
1131 // Update the request time if WebKit has better knowledge of it.
1132 if (navigation_state->request_time().is_null()) {
[email protected]726985e22009-06-18 21:09:281133 double event_time = ds->triggeringEventTime();
[email protected]ed3fb032009-06-16 19:50:561134 if (event_time != 0.0)
1135 navigation_state->set_request_time(Time::FromDoubleT(event_time));
1136 }
1137
1138 bool is_top_most = !frame->GetParent();
1139 if (is_top_most) {
initial.commit09911bf2008-07-26 23:55:291140 navigation_gesture_ = gesture;
[email protected]266eb6f2008-09-30 23:56:501141
[email protected]77e09a92008-08-01 18:11:041142 // Make sure redirect tracking state is clear for the new load.
1143 completed_client_redirect_src_ = GURL();
[email protected]15d79e12009-08-02 19:23:451144 } else if (frame->GetParent()->IsLoading()) {
1145 // Take note of AUTO_SUBFRAME loads here, so that we can know how to
1146 // load an error page. See DidFailProvisionalLoadWithError.
1147 navigation_state->set_transition_type(PageTransition::AUTO_SUBFRAME);
[email protected]77e09a92008-08-01 18:11:041148 }
initial.commit09911bf2008-07-26 23:55:291149
1150 Send(new ViewHostMsg_DidStartProvisionalLoadForFrame(
[email protected]726985e22009-06-18 21:09:281151 routing_id_, is_top_most, ds->request().url()));
initial.commit09911bf2008-07-26 23:55:291152}
1153
1154bool RenderView::DidLoadResourceFromMemoryCache(WebView* webview,
[email protected]726985e22009-06-18 21:09:281155 const WebURLRequest& request,
1156 const WebURLResponse& response,
initial.commit09911bf2008-07-26 23:55:291157 WebFrame* frame) {
1158 // Let the browser know we loaded a resource from the memory cache. This
1159 // message is needed to display the correct SSL indicators.
1160 Send(new ViewHostMsg_DidLoadResourceFromMemoryCache(routing_id_,
[email protected]726985e22009-06-18 21:09:281161 request.url(), frame->GetSecurityOrigin(),
[email protected]ffc45862009-03-17 06:11:081162 frame->GetTop()->GetSecurityOrigin(),
[email protected]726985e22009-06-18 21:09:281163 response.securityInfo()));
initial.commit09911bf2008-07-26 23:55:291164
1165 return false;
1166}
1167
1168void RenderView::DidReceiveProvisionalLoadServerRedirect(WebView* webview,
1169 WebFrame* frame) {
1170 if (frame == webview->GetMainFrame()) {
1171 // Received a redirect on the main frame.
1172 WebDataSource* data_source =
1173 webview->GetMainFrame()->GetProvisionalDataSource();
1174 if (!data_source) {
1175 // Should only be invoked when we have a data source.
1176 NOTREACHED();
1177 return;
1178 }
[email protected]726985e22009-06-18 21:09:281179 std::vector<GURL> redirects;
1180 GetRedirectChain(data_source, &redirects);
initial.commit09911bf2008-07-26 23:55:291181 if (redirects.size() >= 2) {
1182 Send(new ViewHostMsg_DidRedirectProvisionalLoad(
1183 routing_id_, page_id_, redirects[redirects.size() - 2],
1184 redirects[redirects.size() - 1]));
1185 }
1186 }
1187}
1188
1189void RenderView::DidFailProvisionalLoadWithError(WebView* webview,
[email protected]726985e22009-06-18 21:09:281190 const WebURLError& error,
initial.commit09911bf2008-07-26 23:55:291191 WebFrame* frame) {
1192 // Notify the browser that we failed a provisional load with an error.
1193 //
1194 // Note: It is important this notification occur before DidStopLoading so the
1195 // SSL manager can react to the provisional load failure before being
1196 // notified the load stopped.
1197 //
1198 WebDataSource* ds = frame->GetProvisionalDataSource();
1199 DCHECK(ds);
1200
[email protected]726985e22009-06-18 21:09:281201 const WebURLRequest& failed_request = ds->request();
initial.commit09911bf2008-07-26 23:55:291202
1203 bool show_repost_interstitial =
[email protected]726985e22009-06-18 21:09:281204 (error.reason == net::ERR_CACHE_MISS &&
1205 EqualsASCII(failed_request.httpMethod(), "POST"));
initial.commit09911bf2008-07-26 23:55:291206 Send(new ViewHostMsg_DidFailProvisionalLoadWithError(
[email protected]726985e22009-06-18 21:09:281207 routing_id_, !frame->GetParent(),
1208 error.reason, error.unreachableURL,
initial.commit09911bf2008-07-26 23:55:291209 show_repost_interstitial));
1210
initial.commit09911bf2008-07-26 23:55:291211 // Don't display an error page if this is simply a cancelled load. Aside
1212 // from being dumb, WebCore doesn't expect it and it will cause a crash.
[email protected]726985e22009-06-18 21:09:281213 if (error.reason == net::ERR_ABORTED)
initial.commit09911bf2008-07-26 23:55:291214 return;
1215
[email protected]546ddd172009-06-25 00:25:011216 // Make sure we never show errors in view source mode.
1217 frame->SetInViewSourceMode(false);
1218
[email protected]15d79e12009-08-02 19:23:451219 NavigationState* navigation_state = NavigationState::FromDataSource(ds);
1220
initial.commit09911bf2008-07-26 23:55:291221 // If this is a failed back/forward/reload navigation, then we need to do a
1222 // 'replace' load. This is necessary to avoid messing up session history.
1223 // Otherwise, we do a normal load, which simulates a 'go' navigation as far
1224 // as session history is concerned.
[email protected]15d79e12009-08-02 19:23:451225 //
1226 // AUTO_SUBFRAME loads should always be treated as loads that do not advance
1227 // the page id.
1228 //
1229 bool replace =
1230 navigation_state->pending_page_id() != -1 ||
1231 navigation_state->transition_type() == PageTransition::AUTO_SUBFRAME;
initial.commit09911bf2008-07-26 23:55:291232
[email protected]15d79e12009-08-02 19:23:451233 // If we failed on a browser initiated request, then make sure that our error
1234 // page load is regarded as the same browser initiated request.
1235 if (!navigation_state->is_content_initiated()) {
1236 pending_navigation_state_.reset(NavigationState::CreateBrowserInitiated(
1237 navigation_state->pending_page_id(),
1238 navigation_state->transition_type(),
1239 navigation_state->request_time()));
initial.commit09911bf2008-07-26 23:55:291240 }
[email protected]5df266ac2008-10-15 19:50:131241
[email protected]15d79e12009-08-02 19:23:451242 // Provide the user with a more helpful error page?
1243 if (MaybeLoadAlternateErrorPage(frame, error, replace))
1244 return;
1245
[email protected]be645db2009-02-06 20:36:331246 // Fallback to a local error page.
[email protected]726985e22009-06-18 21:09:281247 LoadNavigationErrorPage(frame, failed_request, error, std::string(),
[email protected]5df266ac2008-10-15 19:50:131248 replace);
initial.commit09911bf2008-07-26 23:55:291249}
1250
1251void RenderView::LoadNavigationErrorPage(WebFrame* frame,
[email protected]726985e22009-06-18 21:09:281252 const WebURLRequest& failed_request,
1253 const WebURLError& error,
initial.commit09911bf2008-07-26 23:55:291254 const std::string& html,
1255 bool replace) {
[email protected]726985e22009-06-18 21:09:281256 GURL failed_url = error.unreachableURL;
initial.commit09911bf2008-07-26 23:55:291257
1258 std::string alt_html;
1259 if (html.empty()) {
1260 // Use a local error page.
1261 int resource_id;
1262 DictionaryValue error_strings;
[email protected]726985e22009-06-18 21:09:281263 if (error.reason == net::ERR_CACHE_MISS &&
1264 EqualsASCII(failed_request.httpMethod(), "POST")) {
initial.commit09911bf2008-07-26 23:55:291265 GetFormRepostErrorValues(failed_url, &error_strings);
1266 resource_id = IDR_ERROR_NO_DETAILS_HTML;
1267 } else {
1268 GetLocalizedErrorValues(error, &error_strings);
1269 resource_id = IDR_NET_ERROR_HTML;
1270 }
[email protected]8e50b602009-03-03 22:59:431271 error_strings.SetString(L"textdirection",
1272 (l10n_util::GetTextDirection() == l10n_util::RIGHT_TO_LEFT) ?
1273 L"rtl" : L"ltr");
initial.commit09911bf2008-07-26 23:55:291274
1275 alt_html = GetAltHTMLForTemplate(error_strings, resource_id);
1276 } else {
1277 alt_html = html;
1278 }
1279
[email protected]e6f546c32009-07-01 17:12:551280 frame->LoadHTMLString(alt_html,
1281 GURL(kUnreachableWebDataURL),
1282 failed_url,
1283 replace);
initial.commit09911bf2008-07-26 23:55:291284}
1285
1286void RenderView::DidCommitLoadForFrame(WebView *webview, WebFrame* frame,
1287 bool is_new_navigation) {
[email protected]daa8c58e2009-06-15 17:21:101288 NavigationState* navigation_state =
1289 NavigationState::FromDataSource(frame->GetDataSource());
initial.commit09911bf2008-07-26 23:55:291290
[email protected]a2f6bc112009-06-27 16:27:251291 navigation_state->set_commit_load_time(Time::Now());
initial.commit09911bf2008-07-26 23:55:291292 if (is_new_navigation) {
1293 // When we perform a new navigation, we need to update the previous session
1294 // history entry with state for the page we are leaving.
1295 UpdateSessionHistory(frame);
1296
1297 // We bump our Page ID to correspond with the new session history entry.
1298 page_id_ = next_page_id_++;
1299
1300 MessageLoop::current()->PostDelayedTask(FROM_HERE,
1301 method_factory_.NewRunnableMethod(&RenderView::CapturePageInfo,
1302 page_id_, true),
1303 kDelayForForcedCaptureMs);
1304 } else {
[email protected]15d79e12009-08-02 19:23:451305 // Inspect the navigation_state on this frame to see if the navigation
1306 // corresponds to a session history navigation... Note: |frame| may or
1307 // may not be the toplevel frame, but for the case of capturing session
1308 // history, the first committed frame suffices. We keep track of whether
1309 // we've seen this commit before so that only capture session history once
1310 // per navigation.
[email protected]f4d34b52008-11-24 23:05:011311 //
1312 // Note that we need to check if the page ID changed. In the case of a
1313 // reload, the page ID doesn't change, and UpdateSessionHistory gets the
1314 // previous URL and the current page ID, which would be wrong.
[email protected]15d79e12009-08-02 19:23:451315 if (navigation_state->pending_page_id() != -1 &&
1316 navigation_state->pending_page_id() != page_id_ &&
1317 !navigation_state->request_committed()) {
initial.commit09911bf2008-07-26 23:55:291318 // This is a successful session history navigation!
1319 UpdateSessionHistory(frame);
[email protected]77f17a82009-05-21 04:42:541320 page_id_ = navigation_state->pending_page_id();
initial.commit09911bf2008-07-26 23:55:291321 }
1322 }
1323
1324 // Remember that we've already processed this request, so we don't update
1325 // the session history again. We do this regardless of whether this is
1326 // a session history navigation, because if we attempted a session history
1327 // navigation without valid HistoryItem state, WebCore will think it is a
1328 // new navigation.
[email protected]daa8c58e2009-06-15 17:21:101329 navigation_state->set_request_committed(true);
initial.commit09911bf2008-07-26 23:55:291330
1331 UpdateURL(frame);
1332
1333 // If this committed load was initiated by a client redirect, we're
1334 // at the last stop now, so clear it.
1335 completed_client_redirect_src_ = GURL();
1336
1337 // Check whether we have new encoding name.
1338 UpdateEncoding(frame, webview->GetMainFrameEncodingName());
1339}
1340
1341void RenderView::DidReceiveTitle(WebView* webview,
1342 const std::wstring& title,
1343 WebFrame* frame) {
1344 UpdateTitle(frame, title);
1345
1346 // Also check whether we have new encoding name.
1347 UpdateEncoding(frame, webview->GetMainFrameEncodingName());
1348}
1349
1350void RenderView::DidFinishLoadForFrame(WebView* webview, WebFrame* frame) {
[email protected]a2f6bc112009-06-27 16:27:251351 WebDataSource* ds = frame->GetDataSource();
1352 NavigationState* navigation_state = NavigationState::FromDataSource(ds);
[email protected]78a3a6f2009-07-02 16:15:011353 DCHECK(navigation_state);
1354 navigation_state->set_finish_load_time(Time::Now());
initial.commit09911bf2008-07-26 23:55:291355}
1356
1357void RenderView::DidFailLoadWithError(WebView* webview,
[email protected]726985e22009-06-18 21:09:281358 const WebURLError& error,
initial.commit09911bf2008-07-26 23:55:291359 WebFrame* frame) {
[email protected]546ddd172009-06-25 00:25:011360 // Currently this function is empty. When you implement something here and it
1361 // will display any error messages in HTML, please make sure to call
1362 // frame->SetInViewSourceMode(false) not to show them in view source mode.
initial.commit09911bf2008-07-26 23:55:291363}
1364
1365void RenderView::DidFinishDocumentLoadForFrame(WebView* webview,
1366 WebFrame* frame) {
[email protected]a2f6bc112009-06-27 16:27:251367 WebDataSource* ds = frame->GetDataSource();
1368 NavigationState* navigation_state = NavigationState::FromDataSource(ds);
[email protected]78a3a6f2009-07-02 16:15:011369 DCHECK(navigation_state);
1370 navigation_state->set_finish_document_load_time(Time::Now());
[email protected]a2f6bc112009-06-27 16:27:251371
[email protected]09b8f82f2009-06-16 20:22:111372 Send(new ViewHostMsg_DocumentLoadedInFrame(routing_id_));
1373
[email protected]daa8c58e2009-06-15 17:21:101374 // The document has now been fully loaded. Scan for password forms to be
1375 // sent up to the browser.
1376 SendPasswordForms(frame);
1377
initial.commit09911bf2008-07-26 23:55:291378 // Check whether we have new encoding name.
1379 UpdateEncoding(frame, webview->GetMainFrameEncodingName());
[email protected]1e0f70402008-10-16 23:57:471380
[email protected]8930d472009-02-21 08:05:281381 if (RenderThread::current()) // Will be NULL during unit tests.
1382 RenderThread::current()->user_script_slave()->InjectScripts(
[email protected]0afe8272009-02-14 04:15:161383 frame, UserScript::DOCUMENT_END);
initial.commit09911bf2008-07-26 23:55:291384}
1385
1386void RenderView::DidHandleOnloadEventsForFrame(WebView* webview,
1387 WebFrame* frame) {
1388}
1389
1390void RenderView::DidChangeLocationWithinPageForFrame(WebView* webview,
1391 WebFrame* frame,
1392 bool is_new_navigation) {
[email protected]77f17a82009-05-21 04:42:541393 // If this was a reference fragment navigation that we initiated, then we
1394 // could end up having a non-null pending navigation state. We just need to
1395 // update the ExtraData on the datasource so that others who read the
1396 // ExtraData will get the new NavigationState. Similarly, if we did not
[email protected]daa8c58e2009-06-15 17:21:101397 // initiate this navigation, then we need to take care to reset any pre-
1398 // existing navigation state to a content-initiated navigation state.
1399 // DidCreateDataSource conveniently takes care of this for us.
1400 DidCreateDataSource(frame, frame->GetDataSource());
[email protected]77f17a82009-05-21 04:42:541401
initial.commit09911bf2008-07-26 23:55:291402 DidCommitLoadForFrame(webview, frame, is_new_navigation);
[email protected]77f17a82009-05-21 04:42:541403
[email protected]9d806f52009-03-12 22:50:541404 const string16& title =
[email protected]726985e22009-06-18 21:09:281405 webview->GetMainFrame()->GetDataSource()->pageTitle();
[email protected]9d806f52009-03-12 22:50:541406 UpdateTitle(frame, UTF16ToWideHack(title));
initial.commit09911bf2008-07-26 23:55:291407}
1408
initial.commit09911bf2008-07-26 23:55:291409void RenderView::DidCompleteClientRedirect(WebView* webview,
1410 WebFrame* frame,
1411 const GURL& source) {
1412 if (webview->GetMainFrame() == frame)
1413 completed_client_redirect_src_ = source;
1414}
1415
[email protected]7a9b51f2009-06-29 21:28:291416void RenderView::WillCloseFrame(WebView* webview, WebFrame* frame) {
1417 if (!frame->GetParent()) {
1418 const GURL& url = frame->GetURL();
1419 if (url.SchemeIs("http") || url.SchemeIs("https"))
1420 DumpLoadHistograms();
1421 }
1422}
1423
[email protected]daa8c58e2009-06-15 17:21:101424void RenderView::WillSubmitForm(WebView* webview, WebFrame* frame,
1425 const WebForm& form) {
1426 NavigationState* navigation_state =
1427 NavigationState::FromDataSource(frame->GetProvisionalDataSource());
1428
1429 if (navigation_state->transition_type() == PageTransition::LINK)
1430 navigation_state->set_transition_type(PageTransition::FORM_SUBMIT);
1431
1432 // Save these to be processed when the ensuing navigation is committed.
1433 navigation_state->set_searchable_form_data(
1434 SearchableFormData::Create(form));
1435 navigation_state->set_password_form_data(
1436 PasswordFormDomManager::CreatePasswordForm(form));
1437
1438 if (form.isAutoCompleteEnabled()) {
1439 scoped_ptr<AutofillForm> autofill_form(AutofillForm::Create(form));
1440 if (autofill_form.get())
1441 Send(new ViewHostMsg_AutofillFormSubmitted(routing_id_, *autofill_form));
1442 }
1443}
1444
[email protected]5b35a6b2009-03-16 19:58:081445void RenderView::WillSendRequest(WebView* webview,
1446 uint32 identifier,
[email protected]726985e22009-06-18 21:09:281447 WebURLRequest* request) {
1448 request->setRequestorID(routing_id_);
[email protected]5b35a6b2009-03-16 19:58:081449}
1450
initial.commit09911bf2008-07-26 23:55:291451void RenderView::BindDOMAutomationController(WebFrame* webframe) {
1452 dom_automation_controller_.set_message_sender(this);
1453 dom_automation_controller_.set_routing_id(routing_id_);
1454 dom_automation_controller_.BindToJavascript(webframe,
1455 L"domAutomationController");
1456}
1457
1458void RenderView::WindowObjectCleared(WebFrame* webframe) {
[email protected]81e63782009-02-27 19:35:091459 if (BindingsPolicy::is_dom_automation_enabled(enabled_bindings_))
initial.commit09911bf2008-07-26 23:55:291460 BindDOMAutomationController(webframe);
[email protected]81e63782009-02-27 19:35:091461 if (BindingsPolicy::is_dom_ui_enabled(enabled_bindings_)) {
initial.commit09911bf2008-07-26 23:55:291462 dom_ui_bindings_.set_message_sender(this);
1463 dom_ui_bindings_.set_routing_id(routing_id_);
1464 dom_ui_bindings_.BindToJavascript(webframe, L"chrome");
1465 }
[email protected]81e63782009-02-27 19:35:091466 if (BindingsPolicy::is_external_host_enabled(enabled_bindings_)) {
[email protected]18cb2572008-08-21 20:34:451467 external_host_bindings_.set_message_sender(this);
1468 external_host_bindings_.set_routing_id(routing_id_);
1469 external_host_bindings_.BindToJavascript(webframe, L"externalHost");
1470 }
initial.commit09911bf2008-07-26 23:55:291471}
1472
[email protected]0afe8272009-02-14 04:15:161473void RenderView::DocumentElementAvailable(WebFrame* frame) {
[email protected]4b8323b2009-04-17 18:45:441474 // TODO(mpcomplete): remove this before Chrome extensions ship.
1475 // HACK. This is a temporary workaround to allow cross-origin XHR for Chrome
1476 // extensions. It grants full access to every origin, when we really want
1477 // to be able to restrict them more specifically.
[email protected]e95ad332009-08-03 19:44:251478 GURL url = frame->GetURL();
1479 if (url.SchemeIs(chrome::kExtensionScheme))
[email protected]4b8323b2009-04-17 18:45:441480 frame->GrantUniversalAccess();
[email protected]d959ce22009-04-15 21:03:421481
[email protected]8930d472009-02-21 08:05:281482 if (RenderThread::current()) // Will be NULL during unit tests.
1483 RenderThread::current()->user_script_slave()->InjectScripts(
[email protected]0afe8272009-02-14 04:15:161484 frame, UserScript::DOCUMENT_START);
[email protected]e95ad332009-08-03 19:44:251485
1486 // Notify the browser about non-blank documents loading in the top frame.
1487 if (url.is_valid() && url.spec() != "about:blank") {
1488 if (frame == webview()->GetMainFrame())
1489 Send(new ViewHostMsg_DocumentAvailableInMainFrame(routing_id_));
1490 }
[email protected]0afe8272009-02-14 04:15:161491}
1492
[email protected]b6ce15972009-07-14 22:14:011493void RenderView::DidCreateScriptContextForFrame(WebFrame* webframe) {
[email protected]7120f132009-07-20 21:05:371494 EventBindings::HandleContextCreated(webframe, false);
[email protected]f816c012009-06-26 21:48:321495}
1496
[email protected]b6ce15972009-07-14 22:14:011497void RenderView::DidDestroyScriptContextForFrame(WebFrame* webframe) {
[email protected]f816c012009-06-26 21:48:321498 EventBindings::HandleContextDestroyed(webframe);
1499}
1500
[email protected]b6ce15972009-07-14 22:14:011501void RenderView::DidCreateIsolatedScriptContext(WebFrame* webframe) {
[email protected]7120f132009-07-20 21:05:371502 EventBindings::HandleContextCreated(webframe, true);
[email protected]b6ce15972009-07-14 22:14:011503}
1504
[email protected]4873c7d2009-07-16 06:36:281505WebNavigationPolicy RenderView::PolicyForNavigationAction(
initial.commit09911bf2008-07-26 23:55:291506 WebView* webview,
1507 WebFrame* frame,
[email protected]726985e22009-06-18 21:09:281508 const WebURLRequest& request,
initial.commit09911bf2008-07-26 23:55:291509 WebNavigationType type,
[email protected]4873c7d2009-07-16 06:36:281510 WebNavigationPolicy default_policy,
initial.commit09911bf2008-07-26 23:55:291511 bool is_redirect) {
[email protected]5f450e52009-07-28 13:28:111512 // Webkit is asking whether to navigate to a new URL.
1513 // This is fine normally, except if we're showing UI from one security
1514 // context and they're trying to navigate to a different context.
1515 const GURL& url = request.url();
1516
1517 // If the browser is interested, then give it a chance to look at top level
1518 // navigations
1519 if (renderer_preferences_.browser_handles_top_level_requests &&
1520 // Only send once.
1521 last_top_level_navigation_page_id_ != page_id_ &&
1522 // Not interested in reloads.
1523 type != WebKit::WebNavigationTypeReload &&
1524 // Must be a top level frame.
1525 frame->GetParent() == NULL) {
1526 // Skip if navigation is on the same page (using '#').
1527 GURL frame_origin = frame->GetURL().GetOrigin();
1528 if (url.GetOrigin() != frame_origin || url.ref().empty()) {
1529 last_top_level_navigation_page_id_ = page_id_;
1530 OpenURL(webview, url, GURL(), default_policy);
1531 return WebKit::WebNavigationPolicyIgnore; // Suppress the load here.
1532 }
1533 }
1534
[email protected]daa8c58e2009-06-15 17:21:101535 // A content initiated navigation may have originated from a link-click,
1536 // script, drag-n-drop operation, etc.
[email protected]77f17a82009-05-21 04:42:541537 bool is_content_initiated =
[email protected]daa8c58e2009-06-15 17:21:101538 NavigationState::FromDataSource(frame->GetProvisionalDataSource())->
1539 is_content_initiated();
[email protected]77f17a82009-05-21 04:42:541540
initial.commit09911bf2008-07-26 23:55:291541 // We only care about navigations that are within the current tab (as opposed
1542 // to, for example, opening a new window).
1543 // But we sometimes navigate to about:blank to clear a tab, and we want to
1544 // still allow that.
[email protected]4873c7d2009-07-16 06:36:281545 if (default_policy == WebKit::WebNavigationPolicyCurrentTab &&
1546 is_content_initiated && frame->GetParent() == NULL &&
1547 !url.SchemeIs(chrome::kAboutScheme)) {
[email protected]77f17a82009-05-21 04:42:541548 // When we received such unsolicited navigations, we sometimes want to
1549 // punt them up to the browser to handle.
1550 if (BindingsPolicy::is_dom_ui_enabled(enabled_bindings_) ||
[email protected]1e5f53a2009-06-15 23:48:041551 BindingsPolicy::is_extension_enabled(enabled_bindings_) ||
[email protected]77f17a82009-05-21 04:42:541552 frame->GetInViewSourceMode() ||
[email protected]a2176742009-07-03 12:13:481553 url.SchemeIs(chrome::kViewSourceScheme) ||
1554 url.SchemeIs(chrome::kPrintScheme)) {
[email protected]4873c7d2009-07-16 06:36:281555 OpenURL(webview, url, GURL(), default_policy);
1556 return WebKit::WebNavigationPolicyIgnore; // Suppress the load here.
initial.commit09911bf2008-07-26 23:55:291557 }
1558 }
1559
1560 // Detect when a page is "forking" a new tab that can be safely rendered in
1561 // its own process. This is done by sites like Gmail that try to open links
1562 // in new windows without script connections back to the original page. We
1563 // treat such cases as browser navigations (in which we will create a new
1564 // renderer for a cross-site navigation), rather than WebKit navigations.
1565 //
1566 // We use the following heuristic to decide whether to fork a new page in its
1567 // own process:
1568 // The parent page must open a new tab to about:blank, set the new tab's
1569 // window.opener to null, and then redirect the tab to a cross-site URL using
1570 // JavaScript.
1571 bool is_fork =
1572 // Must start from a tab showing about:blank, which is later redirected.
[email protected]6aad4bd2009-02-26 22:55:171573 frame->GetURL() == GURL("about:blank") &&
initial.commit09911bf2008-07-26 23:55:291574 // Must be the first real navigation of the tab.
1575 GetHistoryBackListCount() < 1 &&
1576 GetHistoryForwardListCount() < 1 &&
1577 // The parent page must have set the child's window.opener to null before
1578 // redirecting to the desired URL.
1579 frame->GetOpener() == NULL &&
1580 // Must be a top-level frame.
1581 frame->GetParent() == NULL &&
[email protected]77f17a82009-05-21 04:42:541582 // Must not have issued the request from this page.
1583 is_content_initiated &&
initial.commit09911bf2008-07-26 23:55:291584 // Must be targeted at the current tab.
[email protected]4873c7d2009-07-16 06:36:281585 default_policy == WebKit::WebNavigationPolicyCurrentTab &&
initial.commit09911bf2008-07-26 23:55:291586 // Must be a JavaScript navigation, which appears as "other".
[email protected]726985e22009-06-18 21:09:281587 type == WebKit::WebNavigationTypeOther;
initial.commit09911bf2008-07-26 23:55:291588 if (is_fork) {
1589 // Open the URL via the browser, not via WebKit.
[email protected]4873c7d2009-07-16 06:36:281590 OpenURL(webview, url, GURL(), default_policy);
1591 return WebKit::WebNavigationPolicyIgnore;
initial.commit09911bf2008-07-26 23:55:291592 }
1593
[email protected]4873c7d2009-07-16 06:36:281594 return default_policy;
initial.commit09911bf2008-07-26 23:55:291595}
1596
[email protected]a455d3812009-03-05 20:18:071597void RenderView::RunJavaScriptAlert(WebFrame* webframe,
initial.commit09911bf2008-07-26 23:55:291598 const std::wstring& message) {
[email protected]478ff2ed2009-04-21 23:49:181599 RunJavaScriptMessage(MessageBoxFlags::kIsJavascriptAlert,
initial.commit09911bf2008-07-26 23:55:291600 message,
1601 std::wstring(),
[email protected]a455d3812009-03-05 20:18:071602 webframe->GetURL(),
initial.commit09911bf2008-07-26 23:55:291603 NULL);
1604}
1605
[email protected]a455d3812009-03-05 20:18:071606bool RenderView::RunJavaScriptConfirm(WebFrame* webframe,
initial.commit09911bf2008-07-26 23:55:291607 const std::wstring& message) {
[email protected]478ff2ed2009-04-21 23:49:181608 return RunJavaScriptMessage(MessageBoxFlags::kIsJavascriptConfirm,
initial.commit09911bf2008-07-26 23:55:291609 message,
1610 std::wstring(),
[email protected]a455d3812009-03-05 20:18:071611 webframe->GetURL(),
initial.commit09911bf2008-07-26 23:55:291612 NULL);
1613}
1614
[email protected]a455d3812009-03-05 20:18:071615bool RenderView::RunJavaScriptPrompt(WebFrame* webframe,
initial.commit09911bf2008-07-26 23:55:291616 const std::wstring& message,
1617 const std::wstring& default_value,
1618 std::wstring* result) {
[email protected]478ff2ed2009-04-21 23:49:181619 return RunJavaScriptMessage(MessageBoxFlags::kIsJavascriptPrompt,
initial.commit09911bf2008-07-26 23:55:291620 message,
1621 default_value,
[email protected]a455d3812009-03-05 20:18:071622 webframe->GetURL(),
initial.commit09911bf2008-07-26 23:55:291623 result);
1624}
1625
1626bool RenderView::RunJavaScriptMessage(int type,
1627 const std::wstring& message,
1628 const std::wstring& default_value,
[email protected]a455d3812009-03-05 20:18:071629 const GURL& frame_url,
initial.commit09911bf2008-07-26 23:55:291630 std::wstring* result) {
1631 bool success = false;
1632 std::wstring result_temp;
1633 if (!result)
1634 result = &result_temp;
1635 IPC::SyncMessage* msg = new ViewHostMsg_RunJavaScriptMessage(
[email protected]a455d3812009-03-05 20:18:071636 routing_id_, message, default_value, frame_url, type, &success, result);
initial.commit09911bf2008-07-26 23:55:291637
[email protected]1c4947f2009-01-15 22:25:111638 msg->set_pump_messages_event(modal_dialog_event_.get());
initial.commit09911bf2008-07-26 23:55:291639 Send(msg);
1640
1641 return success;
1642}
1643
1644void RenderView::AddGURLSearchProvider(const GURL& osd_url, bool autodetected) {
1645 if (!osd_url.is_empty())
1646 Send(new ViewHostMsg_PageHasOSDD(routing_id_, page_id_, osd_url,
1647 autodetected));
1648}
1649
[email protected]a455d3812009-03-05 20:18:071650bool RenderView::RunBeforeUnloadConfirm(WebFrame* webframe,
initial.commit09911bf2008-07-26 23:55:291651 const std::wstring& message) {
1652 bool success = false;
1653 // This is an ignored return value, but is included so we can accept the same
1654 // response as RunJavaScriptMessage.
1655 std::wstring ignored_result;
1656 IPC::SyncMessage* msg = new ViewHostMsg_RunBeforeUnloadConfirm(
[email protected]a455d3812009-03-05 20:18:071657 routing_id_, webframe->GetURL(), message, &success, &ignored_result);
initial.commit09911bf2008-07-26 23:55:291658
[email protected]1c4947f2009-01-15 22:25:111659 msg->set_pump_messages_event(modal_dialog_event_.get());
initial.commit09911bf2008-07-26 23:55:291660 Send(msg);
1661
1662 return success;
1663}
1664
[email protected]0ebf3872008-11-07 21:35:031665void RenderView::QueryFormFieldAutofill(const std::wstring& field_name,
1666 const std::wstring& text,
1667 int64 node_id) {
1668 static int message_id_counter = 0;
1669 form_field_autofill_request_id_ = message_id_counter++;
1670 Send(new ViewHostMsg_QueryFormFieldAutofill(routing_id_,
1671 field_name, text,
1672 node_id,
1673 form_field_autofill_request_id_));
1674}
1675
[email protected]4d2b6fb2009-03-20 22:28:171676void RenderView::RemoveStoredAutofillEntry(const std::wstring& name,
1677 const std::wstring& value) {
1678 Send(new ViewHostMsg_RemoveAutofillEntry(routing_id_, name, value));
1679}
1680
[email protected]0ebf3872008-11-07 21:35:031681void RenderView::OnReceivedAutofillSuggestions(
1682 int64 node_id,
1683 int request_id,
[email protected]8d0f15c2008-11-11 01:01:091684 const std::vector<std::wstring>& suggestions,
[email protected]0ebf3872008-11-07 21:35:031685 int default_suggestion_index) {
1686 if (!webview() || request_id != form_field_autofill_request_id_)
1687 return;
1688
1689 webview()->AutofillSuggestionsForNode(node_id, suggestions,
1690 default_suggestion_index);
1691}
1692
[email protected]2c4410d2009-05-06 23:46:221693void RenderView::OnPopupNotificationVisibilityChanged(bool visible) {
[email protected]634a6f92008-12-01 21:39:311694 popup_notification_visible_ = visible;
1695}
1696
initial.commit09911bf2008-07-26 23:55:291697void RenderView::ShowModalHTMLDialog(const GURL& url, int width, int height,
1698 const std::string& json_arguments,
1699 std::string* json_retval) {
1700 IPC::SyncMessage* msg = new ViewHostMsg_ShowModalHTMLDialog(
1701 routing_id_, url, width, height, json_arguments, json_retval);
1702
[email protected]1c4947f2009-01-15 22:25:111703 msg->set_pump_messages_event(modal_dialog_event_.get());
initial.commit09911bf2008-07-26 23:55:291704 Send(msg);
1705}
1706
1707uint32 RenderView::GetCPBrowsingContext() {
1708 uint32 context = 0;
1709 Send(new ViewHostMsg_GetCPBrowsingContext(&context));
1710 return context;
1711}
1712
1713// Tell the browser to display a destination link.
1714void RenderView::UpdateTargetURL(WebView* webview, const GURL& url) {
1715 if (url != target_url_) {
1716 if (target_url_status_ == TARGET_INFLIGHT ||
1717 target_url_status_ == TARGET_PENDING) {
1718 // If we have a request in-flight, save the URL to be sent when we
1719 // receive an ACK to the in-flight request. We can happily overwrite
1720 // any existing pending sends.
1721 pending_target_url_ = url;
1722 target_url_status_ = TARGET_PENDING;
1723 } else {
1724 Send(new ViewHostMsg_UpdateTargetURL(routing_id_, page_id_, url));
1725 target_url_ = url;
1726 target_url_status_ = TARGET_INFLIGHT;
1727 }
1728 }
1729}
1730
[email protected]b62d1a8c2009-01-13 23:54:571731void RenderView::RunFileChooser(bool multi_select,
[email protected]b949f1112009-04-12 20:03:081732 const string16& title,
1733 const FilePath& default_filename,
initial.commit09911bf2008-07-26 23:55:291734 WebFileChooserCallback* file_chooser) {
1735 if (file_chooser_.get()) {
1736 // TODO(brettw): bug 1235154: This should be a synchronous message to deal
1737 // with the fact that web pages can programatically trigger this. With the
1738 // asnychronous messages, we can get an additional call when one is pending,
1739 // which this test is for. For now, we just ignore the additional file
1740 // chooser request. WebKit doesn't do anything to expect the callback, so
1741 // we can just ignore calling it.
1742 delete file_chooser;
1743 return;
1744 }
1745 file_chooser_.reset(file_chooser);
[email protected]b62d1a8c2009-01-13 23:54:571746 Send(new ViewHostMsg_RunFileChooser(routing_id_, multi_select, title,
[email protected]b949f1112009-04-12 20:03:081747 default_filename));
initial.commit09911bf2008-07-26 23:55:291748}
1749
1750void RenderView::AddMessageToConsole(WebView* webview,
1751 const std::wstring& message,
1752 unsigned int line_no,
1753 const std::wstring& source_id) {
1754 Send(new ViewHostMsg_AddMessageToConsole(routing_id_, message,
1755 static_cast<int32>(line_no),
1756 source_id));
1757}
1758
1759void RenderView::AddSearchProvider(const std::string& url) {
1760 AddGURLSearchProvider(GURL(url),
1761 false); // not autodetected
1762}
1763
[email protected]c88a70fe2009-05-05 20:00:221764WebView* RenderView::CreateWebView(WebView* webview,
1765 bool user_gesture,
1766 const GURL& creator_url) {
[email protected]0aa55312008-10-17 21:53:081767 // Check to make sure we aren't overloading on popups.
1768 if (shared_popup_counter_->data > kMaximumNumberOfUnacknowledgedPopups)
1769 return NULL;
1770
[email protected]634a6f92008-12-01 21:39:311771 // This window can't be closed from a window.close() call until we receive a
1772 // message from the Browser process explicitly allowing it.
1773 popup_notification_visible_ = true;
1774
initial.commit09911bf2008-07-26 23:55:291775 int32 routing_id = MSG_ROUTING_NONE;
[email protected]6c8afae52009-01-22 02:24:571776
[email protected]18bcc3c2009-01-27 21:39:151777 ModalDialogEvent modal_dialog_event;
[email protected]6c8afae52009-01-22 02:24:571778 render_thread_->Send(
[email protected]15787f8f2008-10-17 15:29:031779 new ViewHostMsg_CreateWindow(routing_id_, user_gesture, &routing_id,
1780 &modal_dialog_event));
initial.commit09911bf2008-07-26 23:55:291781 if (routing_id == MSG_ROUTING_NONE) {
initial.commit09911bf2008-07-26 23:55:291782 return NULL;
1783 }
1784
1785 // The WebView holds a reference to this new RenderView
[email protected]80d96fa2009-06-10 22:34:511786 const WebPreferences& web_prefs = webview->GetPreferences();
[email protected]6c8afae52009-01-22 02:24:571787 base::WaitableEvent* waitable_event = new base::WaitableEvent
1788#if defined(OS_WIN)
[email protected]18bcc3c2009-01-27 21:39:151789 (modal_dialog_event.event);
[email protected]6c8afae52009-01-22 02:24:571790#else
1791 (true, false);
1792#endif
[email protected]81a34412009-01-05 19:17:241793 RenderView* view = RenderView::Create(render_thread_,
[email protected]1c4947f2009-01-15 22:25:111794 NULL, waitable_event, routing_id_,
[email protected]80d96fa2009-06-10 22:34:511795 renderer_preferences_, web_prefs,
1796 shared_popup_counter_, routing_id);
[email protected]ed4bf2d2009-05-05 00:10:061797 view->opened_by_user_gesture_ = user_gesture;
[email protected]c88a70fe2009-05-05 20:00:221798 view->creator_url_ = creator_url;
initial.commit09911bf2008-07-26 23:55:291799
1800 // Copy over the alternate error page URL so we can have alt error pages in
1801 // the new render view (we don't need the browser to send the URL back down).
1802 view->alternate_error_page_url_ = alternate_error_page_url_;
1803
1804 return view->webview();
1805}
1806
[email protected]0ebf3872008-11-07 21:35:031807WebWidget* RenderView::CreatePopupWidget(WebView* webview,
[email protected]cfd727f2009-01-09 20:21:111808 bool activatable) {
[email protected]8085dbc82008-09-26 22:53:441809 RenderWidget* widget = RenderWidget::Create(routing_id_,
[email protected]81a34412009-01-05 19:17:241810 render_thread_,
[email protected]cfd727f2009-01-09 20:21:111811 activatable);
initial.commit09911bf2008-07-26 23:55:291812 return widget->webwidget();
1813}
1814
[email protected]88efb7ec2009-07-14 16:32:591815WebWidget* RenderView::CreatePopupWidgetWithInfo(WebView* webview,
1816 const WebPopupMenuInfo& info) {
1817 RenderWidget* widget = RenderWidget::Create(routing_id_,
1818 render_thread_,
1819 true);
1820 widget->ConfigureAsExternalPopupMenu(info);
1821 return widget->webwidget();
1822}
1823
initial.commit09911bf2008-07-26 23:55:291824WebPluginDelegate* RenderView::CreatePluginDelegate(
1825 WebView* webview,
1826 const GURL& url,
1827 const std::string& mime_type,
1828 const std::string& clsid,
1829 std::string* actual_mime_type) {
[email protected]6273e2e72009-04-17 00:13:551830 if (!PluginChannelHost::IsListening())
1831 return NULL;
1832
[email protected]9dd9e8382009-06-05 18:23:211833 GURL policy_url;
1834 if (webview->GetMainFrame())
1835 policy_url = webview->GetMainFrame()->GetURL();
1836
[email protected]f5cdaff2009-05-19 21:01:471837 FilePath path;
1838 render_thread_->Send(
[email protected]9dd9e8382009-06-05 18:23:211839 new ViewHostMsg_GetPluginPath(url, policy_url, mime_type, clsid, &path,
[email protected]f5cdaff2009-05-19 21:01:471840 actual_mime_type));
1841 if (path.value().empty())
1842 return NULL;
1843
1844 std::string mime_type_to_use;
1845 if (!actual_mime_type->empty())
1846 mime_type_to_use = *actual_mime_type;
1847 else
1848 mime_type_to_use = mime_type;
1849
[email protected]88a1fb47a2009-03-13 00:18:061850 if (RenderProcess::current()->in_process_plugins()) {
[email protected]6bf1a812009-07-11 01:57:281851#if defined(OS_WIN) // In-proc plugins aren't supported on Linux or Mac.
[email protected]b94d3322009-02-12 19:49:041852 return WebPluginDelegate::Create(path,
1853 mime_type_to_use,
1854 gfx::NativeViewFromId(host_window_));
[email protected]6bf1a812009-07-11 01:57:281855#else
1856 NOTIMPLEMENTED();
1857 return NULL;
[email protected]ffeba6d2009-04-27 20:43:261858#endif
[email protected]6bf1a812009-07-11 01:57:281859 }
initial.commit09911bf2008-07-26 23:55:291860
1861 WebPluginDelegateProxy* proxy =
[email protected]f5cdaff2009-05-19 21:01:471862 WebPluginDelegateProxy::Create(url, mime_type_to_use, clsid, this);
initial.commit09911bf2008-07-26 23:55:291863 if (!proxy)
1864 return NULL;
1865
initial.commit09911bf2008-07-26 23:55:291866 plugin_delegates_.push_back(proxy);
1867
1868 return proxy;
1869}
1870
[email protected]4e6be3f2009-05-07 02:24:441871WebKit::WebMediaPlayer* RenderView::CreateWebMediaPlayer(
1872 WebKit::WebMediaPlayerClient* client) {
[email protected]add51772009-06-11 18:25:171873 scoped_refptr<media::FilterFactoryCollection> factory =
1874 new media::FilterFactoryCollection();
1875 // Add in any custom filter factories first.
1876 const CommandLine* cmd_line = CommandLine::ForCurrentProcess();
1877 if (!cmd_line->HasSwitch(switches::kDisableAudio)) {
1878 // Add the chrome specific audio renderer.
1879 factory->AddFactory(
1880 AudioRendererImpl::CreateFactory(audio_message_filter()));
1881 }
[email protected]8380c092009-06-25 17:45:511882
1883 // TODO(hclam): obtain the following parameters from |client|.
1884 webkit_glue::MediaResourceLoaderBridgeFactory* bridge_factory =
1885 new webkit_glue::MediaResourceLoaderBridgeFactory(
1886 GURL::EmptyGURL(), // referrer
1887 "null", // frame origin
1888 "null", // main_frame_origin
1889 base::GetCurrentProcId(),
1890 WebAppCacheContext::kNoAppCacheContextId,
1891 routing_id());
1892
[email protected]add51772009-06-11 18:25:171893 if (!cmd_line->HasSwitch(switches::kSimpleDataSource)) {
1894 // Add the chrome specific media data source.
[email protected]70ab61c92009-06-16 19:29:391895 factory->AddFactory(
[email protected]8e296bbd2009-07-22 21:37:171896 webkit_glue::BufferedDataSource::CreateFactory(MessageLoop::current(),
1897 bridge_factory));
[email protected]8380c092009-06-25 17:45:511898 } else {
1899 factory->AddFactory(
1900 webkit_glue::SimpleDataSource::CreateFactory(MessageLoop::current(),
1901 bridge_factory));
[email protected]add51772009-06-11 18:25:171902 }
1903 return new webkit_glue::WebMediaPlayerImpl(client, factory);
[email protected]ec9212f2008-12-18 21:40:361904}
1905
initial.commit09911bf2008-07-26 23:55:291906void RenderView::OnMissingPluginStatus(WebPluginDelegate* delegate,
1907 int status) {
[email protected]6c8afae52009-01-22 02:24:571908#if defined(OS_WIN)
initial.commit09911bf2008-07-26 23:55:291909 if (first_default_plugin_ == NULL) {
1910 // Show the InfoBar for the first available plugin.
1911 if (status == default_plugin::MISSING_PLUGIN_AVAILABLE) {
1912 first_default_plugin_ = delegate;
1913 Send(new ViewHostMsg_MissingPluginStatus(routing_id_, status));
1914 }
1915 } else {
1916 // Closes the InfoBar if user clicks on the plugin (instead of the InfoBar)
1917 // to start the download/install.
1918 if (status == default_plugin::MISSING_PLUGIN_USER_STARTED_DOWNLOAD) {
1919 Send(new ViewHostMsg_MissingPluginStatus(routing_id_, status));
1920 }
1921 }
[email protected]6c8afae52009-01-22 02:24:571922#else
1923 // TODO(port): plugins current not supported
1924 NOTIMPLEMENTED();
1925#endif
initial.commit09911bf2008-07-26 23:55:291926}
1927
[email protected]eb47a132009-03-04 00:39:561928WebWorker* RenderView::CreateWebWorker(WebWorkerClient* client) {
[email protected]ec775ef2009-05-01 21:20:471929 return new WebWorkerProxy(client, RenderThread::current(), routing_id_);
[email protected]eb47a132009-03-04 00:39:561930}
1931
initial.commit09911bf2008-07-26 23:55:291932void RenderView::OpenURL(WebView* webview, const GURL& url,
[email protected]c0588052008-10-27 23:01:501933 const GURL& referrer,
[email protected]4873c7d2009-07-16 06:36:281934 WebNavigationPolicy policy) {
1935 Send(new ViewHostMsg_OpenURL(
1936 routing_id_, url, referrer, NavigationPolicyToDisposition(policy)));
initial.commit09911bf2008-07-26 23:55:291937}
1938
[email protected]1d522202009-04-04 01:56:421939void RenderView::DidContentsSizeChange(WebWidget* webwidget,
1940 int new_width,
1941 int new_height) {
[email protected]0666aef2009-05-13 19:48:081942 // We don't always want to send the change messages over IPC, only if we've
1943 // be put in that mode by getting a |ViewMsg_EnableIntrinsicWidthChangedMode|
1944 // message.
1945 // TODO(rafaelw): Figure out where the best place to set this for extensions
1946 // is. It isn't clean to test for ExtensionView by examining the
1947 // enabled_bindings. This needs to be generalized as it becomes clear what
1948 // extension toolbars need.
1949 if (BindingsPolicy::is_extension_enabled(enabled_bindings_) ||
1950 send_preferred_width_changes_) {
1951 // WebCore likes to tell us things have changed even when they haven't, so
1952 // cache the width and only send the IPC message when we're sure the
1953 // width is different.
[email protected]1d522202009-04-04 01:56:421954 int width = webview()->GetMainFrame()->GetContentsPreferredWidth();
[email protected]0666aef2009-05-13 19:48:081955 if (width != preferred_width_) {
1956 Send(new ViewHostMsg_DidContentsPreferredWidthChange(routing_id_, width));
1957 preferred_width_ = width;
1958 }
[email protected]1d522202009-04-04 01:56:421959 }
1960}
1961
initial.commit09911bf2008-07-26 23:55:291962// We are supposed to get a single call to Show for a newly created RenderView
1963// that was created via RenderView::CreateWebView. So, we wait until this
1964// point to dispatch the ShowView message.
1965//
1966// This method provides us with the information about how to display the newly
1967// created RenderView (i.e., as a constrained popup or as a new tab).
1968//
[email protected]4873c7d2009-07-16 06:36:281969void RenderView::show(WebNavigationPolicy policy) {
initial.commit09911bf2008-07-26 23:55:291970 DCHECK(!did_show_) << "received extraneous Show call";
1971 DCHECK(opener_id_ != MSG_ROUTING_NONE);
1972
1973 if (did_show_)
1974 return;
1975 did_show_ = true;
1976
1977 // NOTE: initial_pos_ may still have its default values at this point, but
1978 // that's okay. It'll be ignored if disposition is not NEW_POPUP, or the
1979 // browser process will impose a default position otherwise.
[email protected]4873c7d2009-07-16 06:36:281980 Send(new ViewHostMsg_ShowView(opener_id_, routing_id_,
1981 NavigationPolicyToDisposition(policy), initial_pos_,
1982 opened_by_user_gesture_, creator_url_));
[email protected]2533ce12009-05-09 00:02:241983 SetPendingWindowRect(initial_pos_);
initial.commit09911bf2008-07-26 23:55:291984}
1985
[email protected]4873c7d2009-07-16 06:36:281986void RenderView::closeWidgetSoon() {
[email protected]2c4410d2009-05-06 23:46:221987 if (!popup_notification_visible_)
[email protected]4873c7d2009-07-16 06:36:281988 RenderWidget::closeWidgetSoon();
[email protected]634a6f92008-12-01 21:39:311989}
1990
[email protected]4873c7d2009-07-16 06:36:281991void RenderView::runModal() {
initial.commit09911bf2008-07-26 23:55:291992 DCHECK(did_show_) << "should already have shown the view";
1993
1994 IPC::SyncMessage* msg = new ViewHostMsg_RunModal(routing_id_);
1995
[email protected]1c4947f2009-01-15 22:25:111996 msg->set_pump_messages_event(modal_dialog_event_.get());
initial.commit09911bf2008-07-26 23:55:291997 Send(msg);
1998}
1999
2000void RenderView::SyncNavigationState() {
2001 if (!webview())
2002 return;
2003
[email protected]ca948a22009-06-25 19:36:172004 const WebHistoryItem& item =
2005 webview()->GetMainFrame()->GetCurrentHistoryItem();
2006 if (item.isNull())
initial.commit09911bf2008-07-26 23:55:292007 return;
[email protected]ca948a22009-06-25 19:36:172008
2009 Send(new ViewHostMsg_UpdateState(
2010 routing_id_, page_id_, webkit_glue::HistoryItemToString(item)));
initial.commit09911bf2008-07-26 23:55:292011}
2012
2013void RenderView::ShowContextMenu(WebView* webview,
[email protected]581b87eb2009-07-23 23:06:562014 ContextNodeType node_type,
initial.commit09911bf2008-07-26 23:55:292015 int x,
2016 int y,
2017 const GURL& link_url,
[email protected]574a1d62009-07-17 03:23:462018 const GURL& src_url,
initial.commit09911bf2008-07-26 23:55:292019 const GURL& page_url,
2020 const GURL& frame_url,
[email protected]574a1d62009-07-17 03:23:462021 const ContextMenuMediaParams& media_params,
initial.commit09911bf2008-07-26 23:55:292022 const std::wstring& selection_text,
2023 const std::wstring& misspelled_word,
[email protected]6aa376b2008-09-23 18:49:522024 int edit_flags,
[email protected]c9825a42009-05-01 22:51:502025 const std::string& security_info,
2026 const std::string& frame_charset) {
[email protected]e09ba552009-02-05 03:26:292027 ContextMenuParams params;
[email protected]581b87eb2009-07-23 23:06:562028 params.node_type = node_type;
initial.commit09911bf2008-07-26 23:55:292029 params.x = x;
2030 params.y = y;
[email protected]574a1d62009-07-17 03:23:462031 params.src_url = src_url;
initial.commit09911bf2008-07-26 23:55:292032 params.link_url = link_url;
[email protected]e6c79812009-04-22 22:31:422033 params.unfiltered_link_url = link_url;
initial.commit09911bf2008-07-26 23:55:292034 params.page_url = page_url;
2035 params.frame_url = frame_url;
[email protected]574a1d62009-07-17 03:23:462036 params.media_params = media_params;
initial.commit09911bf2008-07-26 23:55:292037 params.selection_text = selection_text;
2038 params.misspelled_word = misspelled_word;
[email protected]be645db2009-02-06 20:36:332039 params.spellcheck_enabled =
[email protected]bbbd545c2008-12-15 20:18:042040 webview->GetFocusedFrame()->SpellCheckEnabled();
initial.commit09911bf2008-07-26 23:55:292041 params.edit_flags = edit_flags;
[email protected]6aa376b2008-09-23 18:49:522042 params.security_info = security_info;
[email protected]c9825a42009-05-01 22:51:502043 params.frame_charset = frame_charset;
initial.commit09911bf2008-07-26 23:55:292044 Send(new ViewHostMsg_ContextMenu(routing_id_, params));
2045}
2046
[email protected]e80c73b2009-04-07 23:24:582047void RenderView::StartDragging(WebView* webview,
2048 const WebDragData& drag_data) {
2049 Send(new ViewHostMsg_StartDragging(routing_id_, WebDropData(drag_data)));
initial.commit09911bf2008-07-26 23:55:292050}
2051
2052void RenderView::TakeFocus(WebView* webview, bool reverse) {
2053 Send(new ViewHostMsg_TakeFocus(routing_id_, reverse));
2054}
2055
2056void RenderView::DidDownloadImage(int id,
2057 const GURL& image_url,
2058 bool errored,
2059 const SkBitmap& image) {
[email protected]bf5c2ff392009-07-08 16:24:332060 Send(new ViewHostMsg_DidDownloadFavIcon(routing_id_, id, image_url, errored,
2061 image));
initial.commit09911bf2008-07-26 23:55:292062}
2063
[email protected]bf5c2ff392009-07-08 16:24:332064void RenderView::OnDownloadFavIcon(int id,
2065 const GURL& image_url,
2066 int image_size) {
[email protected]f11ca0732009-04-11 00:09:342067 bool data_image_failed = false;
2068 if (image_url.SchemeIs("data")) {
2069 SkBitmap data_image = ImageFromDataUrl(image_url);
2070 data_image_failed = data_image.empty();
2071 if (!data_image_failed) {
[email protected]bf5c2ff392009-07-08 16:24:332072 Send(new ViewHostMsg_DidDownloadFavIcon(routing_id_, id, image_url, false,
2073 data_image));
[email protected]f11ca0732009-04-11 00:09:342074 }
2075 }
2076
[email protected]bf5c2ff392009-07-08 16:24:332077 if (data_image_failed ||
2078 !webview()->DownloadImage(id, image_url, image_size)) {
2079 Send(new ViewHostMsg_DidDownloadFavIcon(routing_id_, id, image_url, true,
2080 SkBitmap()));
2081 }
initial.commit09911bf2008-07-26 23:55:292082}
2083
[email protected]f11ca0732009-04-11 00:09:342084SkBitmap RenderView::ImageFromDataUrl(const GURL& url) const {
2085 std::string mime_type, char_set, data;
2086 if (net::DataURL::Parse(url, &mime_type, &char_set, &data) && !data.empty()) {
2087 // Decode the favicon using WebKit's image decoder.
2088 webkit_glue::ImageDecoder decoder(gfx::Size(kFavIconSize, kFavIconSize));
2089 const unsigned char* src_data =
2090 reinterpret_cast<const unsigned char*>(&data[0]);
2091
2092 return decoder.Decode(src_data, data.size());
2093 }
2094 return SkBitmap();
2095}
2096
initial.commit09911bf2008-07-26 23:55:292097void RenderView::OnGetApplicationInfo(int page_id) {
2098 webkit_glue::WebApplicationInfo app_info;
2099 if (page_id == page_id_)
2100 webkit_glue::GetApplicationInfo(webview(), &app_info);
2101
2102 // Prune out any data URLs in the set of icons. The browser process expects
2103 // any icon with a data URL to have originated from a favicon. We don't want
2104 // to decode arbitrary data URLs in the browser process. See
2105 // http://b/issue?id=1162972
2106 for (size_t i = 0; i < app_info.icons.size(); ++i) {
[email protected]6de74452009-02-25 18:04:592107 if (app_info.icons[i].url.SchemeIs(chrome::kDataScheme)) {
initial.commit09911bf2008-07-26 23:55:292108 app_info.icons.erase(app_info.icons.begin() + i);
2109 --i;
2110 }
2111 }
2112
2113 Send(new ViewHostMsg_DidGetApplicationInfo(routing_id_, page_id, app_info));
2114}
2115
2116GURL RenderView::GetAlternateErrorPageURL(const GURL& failedURL,
2117 ErrorPageType error_type) {
2118 if (failedURL.SchemeIsSecure()) {
2119 // If the URL that failed was secure, then the embedding web page was not
2120 // expecting a network attacker to be able to manipulate its contents. As
2121 // we fetch alternate error pages over HTTP, we would be allowing a network
2122 // attacker to manipulate the contents of the response if we tried to use
2123 // the link doctor here.
2124 return GURL::EmptyGURL();
2125 }
2126
2127 // Grab the base URL from the browser process.
2128 if (!alternate_error_page_url_.is_valid())
2129 return GURL::EmptyGURL();
2130
2131 // Strip query params from the failed URL.
2132 GURL::Replacements remove_params;
2133 remove_params.ClearUsername();
2134 remove_params.ClearPassword();
2135 remove_params.ClearQuery();
2136 remove_params.ClearRef();
2137 const GURL url_to_send = failedURL.ReplaceComponents(remove_params);
2138
2139 // Construct the query params to send to link doctor.
2140 std::string params(alternate_error_page_url_.query());
2141 params.append("&url=");
2142 params.append(EscapeQueryParamValue(url_to_send.spec()));
2143 params.append("&sourceid=chrome");
2144 params.append("&error=");
2145 switch (error_type) {
2146 case DNS_ERROR:
2147 params.append("dnserror");
2148 break;
2149
2150 case HTTP_404:
2151 params.append("http404");
2152 break;
2153
[email protected]5df266ac2008-10-15 19:50:132154 case CONNECTION_ERROR:
[email protected]e1f934b2009-01-26 20:41:332155 params.append("connectionfailure");
[email protected]5df266ac2008-10-15 19:50:132156 break;
2157
initial.commit09911bf2008-07-26 23:55:292158 default:
2159 NOTREACHED() << "unknown ErrorPageType";
2160 }
2161
2162 // OK, build the final url to return.
2163 GURL::Replacements link_doctor_params;
2164 link_doctor_params.SetQueryStr(params);
2165 GURL url = alternate_error_page_url_.ReplaceComponents(link_doctor_params);
2166 return url;
2167}
2168
[email protected]7ea066a2009-04-06 20:21:592169void RenderView::OnFind(int request_id,
2170 const string16& search_text,
2171 const WebKit::WebFindOptions& options) {
initial.commit09911bf2008-07-26 23:55:292172 WebFrame* main_frame = webview()->GetMainFrame();
2173 WebFrame* frame_after_main = webview()->GetNextFrameAfter(main_frame, true);
2174 WebFrame* focused_frame = webview()->GetFocusedFrame();
2175 WebFrame* search_frame = focused_frame; // start searching focused frame.
2176
2177 bool multi_frame = (frame_after_main != main_frame);
2178
2179 // If we have multiple frames, we don't want to wrap the search within the
2180 // frame, so we check here if we only have main_frame in the chain.
2181 bool wrap_within_frame = !multi_frame;
2182
[email protected]b3f2b912009-04-09 16:18:522183 WebRect selection_rect;
initial.commit09911bf2008-07-26 23:55:292184 bool result = false;
2185
2186 do {
[email protected]7ea066a2009-04-06 20:21:592187 result = search_frame->Find(
2188 request_id, search_text, options, wrap_within_frame, &selection_rect);
initial.commit09911bf2008-07-26 23:55:292189
2190 if (!result) {
2191 // don't leave text selected as you move to the next frame.
2192 search_frame->ClearSelection();
2193
2194 // Find the next frame, but skip the invisible ones.
2195 do {
2196 // What is the next frame to search? (we might be going backwards). Note
2197 // that we specify wrap=true so that search_frame never becomes NULL.
[email protected]7ea066a2009-04-06 20:21:592198 search_frame = options.forward ?
initial.commit09911bf2008-07-26 23:55:292199 webview()->GetNextFrameAfter(search_frame, true) :
2200 webview()->GetPreviousFrameBefore(search_frame, true);
2201 } while (!search_frame->Visible() && search_frame != focused_frame);
2202
[email protected]884db412008-11-24 23:46:502203 // Make sure selection doesn't affect the search operation in new frame.
initial.commit09911bf2008-07-26 23:55:292204 search_frame->ClearSelection();
2205
2206 // If we have multiple frames and we have wrapped back around to the
2207 // focused frame, we need to search it once more allowing wrap within
2208 // the frame, otherwise it will report 'no match' if the focused frame has
2209 // reported matches, but no frames after the focused_frame contain a
2210 // match for the search word(s).
2211 if (multi_frame && search_frame == focused_frame) {
[email protected]7ea066a2009-04-06 20:21:592212 result = search_frame->Find(
2213 request_id, search_text, options, true, // Force wrapping.
2214 &selection_rect);
initial.commit09911bf2008-07-26 23:55:292215 }
2216 }
2217
initial.commit09911bf2008-07-26 23:55:292218 webview()->SetFocusedFrame(search_frame);
2219 } while (!result && search_frame != focused_frame);
2220
[email protected]7ea066a2009-04-06 20:21:592221 if (options.findNext) {
[email protected]4f3dc372009-02-24 00:10:292222 // Force the main_frame to report the actual count.
[email protected]7ea066a2009-04-06 20:21:592223 main_frame->IncreaseMatchCount(0, request_id);
[email protected]4f3dc372009-02-24 00:10:292224 } else {
2225 // If nothing is found, set result to "0 of 0", otherwise, set it to
2226 // "-1 of 1" to indicate that we found at least one item, but we don't know
2227 // yet what is active.
2228 int ordinal = result ? -1 : 0; // -1 here means, we might know more later.
2229 int match_count = result ? 1 : 0; // 1 here means possibly more coming.
initial.commit09911bf2008-07-26 23:55:292230
[email protected]4f3dc372009-02-24 00:10:292231 // If we find no matches then this will be our last status update.
2232 // Otherwise the scoping effort will send more results.
2233 bool final_status_update = !result;
initial.commit09911bf2008-07-26 23:55:292234
[email protected]4f3dc372009-02-24 00:10:292235 // Send the search result over to the browser process.
[email protected]4f999132009-03-31 18:08:402236 Send(new ViewHostMsg_Find_Reply(routing_id_,
[email protected]7ea066a2009-04-06 20:21:592237 request_id,
[email protected]4f3dc372009-02-24 00:10:292238 match_count,
2239 selection_rect,
2240 ordinal,
2241 final_status_update));
initial.commit09911bf2008-07-26 23:55:292242
initial.commit09911bf2008-07-26 23:55:292243 // Scoping effort begins, starting with the mainframe.
2244 search_frame = main_frame;
2245
2246 main_frame->ResetMatchCount();
2247
2248 do {
2249 // Cancel all old scoping requests before starting a new one.
2250 search_frame->CancelPendingScopingEffort();
2251
2252 // We don't start another scoping effort unless at least one match has
2253 // been found.
2254 if (result) {
2255 // Start new scoping request. If the scoping function determines that it
2256 // needs to scope, it will defer until later.
[email protected]7ea066a2009-04-06 20:21:592257 search_frame->ScopeStringMatches(request_id,
2258 search_text,
2259 options,
initial.commit09911bf2008-07-26 23:55:292260 true); // reset the tickmarks
2261 }
2262
2263 // Iterate to the next frame. The frame will not necessarily scope, for
2264 // example if it is not visible.
2265 search_frame = webview()->GetNextFrameAfter(search_frame, true);
2266 } while (search_frame != main_frame);
2267 }
2268}
2269
[email protected]5c4266922009-07-10 16:41:272270void RenderView::OnDeterminePageText() {
2271 if (!is_loading_) {
2272 if (!webview())
2273 return;
2274 WebFrame* main_frame = webview()->GetMainFrame();
2275 std::wstring contents;
2276 CaptureText(main_frame, &contents);
2277 Send(new ViewMsg_DeterminePageText_Reply(routing_id_, contents));
2278 determine_page_text_after_loading_stops_ = false;
2279 return;
2280 }
2281
2282 // We set |determine_page_text_after_loading_stops_| true here so that,
2283 // after page has been loaded completely, the text in the page is captured.
2284 determine_page_text_after_loading_stops_ = true;
2285}
2286
initial.commit09911bf2008-07-26 23:55:292287void RenderView::ReportFindInPageMatchCount(int count, int request_id,
2288 bool final_update) {
2289 // If we have a message that has been queued up, then we should just replace
2290 // it. The ACK from the browser will make sure it gets sent when the browser
2291 // wants it.
2292 if (queued_find_reply_message_.get()) {
2293 IPC::Message* msg = new ViewHostMsg_Find_Reply(
2294 routing_id_,
2295 request_id,
2296 count,
[email protected]b3f2b912009-04-09 16:18:522297 gfx::Rect(),
initial.commit09911bf2008-07-26 23:55:292298 -1, // Don't update active match ordinal.
2299 final_update);
2300 queued_find_reply_message_.reset(msg);
2301 } else {
2302 // Send the search result over to the browser process.
2303 Send(new ViewHostMsg_Find_Reply(
2304 routing_id_,
2305 request_id,
2306 count,
[email protected]b3f2b912009-04-09 16:18:522307 gfx::Rect(),
initial.commit09911bf2008-07-26 23:55:292308 -1, // // Don't update active match ordinal.
2309 final_update));
2310 }
2311}
2312
2313void RenderView::ReportFindInPageSelection(int request_id,
2314 int active_match_ordinal,
[email protected]b3f2b912009-04-09 16:18:522315 const WebRect& selection_rect) {
initial.commit09911bf2008-07-26 23:55:292316 // Send the search result over to the browser process.
2317 Send(new ViewHostMsg_Find_Reply(routing_id_,
2318 request_id,
2319 -1,
2320 selection_rect,
2321 active_match_ordinal,
2322 false));
2323}
2324
[email protected]ed4bf2d2009-05-05 00:10:062325bool RenderView::WasOpenedByUserGesture() const {
initial.commit09911bf2008-07-26 23:55:292326 return opened_by_user_gesture_;
2327}
2328
[email protected]7f40fc5b2009-06-12 19:23:082329void RenderView::SpellCheck(const std::wstring& word, int* misspell_location,
2330 int* misspell_length) {
2331 Send(new ViewHostMsg_SpellCheck(routing_id_, word, misspell_location,
2332 misspell_length));
initial.commit09911bf2008-07-26 23:55:292333}
2334
[email protected]26ea6c42009-06-10 22:32:212335std::wstring RenderView::GetAutoCorrectWord(
2336 const std::wstring& misspelled_word) {
2337 std::wstring autocorrect_word;
[email protected]eda2b5a2009-05-12 19:30:212338 const CommandLine& command_line = *CommandLine::ForCurrentProcess();
2339 if (command_line.HasSwitch(switches::kAutoSpellCorrect)) {
2340 Send(new ViewHostMsg_GetAutoCorrectWord(routing_id_, misspelled_word,
2341 &autocorrect_word));
2342 }
[email protected]26ea6c42009-06-10 22:32:212343
2344 return autocorrect_word;
[email protected]eda2b5a2009-05-12 19:30:212345}
2346
initial.commit09911bf2008-07-26 23:55:292347void RenderView::SetInputMethodState(bool enabled) {
2348 // Save the updated IME status and mark the input focus has been updated.
2349 // The IME status is to be sent to a browser process next time when
2350 // the input caret is rendered.
[email protected]9f23f592008-11-17 08:36:342351 if (!ime_control_busy_) {
2352 ime_control_updated_ = true;
2353 ime_control_new_state_ = enabled;
2354 }
initial.commit09911bf2008-07-26 23:55:292355}
2356
2357void RenderView::ScriptedPrint(WebFrame* frame) {
[email protected]aa82249f2009-07-16 17:23:582358 DCHECK(webview());
2359 if (webview()) {
2360 // Print the full page - not just the frame the javascript is running from.
2361 Print(webview()->GetMainFrame(), true);
2362 }
initial.commit09911bf2008-07-26 23:55:292363}
2364
initial.commit09911bf2008-07-26 23:55:292365void RenderView::UserMetricsRecordAction(const std::wstring& action) {
2366 Send(new ViewHostMsg_UserMetricsRecordAction(routing_id_, action));
2367}
2368
2369void RenderView::DnsPrefetch(const std::vector<std::string>& host_names) {
2370 Send(new ViewHostMsg_DnsPrefetch(host_names));
2371}
2372
[email protected]630e26b2008-10-14 22:55:172373void RenderView::OnZoom(int function) {
2374 static const bool kZoomIsTextOnly = false;
2375 switch (function) {
2376 case PageZoom::SMALLER:
2377 webview()->ZoomOut(kZoomIsTextOnly);
initial.commit09911bf2008-07-26 23:55:292378 break;
[email protected]630e26b2008-10-14 22:55:172379 case PageZoom::STANDARD:
2380 webview()->ResetZoom();
initial.commit09911bf2008-07-26 23:55:292381 break;
[email protected]630e26b2008-10-14 22:55:172382 case PageZoom::LARGER:
2383 webview()->ZoomIn(kZoomIsTextOnly);
initial.commit09911bf2008-07-26 23:55:292384 break;
2385 default:
2386 NOTREACHED();
2387 }
2388}
2389
[email protected]ea8c7452009-04-02 20:47:062390void RenderView::OnInsertText(const string16& text) {
[email protected]5f9e0b82009-05-08 22:13:392391 WebFrame* frame = webview()->GetFocusedFrame();
2392 if (!frame)
2393 return;
2394 WebTextInput* text_input = frame->GetTextInput();
[email protected]00d7e622009-04-21 23:06:052395 if (text_input)
[email protected]7be0e172009-05-14 01:05:272396 text_input->InsertText(text);
[email protected]ea8c7452009-04-02 20:47:062397}
2398
[email protected]e38f40152008-09-12 23:08:302399void RenderView::OnSetPageEncoding(const std::wstring& encoding_name) {
initial.commit09911bf2008-07-26 23:55:292400 webview()->SetPageEncoding(encoding_name);
2401}
2402
[email protected]f6e59a62009-05-13 21:12:032403void RenderView::NavigateBackForwardSoon(int offset) {
[email protected]f46aff62008-10-16 07:58:052404 history_back_list_count_ += offset;
2405 history_forward_list_count_ -= offset;
2406
initial.commit09911bf2008-07-26 23:55:292407 Send(new ViewHostMsg_GoToEntryAtOffset(routing_id_, offset));
2408}
2409
2410int RenderView::GetHistoryBackListCount() {
2411 return history_back_list_count_;
2412}
2413
2414int RenderView::GetHistoryForwardListCount() {
2415 return history_forward_list_count_;
2416}
2417
2418void RenderView::OnNavStateChanged(WebView* webview) {
[email protected]81a34412009-01-05 19:17:242419 if (!nav_state_sync_timer_.IsRunning()) {
2420 nav_state_sync_timer_.Start(
2421 TimeDelta::FromSeconds(delay_seconds_for_form_state_sync_), this,
2422 &RenderView::SyncNavigationState);
2423 }
initial.commit09911bf2008-07-26 23:55:292424}
2425
2426void RenderView::SetTooltipText(WebView* webview,
[email protected]de570ef2009-07-29 18:27:522427 const std::wstring& tooltip_text,
2428 WebTextDirection text_direction_hint) {
2429 Send(new ViewHostMsg_SetTooltipText(routing_id_, tooltip_text,
2430 text_direction_hint));
initial.commit09911bf2008-07-26 23:55:292431}
2432
[email protected]2e417c82009-04-02 22:30:262433void RenderView::DidChangeSelection(bool is_empty_selection) {
2434#if defined(OS_LINUX)
[email protected]d5d7b8002009-05-18 21:20:542435 // TODO(estade): investigate incremental updates to the selection so that we
2436 // don't send the entire selection over IPC every time.
[email protected]2e417c82009-04-02 22:30:262437 if (!is_empty_selection) {
[email protected]d5d7b8002009-05-18 21:20:542438 // Sometimes we get repeated DidChangeSelection calls from webkit when
2439 // the selection hasn't actually changed. We don't want to report these
2440 // because it will cause us to continually claim the X clipboard.
2441 const std::string& this_selection =
2442 webview()->GetFocusedFrame()->GetSelection(false);
2443 if (this_selection == last_selection_)
2444 return;
2445
[email protected]dbadbcc2009-04-09 00:57:102446 Send(new ViewHostMsg_SelectionChanged(routing_id_,
[email protected]d5d7b8002009-05-18 21:20:542447 this_selection));
2448 last_selection_ = this_selection;
[email protected]4f61a022009-06-25 23:49:012449 } else {
2450 last_selection_.clear();
[email protected]2e417c82009-04-02 22:30:262451 }
2452#endif
2453}
2454
initial.commit09911bf2008-07-26 23:55:292455void RenderView::DownloadUrl(const GURL& url, const GURL& referrer) {
2456 Send(new ViewHostMsg_DownloadUrl(routing_id_, url, referrer));
2457}
2458
[email protected]0df30122009-06-03 12:13:082459void RenderView::UpdateInspectorSettings(const std::wstring& raw_settings) {
2460 Send(new ViewHostMsg_UpdateInspectorSettings(routing_id_, raw_settings));
2461}
2462
[email protected]611cad42009-03-16 18:51:342463WebDevToolsAgentDelegate* RenderView::GetWebDevToolsAgentDelegate() {
[email protected]b75b7d072009-04-06 13:47:002464 return devtools_agent_.get();
[email protected]611cad42009-03-16 18:51:342465}
2466
[email protected]ea8c7452009-04-02 20:47:062467void RenderView::PasteFromSelectionClipboard() {
2468 Send(new ViewHostMsg_PasteFromSelectionClipboard(routing_id_));
2469}
2470
initial.commit09911bf2008-07-26 23:55:292471WebFrame* RenderView::GetChildFrame(const std::wstring& frame_xpath) const {
2472 WebFrame* web_frame;
2473 if (frame_xpath.empty()) {
2474 web_frame = webview()->GetMainFrame();
2475 } else {
2476 web_frame = webview()->GetMainFrame()->GetChildFrame(frame_xpath);
2477 }
2478
2479 return web_frame;
2480}
2481
[email protected]f29acf52008-11-03 20:08:332482void RenderView::EvaluateScript(const std::wstring& frame_xpath,
2483 const std::wstring& script) {
initial.commit09911bf2008-07-26 23:55:292484 WebFrame* web_frame = GetChildFrame(frame_xpath);
2485 if (!web_frame)
2486 return;
2487
[email protected]4f999132009-03-31 18:08:402488 web_frame->ExecuteScript(WebScriptSource(WideToUTF16Hack(script)));
initial.commit09911bf2008-07-26 23:55:292489}
2490
[email protected]1810e132009-03-24 23:35:482491void RenderView::InsertCSS(const std::wstring& frame_xpath,
2492 const std::string& css) {
2493 WebFrame* web_frame = GetChildFrame(frame_xpath);
2494 if (!web_frame)
2495 return;
2496
2497 web_frame->InsertCSSStyles(css);
2498}
2499
initial.commit09911bf2008-07-26 23:55:292500void RenderView::OnScriptEvalRequest(const std::wstring& frame_xpath,
2501 const std::wstring& jscript) {
[email protected]f29acf52008-11-03 20:08:332502 EvaluateScript(frame_xpath, jscript);
initial.commit09911bf2008-07-26 23:55:292503}
2504
[email protected]1810e132009-03-24 23:35:482505void RenderView::OnCSSInsertRequest(const std::wstring& frame_xpath,
2506 const std::string& css) {
2507 InsertCSS(frame_xpath, css);
[email protected]ae461542009-06-19 19:03:412508
2509 // Notify RenderViewHost that css has been inserted into the frame.
2510 Send(new ViewHostMsg_OnCSSInserted(routing_id_));
[email protected]1810e132009-03-24 23:35:482511}
2512
[email protected]7ea066a2009-04-06 20:21:592513void RenderView::OnAddMessageToConsole(
2514 const string16& frame_xpath,
2515 const string16& message,
2516 const WebConsoleMessage::Level& level) {
2517 WebFrame* web_frame = GetChildFrame(UTF16ToWideHack(frame_xpath));
[email protected]0dea3ea2009-03-31 23:30:592518 if (web_frame)
[email protected]7ea066a2009-04-06 20:21:592519 web_frame->AddMessageToConsole(WebConsoleMessage(level, message));
initial.commit09911bf2008-07-26 23:55:292520}
2521
[email protected]81e63782009-02-27 19:35:092522void RenderView::OnAllowBindings(int enabled_bindings_flags) {
2523 enabled_bindings_ |= enabled_bindings_flags;
initial.commit09911bf2008-07-26 23:55:292524}
2525
2526void RenderView::OnSetDOMUIProperty(const std::string& name,
2527 const std::string& value) {
[email protected]81e63782009-02-27 19:35:092528 DCHECK(BindingsPolicy::is_dom_ui_enabled(enabled_bindings_));
initial.commit09911bf2008-07-26 23:55:292529 dom_ui_bindings_.SetProperty(name, value);
2530}
2531
2532void RenderView::OnReservePageIDRange(int size_of_range) {
2533 next_page_id_ += size_of_range + 1;
2534}
2535
[email protected]e80c73b2009-04-07 23:24:582536void RenderView::OnDragSourceEndedOrMoved(const gfx::Point& client_point,
2537 const gfx::Point& screen_point,
[email protected]5f9ae6c2009-07-08 02:38:032538 bool ended, bool cancelled) {
2539 if (ended) {
2540 if (cancelled)
2541 webview()->DragSourceCancelledAt(client_point, screen_point);
2542 else
2543 webview()->DragSourceEndedAt(client_point, screen_point);
2544 } else {
[email protected]e80c73b2009-04-07 23:24:582545 webview()->DragSourceMovedTo(client_point, screen_point);
[email protected]5f9ae6c2009-07-08 02:38:032546 }
initial.commit09911bf2008-07-26 23:55:292547}
2548
2549void RenderView::OnDragSourceSystemDragEnded() {
2550 webview()->DragSourceSystemDragEnded();
2551}
2552
2553void RenderView::OnUploadFileRequest(const ViewMsg_UploadFile_Params& p) {
2554 webkit_glue::FileUploadData* f = new webkit_glue::FileUploadData;
2555 f->file_path = p.file_path;
2556 f->form_name = p.form;
2557 f->file_name = p.file;
2558 f->submit_name = p.submit;
2559
2560 // Build the other form values map.
2561 if (!p.other_values.empty()) {
2562 std::vector<std::wstring> e;
2563 std::vector<std::wstring> kvp;
2564 std::vector<std::wstring>::iterator i;
2565
2566 SplitString(p.other_values, L'\n', &e);
2567 for (i = e.begin(); i != e.end(); ++i) {
2568 SplitString(*i, L'=', &kvp);
2569 if (kvp.size() == 2)
2570 f->other_form_values[kvp[0]] = kvp[1];
2571 kvp.clear();
2572 }
2573 }
2574
2575 pending_upload_data_.reset(f);
2576 ProcessPendingUpload();
2577}
2578
2579void RenderView::ProcessPendingUpload() {
2580 webkit_glue::FileUploadData* f = pending_upload_data_.get();
2581 if (f && webview() && webkit_glue::FillFormToUploadFile(webview(), *f))
2582 ResetPendingUpload();
2583}
2584
2585void RenderView::ResetPendingUpload() {
2586 pending_upload_data_.reset();
2587}
2588
2589void RenderView::OnFormFill(const FormData& form) {
2590 webkit_glue::FillForm(this->webview(), form);
2591}
2592
2593void RenderView::OnFillPasswordForm(
[email protected]daa8c58e2009-06-15 17:21:102594 const webkit_glue::PasswordFormDomManager::FillData& form_data) {
initial.commit09911bf2008-07-26 23:55:292595 webkit_glue::FillPasswordForm(this->webview(), form_data);
2596}
2597
2598void RenderView::OnDragTargetDragEnter(const WebDropData& drop_data,
[email protected]e80c73b2009-04-07 23:24:582599 const gfx::Point& client_point,
2600 const gfx::Point& screen_point) {
2601 bool is_drop_target = webview()->DragTargetDragEnter(
2602 drop_data.ToDragData(),
2603 drop_data.identity,
2604 client_point,
2605 screen_point);
initial.commit09911bf2008-07-26 23:55:292606
2607 Send(new ViewHostMsg_UpdateDragCursor(routing_id_, is_drop_target));
2608}
2609
[email protected]e80c73b2009-04-07 23:24:582610void RenderView::OnDragTargetDragOver(const gfx::Point& client_point,
2611 const gfx::Point& screen_point) {
2612 bool is_drop_target =
2613 webview()->DragTargetDragOver(client_point, screen_point);
initial.commit09911bf2008-07-26 23:55:292614
2615 Send(new ViewHostMsg_UpdateDragCursor(routing_id_, is_drop_target));
2616}
2617
2618void RenderView::OnDragTargetDragLeave() {
2619 webview()->DragTargetDragLeave();
2620}
2621
[email protected]e80c73b2009-04-07 23:24:582622void RenderView::OnDragTargetDrop(const gfx::Point& client_point,
2623 const gfx::Point& screen_point) {
2624 webview()->DragTargetDrop(client_point, screen_point);
initial.commit09911bf2008-07-26 23:55:292625}
2626
2627void RenderView::OnUpdateWebPreferences(const WebPreferences& prefs) {
2628 webview()->SetPreferences(prefs);
2629}
2630
2631void RenderView::OnSetAltErrorPageURL(const GURL& url) {
2632 alternate_error_page_url_ = url;
2633}
2634
initial.commit09911bf2008-07-26 23:55:292635void RenderView::OnInstallMissingPlugin() {
2636 // This could happen when the first default plugin is deleted.
2637 if (first_default_plugin_ == NULL)
2638 return;
2639 first_default_plugin_->InstallMissingPlugin();
2640}
2641
[email protected]b62d1a8c2009-01-13 23:54:572642void RenderView::OnFileChooserResponse(
[email protected]561abe62009-04-06 18:08:342643 const std::vector<FilePath>& file_names) {
[email protected]8029f5672009-03-20 22:33:362644 // This could happen if we navigated to a different page before the user
2645 // closed the chooser.
2646 if (!file_chooser_.get())
2647 return;
2648
[email protected]b62d1a8c2009-01-13 23:54:572649 file_chooser_->OnFileChoose(file_names);
initial.commit09911bf2008-07-26 23:55:292650 file_chooser_.reset();
2651}
2652
2653void RenderView::OnEnableViewSourceMode() {
2654 if (!webview())
2655 return;
2656 WebFrame* main_frame = webview()->GetMainFrame();
2657 if (!main_frame)
2658 return;
2659
2660 main_frame->SetInViewSourceMode(true);
2661}
2662
[email protected]0666aef2009-05-13 19:48:082663void RenderView::OnEnableIntrinsicWidthChangedMode() {
2664 send_preferred_width_changes_ = true;
2665}
2666
[email protected]80d96fa2009-06-10 22:34:512667void RenderView::OnSetRendererPrefs(const RendererPreferences& renderer_prefs) {
2668 renderer_preferences_ = renderer_prefs;
[email protected]6e282c92009-07-24 01:19:372669 UpdateFontRenderingFromRendererPrefs();
[email protected]80d96fa2009-06-10 22:34:512670}
2671
[email protected]581b87eb2009-07-23 23:06:562672void RenderView::OnMediaPlayerActionAt(int x,
2673 int y,
2674 const MediaPlayerAction& action) {
2675 if (!webview())
2676 return;
2677
2678 webview()->MediaPlayerActionAt(x, y, action);
2679}
2680
initial.commit09911bf2008-07-26 23:55:292681void RenderView::OnUpdateBackForwardListCount(int back_list_count,
2682 int forward_list_count) {
2683 history_back_list_count_ = back_list_count;
2684 history_forward_list_count_ = forward_list_count;
2685}
2686
[email protected]266eb6f2008-09-30 23:56:502687void RenderView::OnGetAccessibilityInfo(
[email protected]6a983b42009-03-20 20:12:252688 const webkit_glue::WebAccessibility::InParams& in_params,
2689 webkit_glue::WebAccessibility::OutParams* out_params) {
[email protected]6c8afae52009-01-22 02:24:572690#if defined(OS_WIN)
[email protected]6a983b42009-03-20 20:12:252691 if (!web_accessibility_manager_.get()) {
2692 web_accessibility_manager_.reset(
2693 webkit_glue::WebAccessibilityManager::Create());
2694 }
[email protected]266eb6f2008-09-30 23:56:502695
[email protected]6a983b42009-03-20 20:12:252696 if (!web_accessibility_manager_->GetAccObjInfo(webview(), in_params,
2697 out_params)) {
[email protected]266eb6f2008-09-30 23:56:502698 return;
2699 }
[email protected]6c8afae52009-01-22 02:24:572700#else // defined(OS_WIN)
2701 // TODO(port): accessibility not yet implemented
2702 NOTIMPLEMENTED();
2703#endif
[email protected]266eb6f2008-09-30 23:56:502704}
2705
[email protected]6a983b42009-03-20 20:12:252706void RenderView::OnClearAccessibilityInfo(int acc_obj_id, bool clear_all) {
[email protected]6c8afae52009-01-22 02:24:572707#if defined(OS_WIN)
[email protected]6a983b42009-03-20 20:12:252708 if (!web_accessibility_manager_.get()) {
[email protected]266eb6f2008-09-30 23:56:502709 // If accessibility is not activated, ignore clearing message.
2710 return;
2711 }
[email protected]e846d0d2009-05-20 00:53:062712
[email protected]6a983b42009-03-20 20:12:252713 if (!web_accessibility_manager_->ClearAccObjMap(acc_obj_id, clear_all))
[email protected]266eb6f2008-09-30 23:56:502714 return;
[email protected]e846d0d2009-05-20 00:53:062715
[email protected]6c8afae52009-01-22 02:24:572716#else // defined(OS_WIN)
2717 // TODO(port): accessibility not yet implemented
2718 NOTIMPLEMENTED();
2719#endif
[email protected]266eb6f2008-09-30 23:56:502720}
2721
initial.commit09911bf2008-07-26 23:55:292722void RenderView::OnGetAllSavableResourceLinksForCurrentPage(
2723 const GURL& page_url) {
2724 // Prepare list to storage all savable resource links.
2725 std::vector<GURL> resources_list;
2726 std::vector<GURL> referrers_list;
2727 std::vector<GURL> frames_list;
2728 webkit_glue::SavableResourcesResult result(&resources_list,
2729 &referrers_list,
2730 &frames_list);
2731
2732 if (!webkit_glue::GetAllSavableResourceLinksForCurrentPage(webview(),
2733 page_url,
2734 &result)) {
2735 // If something is wrong when collecting all savable resource links,
2736 // send empty list to embedder(browser) to tell it failed.
2737 referrers_list.clear();
2738 resources_list.clear();
2739 frames_list.clear();
2740 }
2741
2742 // Send result of all savable resource links to embedder.
2743 Send(new ViewHostMsg_SendCurrentPageAllSavableResourceLinks(routing_id_,
2744 resources_list,
2745 referrers_list,
2746 frames_list));
2747}
2748
2749void RenderView::OnGetSerializedHtmlDataForCurrentPageWithLocalLinks(
[email protected]f6b48532009-02-12 01:56:322750 const std::vector<GURL>& links,
[email protected]fde6714d12009-02-18 22:39:312751 const std::vector<FilePath>& local_paths,
2752 const FilePath& local_directory_name) {
initial.commit09911bf2008-07-26 23:55:292753 webkit_glue::DomSerializer dom_serializer(webview()->GetMainFrame(),
2754 true,
2755 this,
2756 links,
2757 local_paths,
2758 local_directory_name);
2759 dom_serializer.SerializeDom();
2760}
2761
2762void RenderView::DidSerializeDataForFrame(const GURL& frame_url,
2763 const std::string& data, PageSavingSerializationStatus status) {
2764 Send(new ViewHostMsg_SendSerializedHtmlData(routing_id_,
2765 frame_url, data, static_cast<int32>(status)));
2766}
2767
[email protected]04b4a6c2008-08-02 00:44:472768void RenderView::OnMsgShouldClose() {
initial.commit09911bf2008-07-26 23:55:292769 bool should_close = webview()->ShouldClose();
[email protected]04b4a6c2008-08-02 00:44:472770 Send(new ViewHostMsg_ShouldClose_ACK(routing_id_, should_close));
initial.commit09911bf2008-07-26 23:55:292771}
2772
[email protected]eb6b87a2009-07-24 15:57:392773void RenderView::OnClosePage(const ViewMsg_ClosePage_Params& params) {
initial.commit09911bf2008-07-26 23:55:292774 // TODO(creis): We'd rather use webview()->Close() here, but that currently
2775 // sets the WebView's delegate_ to NULL, preventing any JavaScript dialogs
2776 // in the onunload handler from appearing. For now, we're bypassing that and
2777 // calling the FrameLoader's CloseURL method directly. This should be
2778 // revisited to avoid having two ways to close a page. Having a single way
2779 // to close that can run onunload is also useful for fixing
2780 // http://b/issue?id=753080.
2781 WebFrame* main_frame = webview()->GetMainFrame();
[email protected]7a9b51f2009-06-29 21:28:292782 if (main_frame) {
2783 const GURL& url = main_frame->GetURL();
2784 // TODO(davemoore) this code should be removed once WillCloseFrame() gets
2785 // called when a page is destroyed. DumpLoadHistograms() is safe to call
2786 // multiple times for the same frame, but it will simplify things.
[email protected]eb6b87a2009-07-24 15:57:392787 if (url.SchemeIs(chrome::kHttpScheme) || url.SchemeIs(chrome::kHttpsScheme))
[email protected]7a9b51f2009-06-29 21:28:292788 DumpLoadHistograms();
initial.commit09911bf2008-07-26 23:55:292789 main_frame->ClosePage();
[email protected]7a9b51f2009-06-29 21:28:292790 }
initial.commit09911bf2008-07-26 23:55:292791
[email protected]eb6b87a2009-07-24 15:57:392792 // Just echo back the params in the ACK.
2793 Send(new ViewHostMsg_ClosePage_ACK(routing_id_, params));
initial.commit09911bf2008-07-26 23:55:292794}
2795
2796void RenderView::OnThemeChanged() {
[email protected]6c8afae52009-01-22 02:24:572797#if defined(OS_WIN)
initial.commit09911bf2008-07-26 23:55:292798 gfx::NativeTheme::instance()->CloseHandles();
2799 gfx::Rect view_rect(0, 0, size_.width(), size_.height());
[email protected]4873c7d2009-07-16 06:36:282800 didInvalidateRect(view_rect);
[email protected]6c8afae52009-01-22 02:24:572801#else // defined(OS_WIN)
2802 // TODO(port): we don't support theming on non-Windows platforms yet
2803 NOTIMPLEMENTED();
2804#endif
initial.commit09911bf2008-07-26 23:55:292805}
2806
[email protected]f46aff62008-10-16 07:58:052807void RenderView::DidAddHistoryItem() {
[email protected]f8901082008-10-31 23:34:032808 // We don't want to update the history length for the start page
2809 // navigation.
2810 WebFrame* main_frame = webview()->GetMainFrame();
2811 DCHECK(main_frame != NULL);
2812
2813 WebDataSource* ds = main_frame->GetDataSource();
2814 DCHECK(ds != NULL);
2815
[email protected]daa8c58e2009-06-15 17:21:102816 NavigationState* navigation_state = NavigationState::FromDataSource(ds);
[email protected]78a3a6f2009-07-02 16:15:012817 DCHECK(navigation_state);
[email protected]daa8c58e2009-06-15 17:21:102818 if (navigation_state->transition_type() == PageTransition::START_PAGE)
[email protected]f8901082008-10-31 23:34:032819 return;
2820
[email protected]f46aff62008-10-16 07:58:052821 history_back_list_count_++;
2822 history_forward_list_count_ = 0;
2823}
2824
[email protected]28790922009-03-09 19:48:372825void RenderView::OnMessageFromExternalHost(const std::string& message,
2826 const std::string& origin,
2827 const std::string& target) {
[email protected]3ac14a052008-08-15 21:22:152828 if (message.empty())
2829 return;
2830
[email protected]28790922009-03-09 19:48:372831 external_host_bindings_.ForwardMessageFromExternalHost(message, origin,
2832 target);
[email protected]3ac14a052008-08-15 21:22:152833}
2834
[email protected]0aa55312008-10-17 21:53:082835void RenderView::OnDisassociateFromPopupCount() {
2836 if (decrement_shared_popup_at_destruction_)
2837 shared_popup_counter_->data--;
2838 shared_popup_counter_ = new SharedRenderViewCounter(0);
2839 decrement_shared_popup_at_destruction_ = false;
2840}
2841
[email protected]15d79e12009-08-02 19:23:452842bool RenderView::MaybeLoadAlternateErrorPage(WebFrame* frame,
2843 const WebURLError& error,
2844 bool replace) {
2845 // We only show alternate error pages in the main frame. They are
2846 // intended to assist the user when navigating, so there is not much
2847 // value in showing them for failed subframes. Ideally, we would be
2848 // able to use the TYPED transition type for this, but that flag is
2849 // not preserved across page reloads.
2850 if (frame->GetParent())
2851 return false;
2852
2853 // Use the alternate error page service if this is a DNS failure or
2854 // connection failure. ERR_CONNECTION_FAILED can be dropped once we no
2855 // longer use winhttp.
2856 int ec = error.reason;
2857 if (ec != net::ERR_NAME_NOT_RESOLVED &&
2858 ec != net::ERR_CONNECTION_FAILED &&
2859 ec != net::ERR_CONNECTION_REFUSED &&
2860 ec != net::ERR_ADDRESS_UNREACHABLE &&
2861 ec != net::ERR_TIMED_OUT)
2862 return false;
2863
2864 const GURL& error_page_url = GetAlternateErrorPageURL(error.unreachableURL,
2865 ec == net::ERR_NAME_NOT_RESOLVED ? WebViewDelegate::DNS_ERROR
2866 : WebViewDelegate::CONNECTION_ERROR);
2867 if (!error_page_url.is_valid())
2868 return false;
2869
2870 // Load an empty page first so there is an immediate response to the error,
2871 // and then kick off a request for the alternate error page.
2872 frame->LoadHTMLString(std::string(),
2873 GURL(kUnreachableWebDataURL),
2874 error.unreachableURL,
2875 replace);
2876
2877 // Now, create a fetcher for the error page and associate it with the data
2878 // source we just created via the LoadHTMLString call. That way if another
2879 // navigation occurs, the fetcher will get destroyed.
2880 NavigationState* navigation_state =
2881 NavigationState::FromDataSource(frame->GetProvisionalDataSource());
2882 navigation_state->set_alt_error_page_fetcher(
2883 new AltErrorPageResourceFetcher(
2884 error_page_url, frame, error,
2885 NewCallback(this, &RenderView::AltErrorPageFinished)));
2886 return true;
2887}
2888
initial.commit09911bf2008-07-26 23:55:292889std::string RenderView::GetAltHTMLForTemplate(
2890 const DictionaryValue& error_strings, int template_resource_id) const {
2891 const StringPiece template_html(
2892 ResourceBundle::GetSharedInstance().GetRawDataResource(
2893 template_resource_id));
2894
2895 if (template_html.empty()) {
2896 NOTREACHED() << "unable to load template. ID: " << template_resource_id;
2897 return "";
2898 }
[email protected]7cd22a52009-07-14 00:40:252899
initial.commit09911bf2008-07-26 23:55:292900 // "t" is the id of the templates root node.
[email protected]7cd22a52009-07-14 00:40:252901 return jstemplate_builder::GetTemplatesHtml(
initial.commit09911bf2008-07-26 23:55:292902 template_html, &error_strings, "t");
2903}
[email protected]0e79b9e2009-02-13 04:20:482904
[email protected]15d79e12009-08-02 19:23:452905void RenderView::AltErrorPageFinished(WebFrame* frame,
2906 const WebURLError& original_error,
2907 const std::string& html) {
2908 // Here, we replace the blank page we loaded previously.
2909 LoadNavigationErrorPage(frame, WebURLRequest(), original_error, html, true);
2910}
2911
[email protected]30f75e62009-02-25 22:01:002912void RenderView::OnMoveOrResizeStarted() {
2913 if (webview())
2914 webview()->HideAutofillPopup();
2915}
2916
[email protected]30f75e62009-02-25 22:01:002917void RenderView::OnResize(const gfx::Size& new_size,
2918 const gfx::Rect& resizer_rect) {
2919 if (webview())
2920 webview()->HideAutofillPopup();
2921 RenderWidget::OnResize(new_size, resizer_rect);
2922}
[email protected]0aa477bd2009-03-23 22:21:432923
[email protected]05d478752009-04-08 23:38:162924void RenderView::OnClearFocusedNode() {
2925 if (webview())
2926 webview()->ClearFocusedNode();
2927}
2928
[email protected]699ab0d2009-04-23 23:19:142929void RenderView::OnSetBackground(const SkBitmap& background) {
2930 if (webview())
2931 webview()->SetIsTransparent(!background.empty());
2932
2933 SetBackground(background);
2934}
2935
[email protected]8c66c5a2009-07-22 17:26:342936void RenderView::OnSetActive(bool active) {
2937 if (webview())
2938 webview()->SetActive(active);
2939}
2940
[email protected]309d7a282009-03-24 09:18:272941void RenderView::SendExtensionRequest(const std::string& name,
2942 const std::string& args,
[email protected]c6619182009-05-12 14:59:322943 int request_id,
[email protected]2f25d7b92009-06-10 00:06:472944 bool has_callback) {
[email protected]c6619182009-05-12 14:59:322945 Send(new ViewHostMsg_ExtensionRequest(routing_id_, name, args, request_id,
[email protected]2f25d7b92009-06-10 00:06:472946 has_callback));
[email protected]309d7a282009-03-24 09:18:272947}
2948
[email protected]c6619182009-05-12 14:59:322949void RenderView::OnExtensionResponse(int request_id,
2950 bool success,
2951 const std::string& response,
2952 const std::string& error) {
[email protected]0f6053962009-07-09 19:26:352953 ExtensionProcessBindings::HandleResponse(
2954 request_id, success, response, error);
[email protected]309d7a282009-03-24 09:18:272955}
[email protected]c20210e62009-04-03 21:39:262956
[email protected]7120f132009-07-20 21:05:372957void RenderView::OnExtensionMessageInvoke(const std::string& function_name,
2958 const ListValue& args) {
2959 RendererExtensionBindings::Invoke(function_name, args, this);
2960}
2961
[email protected]e7e4f3c2009-04-21 15:24:082962// Dump all load time histograms.
[email protected]c20210e62009-04-03 21:39:262963//
[email protected]7a9b51f2009-06-29 21:28:292964// There are 13 histograms measuring various times.
[email protected]c20210e62009-04-03 21:39:262965// The time points we keep are
2966// request: time document was requested by user
2967// start: time load of document started
[email protected]a2f6bc112009-06-27 16:27:252968// commit: time load of document started
[email protected]7a9b51f2009-06-29 21:28:292969// finish_document: main document loaded, before onload()
[email protected]c20210e62009-04-03 21:39:262970// finish: after onload() and all resources are loaded
[email protected]7a9b51f2009-06-29 21:28:292971// first_paint: first paint performed
2972// first_paint_after_load: first paint performed after load is finished
2973// begin: request if it was user requested, start otherwise
2974//
[email protected]c20210e62009-04-03 21:39:262975// The times that we histogram are
[email protected]a2f6bc112009-06-27 16:27:252976// request->start,
[email protected]7a9b51f2009-06-29 21:28:292977// start->commit,
2978// commit->finish_document,
2979// finish_document->finish,
2980// begin->commit,
2981// begin->finishDoc,
2982// begin->finish,
2983// begin->first_paint,
2984// begin->first_paint_after_load
2985// commit->finishDoc,
2986// commit->first_paint,
2987// commit->first_paint_after_load,
2988// finish->first_paint_after_load,
[email protected]c20210e62009-04-03 21:39:262989//
[email protected]e7e4f3c2009-04-21 15:24:082990// It's possible for the request time not to be set, if a client
2991// redirect had been done (the user never requested the page)
2992// Also, it's possible to load a page without ever laying it out
[email protected]7a9b51f2009-06-29 21:28:292993// so first_paint and first_paint_after_load can be 0.
[email protected]c20210e62009-04-03 21:39:262994void RenderView::DumpLoadHistograms() const {
2995 WebFrame* main_frame = webview()->GetMainFrame();
[email protected]ed3fb032009-06-16 19:50:562996 NavigationState* navigation_state =
2997 NavigationState::FromDataSource(main_frame->GetDataSource());
[email protected]7a9b51f2009-06-29 21:28:292998 Time finish = navigation_state->finish_load_time();
[email protected]ed3fb032009-06-16 19:50:562999
[email protected]7a9b51f2009-06-29 21:28:293000 // If we've already dumped or we haven't finished loading, do nothing.
3001 if (navigation_state->load_histograms_recorded() || finish.is_null())
3002 return;
[email protected]ed3fb032009-06-16 19:50:563003
[email protected]7a9b51f2009-06-29 21:28:293004 Time request = navigation_state->request_time();
3005 Time start = navigation_state->start_load_time();
3006 Time commit = navigation_state->commit_load_time();
3007 Time finish_doc = navigation_state->finish_document_load_time();
3008 Time first_paint = navigation_state->first_paint_time();
3009 Time first_paint_after_load =
3010 navigation_state->first_paint_after_load_time();
[email protected]c20210e62009-04-03 21:39:263011
[email protected]7a9b51f2009-06-29 21:28:293012 Time begin;
3013 // Client side redirects will have no request time.
3014 if (request.is_null()) {
3015 begin = start;
3016 } else {
3017 begin = request;
3018 UMA_HISTOGRAM_MEDIUM_TIMES("Renderer4.RequestToStart", start - request);
[email protected]e7e4f3c2009-04-21 15:24:083019 }
[email protected]7a9b51f2009-06-29 21:28:293020 UMA_HISTOGRAM_MEDIUM_TIMES("Renderer4.StartToCommit", commit - start);
3021 UMA_HISTOGRAM_MEDIUM_TIMES(
3022 "Renderer4.CommitToFinishDoc", finish_doc - commit);
3023 UMA_HISTOGRAM_MEDIUM_TIMES(
3024 "Renderer4.FinishDocToFinish", finish - finish_doc);
3025
3026 UMA_HISTOGRAM_MEDIUM_TIMES("Renderer4.BeginToCommit", commit - begin);
3027 UMA_HISTOGRAM_MEDIUM_TIMES("Renderer4.BeginToFinishDoc", finish_doc - begin);
[email protected]e695fbd62009-06-30 16:31:543028
3029 static const TimeDelta kBeginToFinishMin(TimeDelta::FromMilliseconds(10));
3030 static const TimeDelta kBeginToFinishMax(TimeDelta::FromMinutes(10));
3031 static const size_t kBeginToFinishBucketCount(100);
3032
3033 UMA_HISTOGRAM_CUSTOM_TIMES("Renderer4.BeginToFinish",
3034 finish - begin, kBeginToFinishMin,
3035 kBeginToFinishMax, kBeginToFinishBucketCount);
[email protected]0a32257a2009-07-09 18:10:413036 UMA_HISTOGRAM_CUSTOM_TIMES("Renderer4.StartToFinish",
3037 finish - start, kBeginToFinishMin,
3038 kBeginToFinishMax, kBeginToFinishBucketCount);
3039 if (!request.is_null())
3040 UMA_HISTOGRAM_CUSTOM_TIMES("Renderer4.RequestToFinish",
3041 finish - request, kBeginToFinishMin,
3042 kBeginToFinishMax, kBeginToFinishBucketCount);
[email protected]e695fbd62009-06-30 16:31:543043
[email protected]36285b52009-06-30 19:10:003044 static bool use_dns_histogram(FieldTrialList::Find("DnsImpact") &&
3045 !FieldTrialList::Find("DnsImpact")->group_name().empty());
[email protected]0a32257a2009-07-09 18:10:413046 if (use_dns_histogram) {
[email protected]36285b52009-06-30 19:10:003047 UMA_HISTOGRAM_CUSTOM_TIMES(
3048 FieldTrial::MakeName("Renderer4.BeginToFinish", "DnsImpact").data(),
3049 finish - begin, kBeginToFinishMin,
3050 kBeginToFinishMax, kBeginToFinishBucketCount);
[email protected]0a32257a2009-07-09 18:10:413051 UMA_HISTOGRAM_CUSTOM_TIMES(
3052 FieldTrial::MakeName("Renderer4.StartToFinish", "DnsImpact").data(),
3053 finish - start, kBeginToFinishMin,
3054 kBeginToFinishMax, kBeginToFinishBucketCount);
3055 if (!request.is_null())
3056 UMA_HISTOGRAM_CUSTOM_TIMES(
3057 FieldTrial::MakeName("Renderer4.RequestToFinish", "DnsImpact").data(),
3058 finish - request, kBeginToFinishMin,
3059 kBeginToFinishMax, kBeginToFinishBucketCount);
3060 }
[email protected]e695fbd62009-06-30 16:31:543061
[email protected]36285b52009-06-30 19:10:003062 static bool use_sdch_histogram(FieldTrialList::Find("GlobalSdch") &&
3063 !FieldTrialList::Find("GlobalSdch")->group_name().empty());
[email protected]0a32257a2009-07-09 18:10:413064 if (use_sdch_histogram) {
[email protected]36285b52009-06-30 19:10:003065 UMA_HISTOGRAM_CUSTOM_TIMES(
3066 FieldTrial::MakeName("Renderer4.BeginToFinish", "GlobalSdch").data(),
3067 finish - begin, kBeginToFinishMin,
3068 kBeginToFinishMax, kBeginToFinishBucketCount);
[email protected]0a32257a2009-07-09 18:10:413069 UMA_HISTOGRAM_CUSTOM_TIMES(
3070 FieldTrial::MakeName("Renderer4.StartToFinish", "GlobalSdch").data(),
3071 finish - start, kBeginToFinishMin,
3072 kBeginToFinishMax, kBeginToFinishBucketCount);
3073 if (!request.is_null())
3074 UMA_HISTOGRAM_CUSTOM_TIMES(
3075 FieldTrial::MakeName("Renderer4.RequestToFinish",
3076 "GlobalSdch").data(),
3077 finish - request, kBeginToFinishMin,
3078 kBeginToFinishMax, kBeginToFinishBucketCount);
3079 }
[email protected]7a9b51f2009-06-29 21:28:293080
[email protected]5fff93f2009-08-02 04:27:343081 static bool use_socket_late_binding_histogram =
3082 FieldTrialList::Find("SocketLateBinding") &&
3083 !FieldTrialList::Find("SocketLateBinding")->group_name().empty();
3084 if (use_socket_late_binding_histogram) {
3085 UMA_HISTOGRAM_CUSTOM_TIMES(
3086 FieldTrial::MakeName("Renderer4.BeginToFinish",
3087 "SocketLateBinding").data(),
3088 finish - begin, kBeginToFinishMin,
3089 kBeginToFinishMax, kBeginToFinishBucketCount);
3090 UMA_HISTOGRAM_CUSTOM_TIMES(
3091 FieldTrial::MakeName("Renderer4.StartToFinish",
3092 "SocketLateBinding").data(),
3093 finish - start, kBeginToFinishMin,
3094 kBeginToFinishMax, kBeginToFinishBucketCount);
3095 if (!request.is_null())
3096 UMA_HISTOGRAM_CUSTOM_TIMES(
3097 FieldTrial::MakeName("Renderer4.RequestToFinish",
3098 "SocketLateBinding").data(),
3099 finish - request, kBeginToFinishMin,
3100 kBeginToFinishMax, kBeginToFinishBucketCount);
3101 }
3102
[email protected]7e05f6c42009-07-11 01:50:483103 static bool use_cache_histogram1(FieldTrialList::Find("CacheSize") &&
3104 !FieldTrialList::Find("CacheSize")->group_name().empty());
3105 if (use_cache_histogram1)
3106 UMA_HISTOGRAM_CUSTOM_TIMES(
3107 FieldTrial::MakeName("Renderer4.StartToFinish", "CacheSize").data(),
3108 finish - start, kBeginToFinishMin,
3109 kBeginToFinishMax, kBeginToFinishBucketCount);
3110
3111 static bool use_cache_histogram2(FieldTrialList::Find("NewEviction") &&
3112 !FieldTrialList::Find("NewEviction")->group_name().empty());
3113 if (use_cache_histogram2)
3114 UMA_HISTOGRAM_CUSTOM_TIMES(
3115 FieldTrial::MakeName("Renderer4.StartToFinish", "NewEviction").data(),
3116 finish - start, kBeginToFinishMin,
3117 kBeginToFinishMax, kBeginToFinishBucketCount);
3118
[email protected]7a9b51f2009-06-29 21:28:293119 UMA_HISTOGRAM_MEDIUM_TIMES("Renderer4.CommitToFinish", finish - commit);
3120
3121 if (!first_paint.is_null()) {
3122 UMA_HISTOGRAM_MEDIUM_TIMES(
3123 "Renderer4.BeginToFirstPaint", first_paint - begin);
3124 UMA_HISTOGRAM_MEDIUM_TIMES(
3125 "Renderer4.CommitToFirstPaint", first_paint - commit);
[email protected]c20210e62009-04-03 21:39:263126 }
[email protected]7a9b51f2009-06-29 21:28:293127
3128 if (!first_paint_after_load.is_null()) {
3129 UMA_HISTOGRAM_MEDIUM_TIMES(
3130 "Renderer4.BeginToFirstPaintAfterLoad", first_paint_after_load - begin);
3131 UMA_HISTOGRAM_MEDIUM_TIMES(
3132 "Renderer4.CommitToFirstPaintAfterLoad",
3133 first_paint_after_load - commit);
3134 UMA_HISTOGRAM_MEDIUM_TIMES(
3135 "Renderer4.FinishToFirstPaintAfterLoad",
3136 first_paint_after_load - finish);
3137 }
3138
3139 navigation_state->set_load_histograms_recorded(true);
[email protected]c20210e62009-04-03 21:39:263140}
[email protected]e846d0d2009-05-20 00:53:063141
3142void RenderView::FocusAccessibilityObject(
3143 WebCore::AccessibilityObject* acc_obj) {
3144#if defined(OS_WIN)
3145 if (!web_accessibility_manager_.get()) {
3146 web_accessibility_manager_.reset(
3147 webkit_glue::WebAccessibilityManager::Create());
3148 }
3149
3150 // Retrieve the accessibility object id of the AccessibilityObject.
3151 int acc_obj_id = web_accessibility_manager_->FocusAccObj(acc_obj);
3152
3153 // If id is valid, alert the browser side that an accessibility focus change
3154 // occurred.
3155 if (acc_obj_id >= 0)
3156 Send(new ViewHostMsg_AccessibilityFocusChange(routing_id_, acc_obj_id));
3157
3158#else // defined(OS_WIN)
3159 // TODO(port): accessibility not yet implemented
3160 NOTIMPLEMENTED();
3161#endif
3162}
[email protected]daa8c58e2009-06-15 17:21:103163
[email protected]4873c7d2009-07-16 06:36:283164void RenderView::DidMovePlugin(const WebPluginGeometry& move) {
3165 SchedulePluginMove(move);
3166}
3167
[email protected]daa8c58e2009-06-15 17:21:103168void RenderView::SendPasswordForms(WebFrame* frame) {
3169 std::vector<WebForm> forms;
3170 frame->GetForms(&forms);
3171
3172 std::vector<PasswordForm> password_forms;
3173 for (size_t i = 0; i < forms.size(); ++i) {
3174 const WebForm& form = forms[i];
3175
3176 // Respect autocomplete=off.
3177 if (form.isAutoCompleteEnabled()) {
3178 scoped_ptr<PasswordForm> password_form(
3179 PasswordFormDomManager::CreatePasswordForm(form));
3180 if (password_form.get())
3181 password_forms.push_back(*password_form);
3182 }
3183 }
3184
3185 if (!password_forms.empty())
3186 Send(new ViewHostMsg_PasswordFormsSeen(routing_id_, password_forms));
3187}
[email protected]0fda7272009-06-26 15:49:333188
3189void RenderView::Print(WebFrame* frame, bool script_initiated) {
3190 DCHECK(frame);
3191 if (print_helper_.get() == NULL) {
3192 print_helper_.reset(new PrintWebViewHelper(this));
3193 }
3194 print_helper_->Print(frame, script_initiated);
3195}