blob: 981bfff11c8401779989e5f2e9e3c733b33c1938 [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]010ea08a2009-10-11 20:21:3213#include "app/gfx/native_widget_types.h"
[email protected]a92b8642009-05-05 23:38:5614#include "app/l10n_util.h"
[email protected]37126212009-05-06 02:23:3115#include "app/message_box_flags.h"
[email protected]9929da92009-05-05 02:05:1116#include "app/resource_bundle.h"
initial.commit09911bf2008-07-26 23:55:2917#include "base/command_line.h"
[email protected]bb063b72009-03-27 23:18:5018#include "base/compiler_specific.h"
[email protected]4646f292009-05-20 03:49:0519#include "base/field_trial.h"
[email protected]8380c092009-06-25 17:45:5120#include "base/process_util.h"
[email protected]7b291f92009-08-14 05:43:5321#include "base/singleton.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]8beff0762009-09-29 02:18:3031#include "chrome/common/plugin_messages.h"
[email protected]e09ba552009-02-05 03:26:2932#include "chrome/common/render_messages.h"
[email protected]9b6f40e2009-06-11 15:54:2633#include "chrome/common/renderer_preferences.h"
initial.commit09911bf2008-07-26 23:55:2934#include "chrome/common/thumbnail_score.h"
[email protected]6de74452009-02-25 18:04:5935#include "chrome/common/url_constants.h"
initial.commit09911bf2008-07-26 23:55:2936#include "chrome/renderer/about_handler.h"
[email protected]5fb88962009-04-16 19:03:2537#include "chrome/renderer/audio_message_filter.h"
[email protected]e4ac5df2009-03-17 15:33:1138#include "chrome/renderer/devtools_agent.h"
39#include "chrome/renderer/devtools_client.h"
[email protected]912256b32009-09-18 09:47:3540#include "chrome/renderer/extension_groups.h"
[email protected]f816c012009-06-26 21:48:3241#include "chrome/renderer/extensions/event_bindings.h"
[email protected]0f6053962009-07-09 19:26:3542#include "chrome/renderer/extensions/extension_process_bindings.h"
[email protected]7120f132009-07-20 21:05:3743#include "chrome/renderer/extensions/renderer_extension_bindings.h"
initial.commit09911bf2008-07-26 23:55:2944#include "chrome/renderer/localized_error.h"
[email protected]6f56d482009-02-20 05:02:5645#include "chrome/renderer/media/audio_renderer_impl.h"
[email protected]ed3fb032009-06-16 19:50:5646#include "chrome/renderer/navigation_state.h"
[email protected]90e908552009-10-05 01:40:1247#include "chrome/renderer/notification_provider.h"
[email protected]8beff0762009-09-29 02:18:3048#include "chrome/renderer/plugin_channel_host.h"
[email protected]d81c1e52009-06-03 22:09:5049#include "chrome/renderer/print_web_view_helper.h"
[email protected]39008c02009-02-11 23:59:2550#include "chrome/renderer/render_process.h"
[email protected]0938d3c2009-01-09 20:37:3551#include "chrome/renderer/user_script_slave.h"
initial.commit09911bf2008-07-26 23:55:2952#include "chrome/renderer/visitedlink_slave.h"
[email protected]d439ba072009-10-17 22:32:2953#include "chrome/renderer/webplugin_delegate_pepper.h"
[email protected]ba4b17f2009-02-11 21:32:2954#include "chrome/renderer/webplugin_delegate_proxy.h"
[email protected]eb47a132009-03-04 00:39:5655#include "chrome/renderer/webworker_proxy.h"
[email protected]34ac8f32009-02-22 23:03:2756#include "grit/generated_resources.h"
57#include "grit/renderer_resources.h"
[email protected]f11ca0732009-04-11 00:09:3458#include "net/base/data_url.h"
initial.commit09911bf2008-07-26 23:55:2959#include "net/base/escape.h"
60#include "net/base/net_errors.h"
[email protected]c399a8a2008-11-22 19:38:0061#include "skia/ext/bitmap_platform_device.h"
[email protected]83c9e6552008-12-03 16:22:1062#include "skia/ext/image_operations.h"
[email protected]cc0445f2009-10-13 16:09:0863#include "webkit/api/public/WebAccessibilityObject.h"
[email protected]726985e22009-06-18 21:09:2864#include "webkit/api/public/WebDataSource.h"
[email protected]cd1c89e82009-10-17 03:31:5565#include "webkit/api/public/WebDevToolsAgentClient.h"
[email protected]afdcf5c2009-05-10 20:30:4166#include "webkit/api/public/WebDragData.h"
[email protected]daa8c58e2009-06-15 17:21:1067#include "webkit/api/public/WebForm.h"
[email protected]dd7daa82009-08-10 05:46:4568#include "webkit/api/public/WebFrame.h"
[email protected]ca948a22009-06-25 19:36:1769#include "webkit/api/public/WebHistoryItem.h"
[email protected]581b87eb2009-07-23 23:06:5670#include "webkit/api/public/WebNode.h"
[email protected]afdcf5c2009-05-10 20:30:4171#include "webkit/api/public/WebPoint.h"
72#include "webkit/api/public/WebRect.h"
73#include "webkit/api/public/WebScriptSource.h"
[email protected]91733b62009-09-18 06:21:0974#include "webkit/api/public/WebSecurityOrigin.h"
[email protected]afdcf5c2009-05-10 20:30:4175#include "webkit/api/public/WebSize.h"
[email protected]a1128322009-10-06 18:38:4676#include "webkit/api/public/WebString.h"
[email protected]726985e22009-06-18 21:09:2877#include "webkit/api/public/WebURL.h"
78#include "webkit/api/public/WebURLError.h"
79#include "webkit/api/public/WebURLRequest.h"
80#include "webkit/api/public/WebURLResponse.h"
81#include "webkit/api/public/WebVector.h"
[email protected]f430b5712009-08-21 21:46:3182#include "webkit/appcache/appcache_interfaces.h"
[email protected]ba4b17f2009-02-11 21:32:2983#include "webkit/default_plugin/default_plugin_shared.h"
[email protected]ca948a22009-06-25 19:36:1784#include "webkit/glue/glue_serialize.h"
[email protected]79e37442009-10-09 18:17:4485#include "webkit/glue/glue_util.h"
initial.commit09911bf2008-07-26 23:55:2986#include "webkit/glue/dom_operations.h"
87#include "webkit/glue/dom_serializer.h"
[email protected]f11ca0732009-04-11 00:09:3488#include "webkit/glue/image_decoder.h"
[email protected]8e296bbd2009-07-22 21:37:1789#include "webkit/glue/media/buffered_data_source.h"
[email protected]8380c092009-06-25 17:45:5190#include "webkit/glue/media/simple_data_source.h"
initial.commit09911bf2008-07-26 23:55:2991#include "webkit/glue/password_form.h"
[email protected]ba4b17f2009-02-11 21:32:2992#include "webkit/glue/plugins/plugin_list.h"
[email protected]8a3b7962009-09-04 05:53:2393#include "webkit/glue/plugins/webplugin_delegate_impl.h"
initial.commit09911bf2008-07-26 23:55:2994#include "webkit/glue/searchable_form_data.h"
[email protected]6a983b42009-03-20 20:12:2595#include "webkit/glue/webaccessibilitymanager_impl.h"
initial.commit09911bf2008-07-26 23:55:2996#include "webkit/glue/webdropdata.h"
initial.commit09911bf2008-07-26 23:55:2997#include "webkit/glue/webkit_glue.h"
[email protected]add51772009-06-11 18:25:1798#include "webkit/glue/webmediaplayer_impl.h"
[email protected]f103ab72009-09-02 17:10:5999#include "webkit/glue/webplugin_impl.h"
initial.commit09911bf2008-07-26 23:55:29100
[email protected]6c8afae52009-01-22 02:24:57101#if defined(OS_WIN)
102// TODO(port): these files are currently Windows only because they concern:
[email protected]6c8afae52009-01-22 02:24:57103// * theming
[email protected]86281ad2009-10-07 20:07:17104#include "app/gfx/native_theme_win.h"
[email protected]6c8afae52009-01-22 02:24:57105#endif
106
[email protected]c20210e62009-04-03 21:39:26107using base::Time;
[email protected]e1acf6f2008-10-27 20:43:33108using base::TimeDelta;
[email protected]15d79e12009-08-02 19:23:45109using webkit_glue::AltErrorPageResourceFetcher;
[email protected]51bd36612009-10-20 22:49:47110using webkit_glue::FormFieldValues;
[email protected]b0950a72009-09-29 23:16:17111using webkit_glue::ImageResourceFetcher;
[email protected]ed3fb032009-06-16 19:50:56112using webkit_glue::PasswordForm;
[email protected]daa8c58e2009-06-15 17:21:10113using webkit_glue::PasswordFormDomManager;
114using webkit_glue::SearchableFormData;
[email protected]cc0445f2009-10-13 16:09:08115using WebKit::WebAccessibilityObject;
[email protected]1c83eb42009-09-11 21:08:41116using WebKit::WebColor;
117using WebKit::WebColorName;
[email protected]0dea3ea2009-03-31 23:30:59118using WebKit::WebConsoleMessage;
[email protected]79e37442009-10-09 18:17:44119using WebKit::WebContextMenuData;
[email protected]e6f546c32009-07-01 17:12:55120using WebKit::WebData;
[email protected]726985e22009-06-18 21:09:28121using WebKit::WebDataSource;
[email protected]cd1c89e82009-10-17 03:31:55122using WebKit::WebDevToolsAgentClient;
[email protected]e80c73b2009-04-07 23:24:58123using WebKit::WebDragData;
[email protected]1d9f4132009-09-08 17:29:25124using WebKit::WebDragOperation;
125using WebKit::WebDragOperationsMask;
[email protected]79dbc662009-09-04 05:42:51126using WebKit::WebEditingAction;
[email protected]6069da8c2009-10-20 20:33:49127using WebKit::WebFindOptions;
[email protected]daa8c58e2009-06-15 17:21:10128using WebKit::WebForm;
[email protected]dd7daa82009-08-10 05:46:45129using WebKit::WebFrame;
[email protected]ca948a22009-06-25 19:36:17130using WebKit::WebHistoryItem;
[email protected]3d9689372009-09-10 04:29:17131using WebKit::WebMediaPlayer;
[email protected]952cb702009-10-07 05:50:28132using WebKit::WebMediaPlayerAction;
[email protected]3d9689372009-09-10 04:29:17133using WebKit::WebMediaPlayerClient;
[email protected]4873c7d2009-07-16 06:36:28134using WebKit::WebNavigationPolicy;
[email protected]726985e22009-06-18 21:09:28135using WebKit::WebNavigationType;
[email protected]79dbc662009-09-04 05:42:51136using WebKit::WebNode;
[email protected]3d9689372009-09-10 04:29:17137using WebKit::WebPlugin;
138using WebKit::WebPluginParams;
[email protected]48c9cf2d2009-09-16 16:47:52139using WebKit::WebPoint;
[email protected]88efb7ec2009-07-14 16:32:59140using WebKit::WebPopupMenuInfo;
[email protected]79dbc662009-09-04 05:42:51141using WebKit::WebRange;
[email protected]b3f2b912009-04-09 16:18:52142using WebKit::WebRect;
[email protected]4f999132009-03-31 18:08:40143using WebKit::WebScriptSource;
[email protected]e3d60e5d2009-09-25 21:08:29144using WebKit::WebSecurityOrigin;
[email protected]2fab253a2009-08-17 23:00:59145using WebKit::WebSettings;
[email protected]8649fb32009-06-26 17:51:02146using WebKit::WebSize;
[email protected]726985e22009-06-18 21:09:28147using WebKit::WebString;
[email protected]79dbc662009-09-04 05:42:51148using WebKit::WebTextAffinity;
[email protected]de570ef2009-07-29 18:27:52149using WebKit::WebTextDirection;
[email protected]726985e22009-06-18 21:09:28150using WebKit::WebURL;
151using WebKit::WebURLError;
152using WebKit::WebURLRequest;
153using WebKit::WebURLResponse;
[email protected]4873c7d2009-07-16 06:36:28154using WebKit::WebVector;
[email protected]50ae00ef2009-10-19 05:11:03155using WebKit::WebView;
[email protected]4873c7d2009-07-16 06:36:28156using WebKit::WebWidget;
[email protected]27ba8532009-04-24 20:22:43157using WebKit::WebWorker;
158using WebKit::WebWorkerClient;
[email protected]e1acf6f2008-10-27 20:43:33159
initial.commit09911bf2008-07-26 23:55:29160//-----------------------------------------------------------------------------
161
162// define to write the time necessary for thumbnail/DOM text retrieval,
163// respectively, into the system debug log
164// #define TIME_BITMAP_RETRIEVAL
165// #define TIME_TEXT_RETRIEVAL
166
167// maximum number of characters in the document to index, any text beyond this
168// point will be clipped
[email protected]6c8afae52009-01-22 02:24:57169static const size_t kMaxIndexChars = 65535;
initial.commit09911bf2008-07-26 23:55:29170
171// Size of the thumbnails that we'll generate
[email protected]8b4f4892009-09-04 21:52:37172static const int kThumbnailWidth = 212;
173static const int kThumbnailHeight = 132;
initial.commit09911bf2008-07-26 23:55:29174
175// Delay in milliseconds that we'll wait before capturing the page contents
176// and thumbnail.
177static const int kDelayForCaptureMs = 500;
178
179// Typically, we capture the page data once the page is loaded.
180// Sometimes, the page never finishes to load, preventing the page capture
181// To workaround this problem, we always perform a capture after the following
182// delay.
183static const int kDelayForForcedCaptureMs = 6000;
184
[email protected]81a34412009-01-05 19:17:24185// The default value for RenderView.delay_seconds_for_form_state_sync_, see
186// that variable for more.
187const int kDefaultDelaySecondsForFormStateSync = 5;
initial.commit09911bf2008-07-26 23:55:29188
[email protected]0aa55312008-10-17 21:53:08189// The maximum number of popups that can be spawned from one page.
190static const int kMaximumNumberOfUnacknowledgedPopups = 25;
191
initial.commit09911bf2008-07-26 23:55:29192static const char* const kUnreachableWebDataURL =
[email protected]60e448982009-05-06 04:21:16193 "chrome://chromewebdata/";
initial.commit09911bf2008-07-26 23:55:29194
[email protected]50b691c2008-10-31 19:08:35195static const char* const kBackForwardNavigationScheme = "history";
196
[email protected]726985e22009-06-18 21:09:28197static void GetRedirectChain(WebDataSource* ds, std::vector<GURL>* result) {
198 WebVector<WebURL> urls;
199 ds->redirectChain(urls);
200 result->reserve(urls.size());
201 for (size_t i = 0; i < urls.size(); ++i)
202 result->push_back(urls[i]);
203}
204
initial.commit09911bf2008-07-26 23:55:29205///////////////////////////////////////////////////////////////////////////////
206
[email protected]60c42a8c72009-10-09 04:08:59207int32 RenderView::next_page_id_ = 1;
208
[email protected]2fab253a2009-08-17 23:00:59209RenderView::RenderView(RenderThreadBase* render_thread,
210 const WebPreferences& webkit_preferences)
[email protected]81a34412009-01-05 19:17:24211 : RenderWidget(render_thread, true),
[email protected]81e63782009-02-27 19:35:09212 enabled_bindings_(0),
[email protected]e75cb49e2009-01-05 23:13:21213 target_url_status_(TARGET_NONE),
[email protected]81a34412009-01-05 19:17:24214 is_loading_(false),
[email protected]e75cb49e2009-01-05 23:13:21215 navigation_gesture_(NavigationGestureUnknown),
[email protected]81a34412009-01-05 19:17:24216 page_id_(-1),
217 last_page_id_sent_to_browser_(-1),
218 last_indexed_page_id_(-1),
[email protected]81a34412009-01-05 19:17:24219 opened_by_user_gesture_(true),
[email protected]bb063b72009-03-27 23:18:50220 ALLOW_THIS_IN_INITIALIZER_LIST(method_factory_(this)),
[email protected]e4ac5df2009-03-17 15:33:11221 devtools_agent_(NULL),
222 devtools_client_(NULL),
[email protected]a1128322009-10-06 18:38:46223 file_chooser_completion_(NULL),
[email protected]81a34412009-01-05 19:17:24224 history_back_list_count_(0),
225 history_forward_list_count_(0),
[email protected]81a34412009-01-05 19:17:24226 has_unload_listener_(false),
227 decrement_shared_popup_at_destruction_(false),
[email protected]acca2a1f2009-10-16 03:53:39228 autofill_query_id_(0),
[email protected]81a34412009-01-05 19:17:24229 popup_notification_visible_(false),
[email protected]8922e1f2009-10-03 05:01:26230 spelling_panel_visible_(false),
[email protected]0666aef2009-05-13 19:48:08231 delay_seconds_for_form_state_sync_(kDefaultDelaySecondsForFormStateSync),
[email protected]ab32b16c2009-10-16 14:57:25232 send_preferred_size_changes_(false),
[email protected]b6849bda2009-10-14 23:59:26233 ALLOW_THIS_IN_INITIALIZER_LIST(
234 notification_provider_(new NotificationProvider(this))),
[email protected]5f450e52009-07-28 13:28:11235 determine_page_text_after_loading_stops_(false),
[email protected]7b291f92009-08-14 05:43:53236 view_type_(ViewType::INVALID),
237 browser_window_id_(-1),
[email protected]83dde542009-09-11 20:59:55238 last_top_level_navigation_page_id_(-1),
239#if defined(OS_MACOSX)
240 has_document_tag_(false),
241#endif
[email protected]98324892009-09-09 21:16:05242 document_tag_(0),
[email protected]2fab253a2009-08-17 23:00:59243 webkit_preferences_(webkit_preferences) {
initial.commit09911bf2008-07-26 23:55:29244}
245
246RenderView::~RenderView() {
[email protected]0aa55312008-10-17 21:53:08247 if (decrement_shared_popup_at_destruction_)
248 shared_popup_counter_->data--;
249
[email protected]b0950a72009-09-29 23:16:17250 // Dispose of un-disposed image fetchers.
251 for (ImageResourceFetcherSet::iterator i = image_fetchers_.begin();
252 i != image_fetchers_.end(); ++i) {
253 delete *i;
254 }
255
[email protected]a1128322009-10-06 18:38:46256 // If file chooser is still waiting for answer, dispatch empty answer.
257 if (file_chooser_completion_)
258 file_chooser_completion_->didChooseFile(WebVector<WebString>());
259
[email protected]83dde542009-09-11 20:59:55260#if defined(OS_MACOSX)
[email protected]98324892009-09-09 21:16:05261 // Tell the spellchecker that the document is closed.
[email protected]83dde542009-09-11 20:59:55262 if (has_document_tag_)
263 Send(new ViewHostMsg_DocumentWithTagClosed(routing_id_, document_tag_));
264#endif
[email protected]98324892009-09-09 21:16:05265
[email protected]5fb88962009-04-16 19:03:25266 render_thread_->RemoveFilter(audio_message_filter_);
[email protected]60c42a8c72009-10-09 04:08:59267
268#ifndef NDEBUG
269 // Make sure we are no longer referenced by the ViewMap.
270 ViewMap* views = Singleton<ViewMap>::get();
271 for (ViewMap::iterator it = views->begin(); it != views->end(); ++it)
272 DCHECK_NE(this, it->second) << "Failed to call Close?";
273#endif
274}
275
276/*static*/
277void RenderView::ForEach(RenderViewVisitor* visitor) {
278 ViewMap* views = Singleton<ViewMap>::get();
279 for (ViewMap::iterator it = views->begin(); it != views->end(); ++it) {
280 if (!visitor->Visit(it->second))
281 return;
282 }
283}
284
285/*static*/
286RenderView* RenderView::FromWebView(WebView* webview) {
287 ViewMap* views = Singleton<ViewMap>::get();
288 ViewMap::iterator it = views->find(webview);
289 return it == views->end() ? NULL : it->second;
initial.commit09911bf2008-07-26 23:55:29290}
291
292/*static*/
[email protected]0aa55312008-10-17 21:53:08293RenderView* RenderView::Create(
[email protected]81a34412009-01-05 19:17:24294 RenderThreadBase* render_thread,
[email protected]18bcc3c2009-01-27 21:39:15295 gfx::NativeViewId parent_hwnd,
[email protected]0aa55312008-10-17 21:53:08296 int32 opener_id,
[email protected]80d96fa2009-06-10 22:34:51297 const RendererPreferences& renderer_prefs,
[email protected]0aa55312008-10-17 21:53:08298 const WebPreferences& webkit_prefs,
299 SharedRenderViewCounter* counter,
300 int32 routing_id) {
initial.commit09911bf2008-07-26 23:55:29301 DCHECK(routing_id != MSG_ROUTING_NONE);
[email protected]2fab253a2009-08-17 23:00:59302 scoped_refptr<RenderView> view = new RenderView(render_thread, webkit_prefs);
initial.commit09911bf2008-07-26 23:55:29303 view->Init(parent_hwnd,
initial.commit09911bf2008-07-26 23:55:29304 opener_id,
[email protected]80d96fa2009-06-10 22:34:51305 renderer_prefs,
[email protected]0aa55312008-10-17 21:53:08306 counter,
initial.commit09911bf2008-07-26 23:55:29307 routing_id); // adds reference
308 return view;
309}
310
311/*static*/
312void RenderView::SetNextPageID(int32 next_page_id) {
313 // This method should only be called during process startup, and the given
314 // page id had better not exceed our current next page id!
[email protected]4646f292009-05-20 03:49:05315 DCHECK_EQ(next_page_id_, 1);
initial.commit09911bf2008-07-26 23:55:29316 DCHECK(next_page_id >= next_page_id_);
317 next_page_id_ = next_page_id;
318}
319
[email protected]1dbafaf72009-09-23 19:43:56320void RenderView::UserMetricsRecordAction(const std::wstring& action) {
321 Send(new ViewHostMsg_UserMetricsRecordAction(routing_id_, action));
322}
323
[email protected]a3a8fb6d2009-10-22 20:12:51324void RenderView::PluginCrashed(const FilePath& plugin_path) {
325 Send(new ViewHostMsg_CrashedPlugin(routing_id_, plugin_path));
initial.commit09911bf2008-07-26 23:55:29326}
327
[email protected]18bcc3c2009-01-27 21:39:15328void RenderView::Init(gfx::NativeViewId parent_hwnd,
initial.commit09911bf2008-07-26 23:55:29329 int32 opener_id,
[email protected]80d96fa2009-06-10 22:34:51330 const RendererPreferences& renderer_prefs,
[email protected]0aa55312008-10-17 21:53:08331 SharedRenderViewCounter* counter,
initial.commit09911bf2008-07-26 23:55:29332 int32 routing_id) {
333 DCHECK(!webview());
334
335 if (opener_id != MSG_ROUTING_NONE)
336 opener_id_ = opener_id;
337
[email protected]0aa55312008-10-17 21:53:08338 if (counter) {
339 shared_popup_counter_ = counter;
340 shared_popup_counter_->data++;
341 decrement_shared_popup_at_destruction_ = true;
342 } else {
343 shared_popup_counter_ = new SharedRenderViewCounter(0);
344 decrement_shared_popup_at_destruction_ = false;
345 }
346
[email protected]58bfc6b2009-06-24 09:45:02347 devtools_agent_.reset(new DevToolsAgent(routing_id, this));
[email protected]9b9d7282009-04-08 14:13:04348
[email protected]50ae00ef2009-10-19 05:11:03349 webwidget_ = WebView::create(this);
[email protected]60c42a8c72009-10-09 04:08:59350 Singleton<ViewMap>::get()->insert(std::make_pair(webview(), this));
[email protected]2fab253a2009-08-17 23:00:59351 webkit_preferences_.Apply(webview());
[email protected]b4bb2502009-10-01 22:35:27352 webview()->initializeMainFrame(this);
initial.commit09911bf2008-07-26 23:55:29353
[email protected]d3ba77272009-09-03 00:06:09354 OnSetRendererPrefs(renderer_prefs);
355
initial.commit09911bf2008-07-26 23:55:29356 routing_id_ = routing_id;
[email protected]81a34412009-01-05 19:17:24357 render_thread_->AddRoute(routing_id_, this);
initial.commit09911bf2008-07-26 23:55:29358 // Take a reference on behalf of the RenderThread. This will be balanced
359 // when we receive ViewMsg_Close.
360 AddRef();
361
362 // If this is a popup, we must wait for the CreatingNew_ACK message before
363 // completing initialization. Otherwise, we can finish it now.
364 if (opener_id == MSG_ROUTING_NONE) {
365 did_show_ = true;
366 CompleteInit(parent_hwnd);
367 }
368
369 host_window_ = parent_hwnd;
initial.commit09911bf2008-07-26 23:55:29370
[email protected]58bfc6b2009-06-24 09:45:02371 const CommandLine& command_line = *CommandLine::ForCurrentProcess();
[email protected]81e63782009-02-27 19:35:09372 if (command_line.HasSwitch(switches::kDomAutomationController))
373 enabled_bindings_ |= BindingsPolicy::DOM_AUTOMATION;
initial.commit09911bf2008-07-26 23:55:29374
[email protected]5fb88962009-04-16 19:03:25375 audio_message_filter_ = new AudioMessageFilter(routing_id_);
376 render_thread_->AddFilter(audio_message_filter_);
initial.commit09911bf2008-07-26 23:55:29377}
378
379void RenderView::OnMessageReceived(const IPC::Message& message) {
[email protected]26aa0482009-09-30 16:55:27380 WebFrame* main_frame = webview() ? webview()->mainFrame() : NULL;
[email protected]a9f607e2009-10-23 19:59:27381 if (main_frame)
382 child_process_logging::SetActiveURL(main_frame->url());
[email protected]f8b6b6f2009-03-10 16:48:26383
[email protected]b2abac72009-02-26 12:39:28384 // If this is developer tools renderer intercept tools messages first.
[email protected]e4ac5df2009-03-17 15:33:11385 if (devtools_client_.get() && devtools_client_->OnMessageReceived(message))
[email protected]b2abac72009-02-26 12:39:28386 return;
[email protected]b4b967e2009-04-22 11:33:05387 if (devtools_agent_.get() && devtools_agent_->OnMessageReceived(message))
388 return;
[email protected]b6849bda2009-10-14 23:59:26389 if (notification_provider_->OnMessageReceived(message))
390 return;
[email protected]b2abac72009-02-26 12:39:28391
initial.commit09911bf2008-07-26 23:55:29392 IPC_BEGIN_MESSAGE_MAP(RenderView, message)
initial.commit09911bf2008-07-26 23:55:29393 IPC_MESSAGE_HANDLER(ViewMsg_CaptureThumbnail, SendThumbnail)
initial.commit09911bf2008-07-26 23:55:29394 IPC_MESSAGE_HANDLER(ViewMsg_PrintPages, OnPrintPages)
[email protected]82270452009-06-19 15:58:01395 IPC_MESSAGE_HANDLER(ViewMsg_PrintingDone, OnPrintingDone)
initial.commit09911bf2008-07-26 23:55:29396 IPC_MESSAGE_HANDLER(ViewMsg_Navigate, OnNavigate)
397 IPC_MESSAGE_HANDLER(ViewMsg_Stop, OnStop)
398 IPC_MESSAGE_HANDLER(ViewMsg_LoadAlternateHTMLText, OnLoadAlternateHTMLText)
399 IPC_MESSAGE_HANDLER(ViewMsg_StopFinding, OnStopFinding)
400 IPC_MESSAGE_HANDLER(ViewMsg_Undo, OnUndo)
401 IPC_MESSAGE_HANDLER(ViewMsg_Redo, OnRedo)
402 IPC_MESSAGE_HANDLER(ViewMsg_Cut, OnCut)
403 IPC_MESSAGE_HANDLER(ViewMsg_Copy, OnCopy)
[email protected]c0cc3092009-09-12 08:27:27404#if defined(OS_MACOSX)
[email protected]a954bf72009-09-12 07:30:35405 IPC_MESSAGE_HANDLER(ViewMsg_CopyToFindPboard, OnCopyToFindPboard)
[email protected]c0cc3092009-09-12 08:27:27406#endif
initial.commit09911bf2008-07-26 23:55:29407 IPC_MESSAGE_HANDLER(ViewMsg_Paste, OnPaste)
408 IPC_MESSAGE_HANDLER(ViewMsg_Replace, OnReplace)
[email protected]98324892009-09-09 21:16:05409 IPC_MESSAGE_HANDLER(ViewMsg_ToggleSpellPanel, OnToggleSpellPanel)
410 IPC_MESSAGE_HANDLER(ViewMsg_AdvanceToNextMisspelling,
411 OnAdvanceToNextMisspelling)
[email protected]bbbd545c2008-12-15 20:18:04412 IPC_MESSAGE_HANDLER(ViewMsg_ToggleSpellCheck, OnToggleSpellCheck)
initial.commit09911bf2008-07-26 23:55:29413 IPC_MESSAGE_HANDLER(ViewMsg_Delete, OnDelete)
414 IPC_MESSAGE_HANDLER(ViewMsg_SelectAll, OnSelectAll)
415 IPC_MESSAGE_HANDLER(ViewMsg_CopyImageAt, OnCopyImageAt)
[email protected]4b59ae602009-06-23 20:58:15416 IPC_MESSAGE_HANDLER(ViewMsg_ExecuteEditCommand, OnExecuteEditCommand)
initial.commit09911bf2008-07-26 23:55:29417 IPC_MESSAGE_HANDLER(ViewMsg_Find, OnFind)
[email protected]5c4266922009-07-10 16:41:27418 IPC_MESSAGE_HANDLER(ViewMsg_DeterminePageText, OnDeterminePageText)
[email protected]630e26b2008-10-14 22:55:17419 IPC_MESSAGE_HANDLER(ViewMsg_Zoom, OnZoom)
initial.commit09911bf2008-07-26 23:55:29420 IPC_MESSAGE_HANDLER(ViewMsg_SetPageEncoding, OnSetPageEncoding)
[email protected]a697f4c2009-09-14 22:30:18421 IPC_MESSAGE_HANDLER(ViewMsg_ResetPageEncodingToDefault,
422 OnResetPageEncodingToDefault)
[email protected]b2abac72009-02-26 12:39:28423 IPC_MESSAGE_HANDLER(ViewMsg_SetupDevToolsClient, OnSetupDevToolsClient)
[email protected]bf5c2ff392009-07-08 16:24:33424 IPC_MESSAGE_HANDLER(ViewMsg_DownloadFavIcon, OnDownloadFavIcon)
initial.commit09911bf2008-07-26 23:55:29425 IPC_MESSAGE_HANDLER(ViewMsg_ScriptEvalRequest, OnScriptEvalRequest)
[email protected]1810e132009-03-24 23:35:48426 IPC_MESSAGE_HANDLER(ViewMsg_CSSInsertRequest, OnCSSInsertRequest)
initial.commit09911bf2008-07-26 23:55:29427 IPC_MESSAGE_HANDLER(ViewMsg_AddMessageToConsole, OnAddMessageToConsole)
initial.commit09911bf2008-07-26 23:55:29428 IPC_MESSAGE_HANDLER(ViewMsg_ReservePageIDRange, OnReservePageIDRange)
initial.commit09911bf2008-07-26 23:55:29429 IPC_MESSAGE_HANDLER(ViewMsg_FormFill, OnFormFill)
430 IPC_MESSAGE_HANDLER(ViewMsg_FillPasswordForm, OnFillPasswordForm)
431 IPC_MESSAGE_HANDLER(ViewMsg_DragTargetDragEnter, OnDragTargetDragEnter)
432 IPC_MESSAGE_HANDLER(ViewMsg_DragTargetDragOver, OnDragTargetDragOver)
433 IPC_MESSAGE_HANDLER(ViewMsg_DragTargetDragLeave, OnDragTargetDragLeave)
434 IPC_MESSAGE_HANDLER(ViewMsg_DragTargetDrop, OnDragTargetDrop)
[email protected]18cb2572008-08-21 20:34:45435 IPC_MESSAGE_HANDLER(ViewMsg_AllowBindings, OnAllowBindings)
initial.commit09911bf2008-07-26 23:55:29436 IPC_MESSAGE_HANDLER(ViewMsg_SetDOMUIProperty, OnSetDOMUIProperty)
[email protected]266eb6f2008-09-30 23:56:50437 IPC_MESSAGE_HANDLER(ViewMsg_DragSourceEndedOrMoved,
438 OnDragSourceEndedOrMoved)
initial.commit09911bf2008-07-26 23:55:29439 IPC_MESSAGE_HANDLER(ViewMsg_DragSourceSystemDragEnded,
440 OnDragSourceSystemDragEnded)
441 IPC_MESSAGE_HANDLER(ViewMsg_SetInitialFocus, OnSetInitialFocus)
442 IPC_MESSAGE_HANDLER(ViewMsg_FindReplyACK, OnFindReplyAck)
443 IPC_MESSAGE_HANDLER(ViewMsg_UpdateTargetURL_ACK, OnUpdateTargetURLAck)
444 IPC_MESSAGE_HANDLER(ViewMsg_UpdateWebPreferences, OnUpdateWebPreferences)
445 IPC_MESSAGE_HANDLER(ViewMsg_SetAltErrorPageURL, OnSetAltErrorPageURL)
446 IPC_MESSAGE_HANDLER(ViewMsg_InstallMissingPlugin, OnInstallMissingPlugin)
447 IPC_MESSAGE_HANDLER(ViewMsg_RunFileChooserResponse, OnFileChooserResponse)
448 IPC_MESSAGE_HANDLER(ViewMsg_EnableViewSourceMode, OnEnableViewSourceMode)
449 IPC_MESSAGE_HANDLER(ViewMsg_UpdateBackForwardListCount,
450 OnUpdateBackForwardListCount)
451 IPC_MESSAGE_HANDLER(ViewMsg_GetAllSavableResourceLinksForCurrentPage,
452 OnGetAllSavableResourceLinksForCurrentPage)
[email protected]f09c7182009-03-10 12:54:04453 IPC_MESSAGE_HANDLER(
454 ViewMsg_GetSerializedHtmlDataForCurrentPageWithLocalLinks,
455 OnGetSerializedHtmlDataForCurrentPageWithLocalLinks)
initial.commit09911bf2008-07-26 23:55:29456 IPC_MESSAGE_HANDLER(ViewMsg_GetApplicationInfo, OnGetApplicationInfo)
[email protected]266eb6f2008-09-30 23:56:50457 IPC_MESSAGE_HANDLER(ViewMsg_GetAccessibilityInfo, OnGetAccessibilityInfo)
458 IPC_MESSAGE_HANDLER(ViewMsg_ClearAccessibilityInfo,
459 OnClearAccessibilityInfo)
initial.commit09911bf2008-07-26 23:55:29460 IPC_MESSAGE_HANDLER(ViewMsg_ShouldClose, OnMsgShouldClose)
461 IPC_MESSAGE_HANDLER(ViewMsg_ClosePage, OnClosePage)
462 IPC_MESSAGE_HANDLER(ViewMsg_ThemeChanged, OnThemeChanged)
[email protected]18cb2572008-08-21 20:34:45463 IPC_MESSAGE_HANDLER(ViewMsg_HandleMessageFromExternalHost,
464 OnMessageFromExternalHost)
[email protected]0aa55312008-10-17 21:53:08465 IPC_MESSAGE_HANDLER(ViewMsg_DisassociateFromPopupCount,
466 OnDisassociateFromPopupCount)
[email protected]842936a2009-10-14 06:00:36467 IPC_MESSAGE_HANDLER(ViewMsg_QueryFormFieldAutofill_ACK,
468 OnQueryFormFieldAutofillAck)
[email protected]2c4410d2009-05-06 23:46:22469 IPC_MESSAGE_HANDLER(ViewMsg_PopupNotificationVisibilityChanged,
470 OnPopupNotificationVisibilityChanged)
[email protected]30f75e62009-02-25 22:01:00471 IPC_MESSAGE_HANDLER(ViewMsg_MoveOrResizeStarted, OnMoveOrResizeStarted)
[email protected]309d7a282009-03-24 09:18:27472 IPC_MESSAGE_HANDLER(ViewMsg_ExtensionResponse, OnExtensionResponse)
[email protected]7120f132009-07-20 21:05:37473 IPC_MESSAGE_HANDLER(ViewMsg_ExtensionMessageInvoke,
474 OnExtensionMessageInvoke)
[email protected]05d478752009-04-08 23:38:16475 IPC_MESSAGE_HANDLER(ViewMsg_ClearFocusedNode, OnClearFocusedNode)
[email protected]699ab0d2009-04-23 23:19:14476 IPC_MESSAGE_HANDLER(ViewMsg_SetBackground, OnSetBackground)
[email protected]ab32b16c2009-10-16 14:57:25477 IPC_MESSAGE_HANDLER(ViewMsg_EnablePreferredSizeChangedMode,
478 OnEnablePreferredSizeChangedMode)
[email protected]80d96fa2009-06-10 22:34:51479 IPC_MESSAGE_HANDLER(ViewMsg_SetRendererPrefs, OnSetRendererPrefs)
[email protected]7b291f92009-08-14 05:43:53480 IPC_MESSAGE_HANDLER(ViewMsg_UpdateBrowserWindowId,
481 OnUpdateBrowserWindowId)
482 IPC_MESSAGE_HANDLER(ViewMsg_NotifyRenderViewType,
483 OnNotifyRendererViewType)
[email protected]581b87eb2009-07-23 23:06:56484 IPC_MESSAGE_HANDLER(ViewMsg_MediaPlayerActionAt, OnMediaPlayerActionAt)
[email protected]8c66c5a2009-07-22 17:26:34485 IPC_MESSAGE_HANDLER(ViewMsg_SetActive, OnSetActive)
[email protected]446705872009-09-10 07:22:48486 IPC_MESSAGE_HANDLER(ViewMsg_SetEditCommandsForNextKeyEvent,
487 OnSetEditCommandsForNextKeyEvent);
[email protected]912256b32009-09-18 09:47:35488 IPC_MESSAGE_HANDLER(ViewMsg_ExecuteCode,
489 OnExecuteCode)
[email protected]634a6f92008-12-01 21:39:31490
initial.commit09911bf2008-07-26 23:55:29491 // Have the super handle all other messages.
492 IPC_MESSAGE_UNHANDLED(RenderWidget::OnMessageReceived(message))
493 IPC_END_MESSAGE_MAP()
494}
495
initial.commit09911bf2008-07-26 23:55:29496void RenderView::SendThumbnail() {
[email protected]26aa0482009-09-30 16:55:27497 WebFrame* main_frame = webview()->mainFrame();
initial.commit09911bf2008-07-26 23:55:29498 if (!main_frame)
499 return;
500
501 // get the URL for this page
[email protected]dd7daa82009-08-10 05:46:45502 GURL url(main_frame->url());
initial.commit09911bf2008-07-26 23:55:29503 if (url.is_empty())
504 return;
505
506 if (size_.IsEmpty())
507 return; // Don't create an empty thumbnail!
508
509 ThumbnailScore score;
510 SkBitmap thumbnail;
[email protected]8649fb32009-06-26 17:51:02511 if (!CaptureThumbnail(webview(), kThumbnailWidth, kThumbnailHeight,
[email protected]b6e4bec2008-11-12 01:17:15512 &thumbnail, &score))
513 return;
514
initial.commit09911bf2008-07-26 23:55:29515 // send the thumbnail message to the browser process
[email protected]674741932009-02-04 23:44:46516 Send(new ViewHostMsg_Thumbnail(routing_id_, url, score, thumbnail));
initial.commit09911bf2008-07-26 23:55:29517}
518
[email protected]068637222009-01-29 16:58:07519void RenderView::OnPrintPages() {
initial.commit09911bf2008-07-26 23:55:29520 DCHECK(webview());
[email protected]aa82249f2009-07-16 17:23:58521 if (webview()) {
522 // If the user has selected text in the currently focused frame we print
523 // only that frame (this makes print selection work for multiple frames).
[email protected]26aa0482009-09-30 16:55:27524 if (webview()->focusedFrame()->hasSelection())
525 Print(webview()->focusedFrame(), false);
[email protected]aa82249f2009-07-16 17:23:58526 else
[email protected]26aa0482009-09-30 16:55:27527 Print(webview()->mainFrame(), false);
[email protected]aa82249f2009-07-16 17:23:58528 }
initial.commit09911bf2008-07-26 23:55:29529}
530
[email protected]82270452009-06-19 15:58:01531void RenderView::OnPrintingDone(int document_cookie, bool success) {
532 // Ignoring document cookie here since only one print job can be outstanding
533 // per renderer and document_cookie is 0 when printing is successful.
534 DCHECK(print_helper_.get());
535 if (print_helper_.get() != NULL) {
536 print_helper_->DidFinishPrinting(success);
537 }
538}
539
initial.commit09911bf2008-07-26 23:55:29540void RenderView::CapturePageInfo(int load_id, bool preliminary_capture) {
541 if (load_id != page_id_)
542 return; // this capture call is no longer relevant due to navigation
543 if (load_id == last_indexed_page_id_)
544 return; // we already indexed this page
545
546 if (!webview())
547 return;
548
[email protected]26aa0482009-09-30 16:55:27549 WebFrame* main_frame = webview()->mainFrame();
initial.commit09911bf2008-07-26 23:55:29550 if (!main_frame)
551 return;
552
553 // Don't index/capture pages that are in view source mode.
[email protected]dd7daa82009-08-10 05:46:45554 if (main_frame->isViewSourceModeEnabled())
initial.commit09911bf2008-07-26 23:55:29555 return;
556
557 // Don't index/capture pages that failed to load. This only checks the top
558 // level frame so the thumbnail may contain a frame that failed to load.
[email protected]dd7daa82009-08-10 05:46:45559 WebDataSource* ds = main_frame->dataSource();
[email protected]726985e22009-06-18 21:09:28560 if (ds && ds->hasUnreachableURL())
initial.commit09911bf2008-07-26 23:55:29561 return;
562
563 if (!preliminary_capture)
564 last_indexed_page_id_ = load_id;
565
566 // get the URL for this page
[email protected]dd7daa82009-08-10 05:46:45567 GURL url(main_frame->url());
initial.commit09911bf2008-07-26 23:55:29568 if (url.is_empty())
569 return;
570
571 // full text
572 std::wstring contents;
573 CaptureText(main_frame, &contents);
574 if (contents.size()) {
575 // Send the text to the browser for indexing.
576 Send(new ViewHostMsg_PageContents(url, load_id, contents));
577 }
578
[email protected]5c4266922009-07-10 16:41:27579 // Send over text content of this page to the browser.
580 if (determine_page_text_after_loading_stops_) {
581 determine_page_text_after_loading_stops_ = false;
582 Send(new ViewMsg_DeterminePageText_Reply(routing_id_, contents));
583 }
584
initial.commit09911bf2008-07-26 23:55:29585 // thumbnail
586 SendThumbnail();
587}
588
589void RenderView::CaptureText(WebFrame* frame, std::wstring* contents) {
590 contents->clear();
591 if (!frame)
592 return;
593
[email protected]0faf0bd92008-09-09 20:53:27594 // Don't index any https pages. People generally don't want their bank
595 // accounts, etc. indexed on their computer, especially since some of these
596 // things are not marked cachable.
597 // TODO(brettw) we may want to consider more elaborate heuristics such as
598 // the cachability of the page. We may also want to consider subframes (this
599 // test will still index subframes if the subframe is SSL).
[email protected]dd7daa82009-08-10 05:46:45600 if (GURL(frame->url()).SchemeIsSecure())
[email protected]0faf0bd92008-09-09 20:53:27601 return;
602
initial.commit09911bf2008-07-26 23:55:29603#ifdef TIME_TEXT_RETRIEVAL
604 double begin = time_util::GetHighResolutionTimeNow();
605#endif
606
607 // get the contents of the frame
[email protected]dd7daa82009-08-10 05:46:45608 *contents = UTF16ToWideHack(frame->contentAsText(kMaxIndexChars));
initial.commit09911bf2008-07-26 23:55:29609
610#ifdef TIME_TEXT_RETRIEVAL
611 double end = time_util::GetHighResolutionTimeNow();
612 char buf[128];
613 sprintf_s(buf, "%d chars retrieved for indexing in %gms\n",
614 contents.size(), (end - begin)*1000);
615 OutputDebugStringA(buf);
616#endif
617
618 // When the contents are clipped to the maximum, we don't want to have a
619 // partial word indexed at the end that might have been clipped. Therefore,
620 // terminate the string at the last space to ensure no words are clipped.
621 if (contents->size() == kMaxIndexChars) {
622 size_t last_space_index = contents->find_last_of(kWhitespaceWide);
623 if (last_space_index == std::wstring::npos)
624 return; // don't index if we got a huge block of text with no spaces
625 contents->resize(last_space_index);
626 }
627}
628
[email protected]8649fb32009-06-26 17:51:02629bool RenderView::CaptureThumbnail(WebView* view,
initial.commit09911bf2008-07-26 23:55:29630 int w,
631 int h,
632 SkBitmap* thumbnail,
633 ThumbnailScore* score) {
634#ifdef TIME_BITMAP_RETRIEVAL
635 double begin = time_util::GetHighResolutionTimeNow();
636#endif
637
[email protected]4873c7d2009-07-16 06:36:28638 view->layout();
639 const WebSize& size = view->size();
[email protected]b6e4bec2008-11-12 01:17:15640
[email protected]8649fb32009-06-26 17:51:02641 skia::PlatformCanvas canvas;
642 if (!canvas.initialize(size.width, size.height, true))
643 return false;
[email protected]8c89e7792009-08-19 21:18:34644 view->paint(webkit_glue::ToWebCanvas(&canvas),
645 WebRect(0, 0, size.width, size.height));
[email protected]8649fb32009-06-26 17:51:02646
647 skia::BitmapPlatformDevice& device =
648 static_cast<skia::BitmapPlatformDevice&>(canvas.getTopPlatformDevice());
649
650 const SkBitmap& src_bmp = device.accessBitmap(false);
initial.commit09911bf2008-07-26 23:55:29651
[email protected]cab34d6a2009-09-24 01:14:52652 SkRect dest_rect = { 0, 0, SkIntToScalar(w), SkIntToScalar(h) };
initial.commit09911bf2008-07-26 23:55:29653 float dest_aspect = dest_rect.width() / dest_rect.height();
654
655 // Get the src rect so that we can preserve the aspect ratio while filling
656 // the destination.
657 SkIRect src_rect;
658 if (src_bmp.width() < dest_rect.width() ||
659 src_bmp.height() < dest_rect.height()) {
660 // Source image is smaller: we clip the part of source image within the
661 // dest rect, and then stretch it to fill the dest rect. We don't respect
662 // the aspect ratio in this case.
663 src_rect.set(0, 0, static_cast<S16CPU>(dest_rect.width()),
664 static_cast<S16CPU>(dest_rect.height()));
665 score->good_clipping = false;
666 } else {
667 float src_aspect = static_cast<float>(src_bmp.width()) / src_bmp.height();
668 if (src_aspect > dest_aspect) {
669 // Wider than tall, clip horizontally: we center the smaller thumbnail in
670 // the wider screen.
671 S16CPU new_width = static_cast<S16CPU>(src_bmp.height() * dest_aspect);
672 S16CPU x_offset = (src_bmp.width() - new_width) / 2;
673 src_rect.set(x_offset, 0, new_width + x_offset, src_bmp.height());
674 score->good_clipping = false;
675 } else {
676 src_rect.set(0, 0, src_bmp.width(),
677 static_cast<S16CPU>(src_bmp.width() / dest_aspect));
678 score->good_clipping = true;
679 }
680 }
681
[email protected]26aa0482009-09-30 16:55:27682 score->at_top = (view->mainFrame()->scrollOffset().height == 0);
initial.commit09911bf2008-07-26 23:55:29683
684 SkBitmap subset;
[email protected]8649fb32009-06-26 17:51:02685 device.accessBitmap(false).extractSubset(&subset, src_rect);
initial.commit09911bf2008-07-26 23:55:29686
687 // Resample the subset that we want to get it the right size.
[email protected]465b34b72008-12-12 20:19:14688 *thumbnail = skia::ImageOperations::Resize(
689 subset, skia::ImageOperations::RESIZE_LANCZOS3, w, h);
initial.commit09911bf2008-07-26 23:55:29690
691 score->boring_score = CalculateBoringScore(thumbnail);
692
693#ifdef TIME_BITMAP_RETRIEVAL
694 double end = time_util::GetHighResolutionTimeNow();
695 char buf[128];
696 sprintf_s(buf, "thumbnail in %gms\n", (end - begin) * 1000);
697 OutputDebugStringA(buf);
698#endif
[email protected]b6e4bec2008-11-12 01:17:15699 return true;
initial.commit09911bf2008-07-26 23:55:29700}
701
702double RenderView::CalculateBoringScore(SkBitmap* bitmap) {
703 int histogram[256] = {0};
704 color_utils::BuildLumaHistogram(bitmap, histogram);
705
706 int color_count = *std::max_element(histogram, histogram + 256);
707 int pixel_count = bitmap->width() * bitmap->height();
708 return static_cast<double>(color_count) / pixel_count;
709}
710
711void RenderView::OnNavigate(const ViewMsg_Navigate_Params& params) {
712 if (!webview())
713 return;
714
[email protected]8c785c62009-07-13 14:20:15715 if (devtools_agent_.get())
716 devtools_agent_->OnNavigate();
717
[email protected]a9f607e2009-10-23 19:59:27718 child_process_logging::SetActiveURL(params.url);
[email protected]f8b6b6f2009-03-10 16:48:26719
initial.commit09911bf2008-07-26 23:55:29720 AboutHandler::MaybeHandle(params.url);
721
722 bool is_reload = params.reload;
723
[email protected]26aa0482009-09-30 16:55:27724 WebFrame* main_frame = webview()->mainFrame();
[email protected]dd7daa82009-08-10 05:46:45725 if (is_reload && main_frame->currentHistoryItem().isNull()) {
initial.commit09911bf2008-07-26 23:55:29726 // We cannot reload if we do not have any history state. This happens, for
727 // example, when recovering from a crash. Our workaround here is a bit of
728 // a hack since it means that reload after a crashed tab does not cause an
729 // end-to-end cache validation.
730 is_reload = false;
731 }
732
[email protected]77f17a82009-05-21 04:42:54733 // A navigation resulting from loading a javascript URL should not be treated
734 // as a browser initiated event. Instead, we want it to look as if the page
735 // initiated any load resulting from JS execution.
736 if (!params.url.SchemeIs(chrome::kJavaScriptScheme)) {
[email protected]daa8c58e2009-06-15 17:21:10737 pending_navigation_state_.reset(NavigationState::CreateBrowserInitiated(
[email protected]77f17a82009-05-21 04:42:54738 params.page_id, params.transition, params.request_time));
739 }
initial.commit09911bf2008-07-26 23:55:29740
[email protected]04d3c6e2009-05-22 17:00:13741 // If we are reloading, then WebKit will use the history state of the current
742 // page, so we should just ignore any given history state. Otherwise, if we
743 // have history state, then we need to navigate to it, which corresponds to a
744 // back/forward navigation event.
[email protected]e6f546c32009-07-01 17:12:55745 if (is_reload) {
[email protected]dd7daa82009-08-10 05:46:45746 main_frame->reload();
[email protected]e6f546c32009-07-01 17:12:55747 } else if (!params.state.empty()) {
[email protected]04d3c6e2009-05-22 17:00:13748 // We must know the page ID of the page we are navigating back to.
[email protected]f929f2f22009-06-12 16:56:58749 DCHECK_NE(params.page_id, -1);
[email protected]dd7daa82009-08-10 05:46:45750 main_frame->loadHistoryItem(
[email protected]ca948a22009-06-25 19:36:17751 webkit_glue::HistoryItemFromString(params.state));
[email protected]04d3c6e2009-05-22 17:00:13752 } else {
753 // Navigate to the given URL.
[email protected]726985e22009-06-18 21:09:28754 WebURLRequest request(params.url);
initial.commit09911bf2008-07-26 23:55:29755
[email protected]e6f546c32009-07-01 17:12:55756 // A session history navigation should have been accompanied by state.
757 DCHECK_EQ(params.page_id, -1);
[email protected]04d3c6e2009-05-22 17:00:13758
[email protected]dd7daa82009-08-10 05:46:45759 if (main_frame->isViewSourceModeEnabled())
[email protected]e6f546c32009-07-01 17:12:55760 request.setCachePolicy(WebURLRequest::ReturnCacheDataElseLoad);
[email protected]04d3c6e2009-05-22 17:00:13761
[email protected]726985e22009-06-18 21:09:28762 if (params.referrer.is_valid()) {
763 request.setHTTPHeaderField(WebString::fromUTF8("Referer"),
764 WebString::fromUTF8(params.referrer.spec()));
765 }
[email protected]04d3c6e2009-05-22 17:00:13766
[email protected]dd7daa82009-08-10 05:46:45767 main_frame->loadRequest(request);
[email protected]c0588052008-10-27 23:01:50768 }
769
[email protected]77f17a82009-05-21 04:42:54770 // In case LoadRequest failed before DidCreateDataSource was called.
771 pending_navigation_state_.reset();
initial.commit09911bf2008-07-26 23:55:29772}
773
774// Stop loading the current page
775void RenderView::OnStop() {
776 if (webview())
[email protected]b4bb2502009-10-01 22:35:27777 webview()->mainFrame()->stopLoading();
initial.commit09911bf2008-07-26 23:55:29778}
779
[email protected]e6f546c32009-07-01 17:12:55780void RenderView::OnLoadAlternateHTMLText(const std::string& html,
initial.commit09911bf2008-07-26 23:55:29781 bool new_navigation,
782 const GURL& display_url,
783 const std::string& security_info) {
784 if (!webview())
785 return;
786
[email protected]e6f546c32009-07-01 17:12:55787 pending_navigation_state_.reset(NavigationState::CreateBrowserInitiated(
788 new_navigation ? -1 : page_id_, PageTransition::LINK, Time::Now()));
789 pending_navigation_state_->set_security_info(security_info);
initial.commit09911bf2008-07-26 23:55:29790
[email protected]26aa0482009-09-30 16:55:27791 webview()->mainFrame()->loadHTMLString(
792 html, GURL(kUnreachableWebDataURL), display_url, !new_navigation);
[email protected]e6f546c32009-07-01 17:12:55793
794 pending_navigation_state_.reset();
initial.commit09911bf2008-07-26 23:55:29795}
796
797void RenderView::OnCopyImageAt(int x, int y) {
[email protected]26aa0482009-09-30 16:55:27798 webview()->copyImageAt(WebPoint(x, y));
initial.commit09911bf2008-07-26 23:55:29799}
800
[email protected]68b1e922009-06-23 16:00:25801void RenderView::OnExecuteEditCommand(const std::string& name,
802 const std::string& value) {
[email protected]26aa0482009-09-30 16:55:27803 if (!webview() || !webview()->focusedFrame())
[email protected]68b1e922009-06-23 16:00:25804 return;
805
[email protected]26aa0482009-09-30 16:55:27806 webview()->focusedFrame()->executeCommand(
[email protected]dd7daa82009-08-10 05:46:45807 WebString::fromUTF8(name), WebString::fromUTF8(value));
[email protected]68b1e922009-06-23 16:00:25808}
809
[email protected]b2abac72009-02-26 12:39:28810void RenderView::OnSetupDevToolsClient() {
[email protected]e4ac5df2009-03-17 15:33:11811 DCHECK(!devtools_client_.get());
812 devtools_client_.reset(new DevToolsClient(this));
[email protected]b2abac72009-02-26 12:39:28813}
814
initial.commit09911bf2008-07-26 23:55:29815void RenderView::OnStopFinding(bool clear_selection) {
816 WebView* view = webview();
817 if (!view)
818 return;
819
820 if (clear_selection)
[email protected]26aa0482009-09-30 16:55:27821 view->focusedFrame()->executeCommand(WebString::fromUTF8("Unselect"));
initial.commit09911bf2008-07-26 23:55:29822
[email protected]26aa0482009-09-30 16:55:27823 WebFrame* frame = view->mainFrame();
initial.commit09911bf2008-07-26 23:55:29824 while (frame) {
[email protected]dd7daa82009-08-10 05:46:45825 frame->stopFinding(clear_selection);
[email protected]b4bb2502009-10-01 22:35:27826 frame = frame->traverseNext(false);
initial.commit09911bf2008-07-26 23:55:29827 }
828}
829
830void RenderView::OnFindReplyAck() {
831 // Check if there is any queued up request waiting to be sent.
832 if (queued_find_reply_message_.get()) {
833 // Send the search result over to the browser process.
834 Send(queued_find_reply_message_.get());
835 queued_find_reply_message_.release();
836 }
837}
838
839void RenderView::OnUpdateTargetURLAck() {
840 // Check if there is a targeturl waiting to be sent.
841 if (target_url_status_ == TARGET_PENDING) {
842 Send(new ViewHostMsg_UpdateTargetURL(routing_id_, page_id_,
843 pending_target_url_));
844 }
845
846 target_url_status_ = TARGET_NONE;
847}
848
849void RenderView::OnUndo() {
850 if (!webview())
851 return;
852
[email protected]26aa0482009-09-30 16:55:27853 webview()->focusedFrame()->executeCommand(WebString::fromUTF8("Undo"));
[email protected]dd7daa82009-08-10 05:46:45854 UserMetricsRecordAction(L"Undo");
initial.commit09911bf2008-07-26 23:55:29855}
856
857void RenderView::OnRedo() {
858 if (!webview())
859 return;
860
[email protected]26aa0482009-09-30 16:55:27861 webview()->focusedFrame()->executeCommand(WebString::fromUTF8("Redo"));
[email protected]dd7daa82009-08-10 05:46:45862 UserMetricsRecordAction(L"Redo");
initial.commit09911bf2008-07-26 23:55:29863}
864
865void RenderView::OnCut() {
866 if (!webview())
867 return;
868
[email protected]26aa0482009-09-30 16:55:27869 webview()->focusedFrame()->executeCommand(WebString::fromUTF8("Cut"));
[email protected]dd7daa82009-08-10 05:46:45870 UserMetricsRecordAction(L"Cut");
initial.commit09911bf2008-07-26 23:55:29871}
872
873void RenderView::OnCopy() {
874 if (!webview())
875 return;
876
[email protected]26aa0482009-09-30 16:55:27877 webview()->focusedFrame()->executeCommand(WebString::fromUTF8("Copy"));
[email protected]dd7daa82009-08-10 05:46:45878 UserMetricsRecordAction(L"Copy");
initial.commit09911bf2008-07-26 23:55:29879}
880
[email protected]c0cc3092009-09-12 08:27:27881#if defined(OS_MACOSX)
[email protected]a954bf72009-09-12 07:30:35882void RenderView::OnCopyToFindPboard() {
883 if (!webview())
884 return;
885
886 // Since the find pasteboard supports only plain text, this can be simpler
887 // than the |OnCopy()| case.
[email protected]26aa0482009-09-30 16:55:27888 WebFrame* frame = webview()->focusedFrame();
[email protected]a954bf72009-09-12 07:30:35889 if (frame->hasSelection()) {
890 string16 selection = frame->selectionAsText();
891 RenderThread::current()->Send(
892 new ViewHostMsg_ClipboardFindPboardWriteStringAsync(selection));
893 }
894
895 UserMetricsRecordAction(L"CopyToFindPboard");
896}
[email protected]c0cc3092009-09-12 08:27:27897#endif
[email protected]a954bf72009-09-12 07:30:35898
initial.commit09911bf2008-07-26 23:55:29899void RenderView::OnPaste() {
900 if (!webview())
901 return;
902
[email protected]26aa0482009-09-30 16:55:27903 webview()->focusedFrame()->executeCommand(WebString::fromUTF8("Paste"));
[email protected]dd7daa82009-08-10 05:46:45904 UserMetricsRecordAction(L"Paste");
initial.commit09911bf2008-07-26 23:55:29905}
906
[email protected]2a3a7762009-10-19 19:17:32907void RenderView::OnReplace(const string16& text) {
initial.commit09911bf2008-07-26 23:55:29908 if (!webview())
909 return;
910
[email protected]2a3a7762009-10-19 19:17:32911 webview()->focusedFrame()->replaceSelection(text);
initial.commit09911bf2008-07-26 23:55:29912}
913
[email protected]98324892009-09-09 21:16:05914void RenderView::OnAdvanceToNextMisspelling() {
915 if (!webview())
916 return;
[email protected]26aa0482009-09-30 16:55:27917 webview()->focusedFrame()->executeCommand(
[email protected]98324892009-09-09 21:16:05918 WebString::fromUTF8("AdvanceToNextMisspelling"));
919}
920
921void RenderView::OnToggleSpellPanel(bool is_currently_visible) {
922 if (!webview())
923 return;
924 // We need to tell the webView whether the spelling panel is visible or not so
925 // that it won't need to make ipc calls later.
[email protected]8922e1f2009-10-03 05:01:26926 spelling_panel_visible_ = is_currently_visible;
[email protected]26aa0482009-09-30 16:55:27927 webview()->focusedFrame()->executeCommand(
[email protected]98324892009-09-09 21:16:05928 WebString::fromUTF8("ToggleSpellPanel"));
929}
930
[email protected]bbbd545c2008-12-15 20:18:04931void RenderView::OnToggleSpellCheck() {
932 if (!webview())
933 return;
934
[email protected]26aa0482009-09-30 16:55:27935 WebFrame* frame = webview()->focusedFrame();
[email protected]dd7daa82009-08-10 05:46:45936 frame->enableContinuousSpellChecking(
937 !frame->isContinuousSpellCheckingEnabled());
[email protected]bbbd545c2008-12-15 20:18:04938}
939
initial.commit09911bf2008-07-26 23:55:29940void RenderView::OnDelete() {
941 if (!webview())
942 return;
943
[email protected]26aa0482009-09-30 16:55:27944 webview()->focusedFrame()->executeCommand(WebString::fromUTF8("Delete"));
[email protected]dd7daa82009-08-10 05:46:45945 UserMetricsRecordAction(L"DeleteSelection");
initial.commit09911bf2008-07-26 23:55:29946}
947
948void RenderView::OnSelectAll() {
949 if (!webview())
950 return;
951
[email protected]26aa0482009-09-30 16:55:27952 webview()->focusedFrame()->executeCommand(
[email protected]a100d76bb2009-08-14 17:50:22953 WebString::fromUTF8("SelectAll"));
954 UserMetricsRecordAction(L"SelectAll");
initial.commit09911bf2008-07-26 23:55:29955}
956
957void RenderView::OnSetInitialFocus(bool reverse) {
958 if (!webview())
959 return;
[email protected]26aa0482009-09-30 16:55:27960 webview()->setInitialFocus(reverse);
initial.commit09911bf2008-07-26 23:55:29961}
962
963///////////////////////////////////////////////////////////////////////////////
964
965// Tell the embedding application that the URL of the active page has changed
966void RenderView::UpdateURL(WebFrame* frame) {
[email protected]dd7daa82009-08-10 05:46:45967 WebDataSource* ds = frame->dataSource();
initial.commit09911bf2008-07-26 23:55:29968 DCHECK(ds);
969
[email protected]726985e22009-06-18 21:09:28970 const WebURLRequest& request = ds->request();
971 const WebURLRequest& original_request = ds->originalRequest();
972 const WebURLResponse& response = ds->response();
initial.commit09911bf2008-07-26 23:55:29973
[email protected]daa8c58e2009-06-15 17:21:10974 NavigationState* navigation_state = NavigationState::FromDataSource(ds);
975 DCHECK(navigation_state);
initial.commit09911bf2008-07-26 23:55:29976
977 ViewHostMsg_FrameNavigate_Params params;
[email protected]726985e22009-06-18 21:09:28978 params.http_status_code = response.httpStatusCode();
initial.commit09911bf2008-07-26 23:55:29979 params.is_post = false;
980 params.page_id = page_id_;
[email protected]726985e22009-06-18 21:09:28981 params.is_content_filtered = response.isContentFiltered();
[email protected]e6f546c32009-07-01 17:12:55982 if (!navigation_state->security_info().empty()) {
initial.commit09911bf2008-07-26 23:55:29983 // SSL state specified in the request takes precedence over the one in the
984 // response.
985 // So far this is only intended for error pages that are not expected to be
986 // over ssl, so we should not get any clash.
[email protected]726985e22009-06-18 21:09:28987 DCHECK(response.securityInfo().isEmpty());
[email protected]e6f546c32009-07-01 17:12:55988 params.security_info = navigation_state->security_info();
initial.commit09911bf2008-07-26 23:55:29989 } else {
[email protected]726985e22009-06-18 21:09:28990 params.security_info = response.securityInfo();
initial.commit09911bf2008-07-26 23:55:29991 }
992
993 // Set the URL to be displayed in the browser UI to the user.
[email protected]726985e22009-06-18 21:09:28994 if (ds->hasUnreachableURL()) {
995 params.url = ds->unreachableURL();
initial.commit09911bf2008-07-26 23:55:29996 } else {
[email protected]726985e22009-06-18 21:09:28997 params.url = request.url();
initial.commit09911bf2008-07-26 23:55:29998 }
999
[email protected]726985e22009-06-18 21:09:281000 GetRedirectChain(ds, &params.redirects);
1001 params.should_update_history = !ds->hasUnreachableURL();
initial.commit09911bf2008-07-26 23:55:291002
1003 const SearchableFormData* searchable_form_data =
[email protected]daa8c58e2009-06-15 17:21:101004 navigation_state->searchable_form_data();
initial.commit09911bf2008-07-26 23:55:291005 if (searchable_form_data) {
1006 params.searchable_form_url = searchable_form_data->url();
initial.commit09911bf2008-07-26 23:55:291007 params.searchable_form_encoding = searchable_form_data->encoding();
1008 }
1009
1010 const PasswordForm* password_form_data =
[email protected]daa8c58e2009-06-15 17:21:101011 navigation_state->password_form_data();
initial.commit09911bf2008-07-26 23:55:291012 if (password_form_data)
1013 params.password_form = *password_form_data;
1014
1015 params.gesture = navigation_gesture_;
1016 navigation_gesture_ = NavigationGestureUnknown;
1017
[email protected]dd7daa82009-08-10 05:46:451018 if (!frame->parent()) {
initial.commit09911bf2008-07-26 23:55:291019 // Top-level navigation.
1020
1021 // Update contents MIME type for main frame.
[email protected]9c5645b2009-08-11 03:37:551022 params.contents_mime_type = ds->response().mimeType().utf8();
initial.commit09911bf2008-07-26 23:55:291023
[email protected]daa8c58e2009-06-15 17:21:101024 params.transition = navigation_state->transition_type();
initial.commit09911bf2008-07-26 23:55:291025 if (!PageTransition::IsMainFrame(params.transition)) {
1026 // If the main frame does a load, it should not be reported as a subframe
1027 // navigation. This can occur in the following case:
1028 // 1. You're on a site with frames.
1029 // 2. You do a subframe navigation. This is stored with transition type
1030 // MANUAL_SUBFRAME.
1031 // 3. You navigate to some non-frame site, say, google.com.
1032 // 4. You navigate back to the page from step 2. Since it was initially
1033 // MANUAL_SUBFRAME, it will be that same transition type here.
1034 // We don't want that, because any navigation that changes the toplevel
1035 // frame should be tracked as a toplevel navigation (this allows us to
1036 // update the URL bar, etc).
1037 params.transition = PageTransition::LINK;
1038 }
1039
initial.commit09911bf2008-07-26 23:55:291040 // If we have a valid consumed client redirect source,
1041 // the page contained a client redirect (meta refresh, document.loc...),
1042 // so we set the referrer and transition to match.
1043 if (completed_client_redirect_src_.is_valid()) {
[email protected]77e09a92008-08-01 18:11:041044 DCHECK(completed_client_redirect_src_ == params.redirects[0]);
initial.commit09911bf2008-07-26 23:55:291045 params.referrer = completed_client_redirect_src_;
1046 params.transition = static_cast<PageTransition::Type>(
1047 params.transition | PageTransition::CLIENT_REDIRECT);
1048 } else {
1049 // Bug 654101: the referrer will be empty on https->http transitions. It
1050 // would be nice if we could get the real referrer from somewhere.
[email protected]726985e22009-06-18 21:09:281051 params.referrer = GURL(
1052 original_request.httpHeaderField(WebString::fromUTF8("Referer")));
initial.commit09911bf2008-07-26 23:55:291053 }
1054
[email protected]726985e22009-06-18 21:09:281055 string16 method = request.httpMethod();
1056 if (EqualsASCII(method, "POST"))
initial.commit09911bf2008-07-26 23:55:291057 params.is_post = true;
1058
[email protected]c2a797d2009-09-21 16:46:321059 // Save some histogram data so we can compute the average memory used per
1060 // page load of the glyphs.
1061 UMA_HISTOGRAM_COUNTS_10000("Memory.GlyphPagesPerLoad",
1062 webkit_glue::GetGlyphPageCount());
1063
initial.commit09911bf2008-07-26 23:55:291064 Send(new ViewHostMsg_FrameNavigate(routing_id_, params));
1065 } else {
1066 // Subframe navigation: the type depends on whether this navigation
1067 // generated a new session history entry. When they do generate a session
1068 // history entry, it means the user initiated the navigation and we should
1069 // mark it as such. This test checks if this is the first time UpdateURL
1070 // has been called since WillNavigateToURL was called to initiate the load.
1071 if (page_id_ > last_page_id_sent_to_browser_)
1072 params.transition = PageTransition::MANUAL_SUBFRAME;
1073 else
1074 params.transition = PageTransition::AUTO_SUBFRAME;
1075
initial.commit09911bf2008-07-26 23:55:291076 Send(new ViewHostMsg_FrameNavigate(routing_id_, params));
1077 }
1078
1079 last_page_id_sent_to_browser_ =
1080 std::max(last_page_id_sent_to_browser_, page_id_);
1081
1082 // If we end up reusing this WebRequest (for example, due to a #ref click),
[email protected]daa8c58e2009-06-15 17:21:101083 // we don't want the transition type to persist. Just clear it.
1084 navigation_state->set_transition_type(PageTransition::LINK);
[email protected]266eb6f2008-09-30 23:56:501085
[email protected]6c8afae52009-01-22 02:24:571086#if defined(OS_WIN)
[email protected]6a983b42009-03-20 20:12:251087 if (web_accessibility_manager_.get()) {
[email protected]be645db2009-02-06 20:36:331088 // Clear accessibility info cache.
[email protected]6a983b42009-03-20 20:12:251089 web_accessibility_manager_->ClearAccObjMap(-1, true);
[email protected]266eb6f2008-09-30 23:56:501090 }
[email protected]6c8afae52009-01-22 02:24:571091#else
[email protected]7d926f92009-03-03 14:26:541092 // TODO(port): accessibility not yet implemented. See http://crbug.com/8288.
[email protected]6c8afae52009-01-22 02:24:571093#endif
initial.commit09911bf2008-07-26 23:55:291094}
1095
1096// Tell the embedding application that the title of the active page has changed
[email protected]3d9689372009-09-10 04:29:171097void RenderView::UpdateTitle(WebFrame* frame, const string16& title) {
initial.commit09911bf2008-07-26 23:55:291098 // Ignore all but top level navigations...
[email protected]3d9689372009-09-10 04:29:171099 if (!frame->parent()) {
[email protected]f0af6a72009-05-30 05:25:171100 Send(new ViewHostMsg_UpdateTitle(
[email protected]3d9689372009-09-10 04:29:171101 routing_id_,
1102 page_id_,
1103 UTF16ToWideHack(title.length() > chrome::kMaxTitleChars ?
1104 title.substr(0, chrome::kMaxTitleChars) : title)));
[email protected]f0af6a72009-05-30 05:25:171105 }
initial.commit09911bf2008-07-26 23:55:291106}
1107
1108void RenderView::UpdateEncoding(WebFrame* frame,
[email protected]41fc0322009-09-04 22:23:401109 const std::string& encoding_name) {
initial.commit09911bf2008-07-26 23:55:291110 // Only update main frame's encoding_name.
[email protected]26aa0482009-09-30 16:55:271111 if (webview()->mainFrame() == frame &&
initial.commit09911bf2008-07-26 23:55:291112 last_encoding_name_ != encoding_name) {
[email protected]e38f40152008-09-12 23:08:301113 // Save the encoding name for later comparing.
initial.commit09911bf2008-07-26 23:55:291114 last_encoding_name_ = encoding_name;
1115
[email protected]e38f40152008-09-12 23:08:301116 Send(new ViewHostMsg_UpdateEncoding(routing_id_, last_encoding_name_));
initial.commit09911bf2008-07-26 23:55:291117 }
1118}
1119
[email protected]f4d34b52008-11-24 23:05:011120// Sends the previous session history state to the browser so it will be saved
1121// before we navigate to a new page. This must be called *before* the page ID
1122// has been updated so we know what it was.
initial.commit09911bf2008-07-26 23:55:291123void RenderView::UpdateSessionHistory(WebFrame* frame) {
1124 // If we have a valid page ID at this point, then it corresponds to the page
1125 // we are navigating away from. Otherwise, this is the first navigation, so
1126 // there is no past session history to record.
1127 if (page_id_ == -1)
1128 return;
1129
[email protected]ca948a22009-06-25 19:36:171130 const WebHistoryItem& item =
[email protected]26aa0482009-09-30 16:55:271131 webview()->mainFrame()->previousHistoryItem();
[email protected]ca948a22009-06-25 19:36:171132 if (item.isNull())
initial.commit09911bf2008-07-26 23:55:291133 return;
[email protected]ca948a22009-06-25 19:36:171134
1135 Send(new ViewHostMsg_UpdateState(
1136 routing_id_, page_id_, webkit_glue::HistoryItemToString(item)));
initial.commit09911bf2008-07-26 23:55:291137}
1138
[email protected]3d9689372009-09-10 04:29:171139void RenderView::OpenURL(
1140 const GURL& url, const GURL& referrer, WebNavigationPolicy policy) {
1141 Send(new ViewHostMsg_OpenURL(
1142 routing_id_, url, referrer, NavigationPolicyToDisposition(policy)));
1143}
1144
[email protected]79dbc662009-09-04 05:42:511145// WebViewDelegate ------------------------------------------------------------
initial.commit09911bf2008-07-26 23:55:291146
[email protected]a2f6bc112009-06-27 16:27:251147void RenderView::DidPaint() {
[email protected]26aa0482009-09-30 16:55:271148 WebFrame* main_frame = webview()->mainFrame();
[email protected]a2f6bc112009-06-27 16:27:251149
[email protected]dd7daa82009-08-10 05:46:451150 if (main_frame->provisionalDataSource()) {
[email protected]a2f6bc112009-06-27 16:27:251151 // If we have a provisional frame we are between the start
1152 // and commit stages of loading...ignore this paint.
1153 return;
1154 }
1155
[email protected]dd7daa82009-08-10 05:46:451156 WebDataSource* ds = main_frame->dataSource();
[email protected]a2f6bc112009-06-27 16:27:251157 NavigationState* navigation_state = NavigationState::FromDataSource(ds);
[email protected]78a3a6f2009-07-02 16:15:011158 DCHECK(navigation_state);
1159
1160 Time now = Time::Now();
1161 if (navigation_state->first_paint_time().is_null()) {
1162 navigation_state->set_first_paint_time(now);
1163 }
1164 if (navigation_state->first_paint_after_load_time().is_null() &&
1165 !navigation_state->finish_load_time().is_null()) {
1166 navigation_state->set_first_paint_after_load_time(now);
[email protected]a2f6bc112009-06-27 16:27:251167 }
1168}
1169
initial.commit09911bf2008-07-26 23:55:291170void RenderView::LoadNavigationErrorPage(WebFrame* frame,
[email protected]726985e22009-06-18 21:09:281171 const WebURLRequest& failed_request,
1172 const WebURLError& error,
initial.commit09911bf2008-07-26 23:55:291173 const std::string& html,
1174 bool replace) {
[email protected]726985e22009-06-18 21:09:281175 GURL failed_url = error.unreachableURL;
initial.commit09911bf2008-07-26 23:55:291176
1177 std::string alt_html;
1178 if (html.empty()) {
1179 // Use a local error page.
1180 int resource_id;
1181 DictionaryValue error_strings;
[email protected]726985e22009-06-18 21:09:281182 if (error.reason == net::ERR_CACHE_MISS &&
1183 EqualsASCII(failed_request.httpMethod(), "POST")) {
initial.commit09911bf2008-07-26 23:55:291184 GetFormRepostErrorValues(failed_url, &error_strings);
1185 resource_id = IDR_ERROR_NO_DETAILS_HTML;
1186 } else {
1187 GetLocalizedErrorValues(error, &error_strings);
1188 resource_id = IDR_NET_ERROR_HTML;
1189 }
[email protected]8e50b602009-03-03 22:59:431190 error_strings.SetString(L"textdirection",
1191 (l10n_util::GetTextDirection() == l10n_util::RIGHT_TO_LEFT) ?
1192 L"rtl" : L"ltr");
initial.commit09911bf2008-07-26 23:55:291193
1194 alt_html = GetAltHTMLForTemplate(error_strings, resource_id);
1195 } else {
1196 alt_html = html;
1197 }
1198
[email protected]dd7daa82009-08-10 05:46:451199 frame->loadHTMLString(alt_html,
[email protected]e6f546c32009-07-01 17:12:551200 GURL(kUnreachableWebDataURL),
1201 failed_url,
1202 replace);
initial.commit09911bf2008-07-26 23:55:291203}
1204
[email protected]7ccddb8c2009-08-04 17:36:551205void RenderView::BindDOMAutomationController(WebFrame* frame) {
initial.commit09911bf2008-07-26 23:55:291206 dom_automation_controller_.set_message_sender(this);
1207 dom_automation_controller_.set_routing_id(routing_id_);
[email protected]7ccddb8c2009-08-04 17:36:551208 dom_automation_controller_.BindToJavascript(frame,
initial.commit09911bf2008-07-26 23:55:291209 L"domAutomationController");
1210}
1211
initial.commit09911bf2008-07-26 23:55:291212bool RenderView::RunJavaScriptMessage(int type,
1213 const std::wstring& message,
1214 const std::wstring& default_value,
[email protected]a455d3812009-03-05 20:18:071215 const GURL& frame_url,
initial.commit09911bf2008-07-26 23:55:291216 std::wstring* result) {
1217 bool success = false;
1218 std::wstring result_temp;
1219 if (!result)
1220 result = &result_temp;
initial.commit09911bf2008-07-26 23:55:291221
[email protected]12636df2009-09-28 22:32:211222 SendAndRunNestedMessageLoop(new ViewHostMsg_RunJavaScriptMessage(
1223 routing_id_, message, default_value, frame_url, type, &success, result));
initial.commit09911bf2008-07-26 23:55:291224 return success;
1225}
1226
1227void RenderView::AddGURLSearchProvider(const GURL& osd_url, bool autodetected) {
1228 if (!osd_url.is_empty())
1229 Send(new ViewHostMsg_PageHasOSDD(routing_id_, page_id_, osd_url,
1230 autodetected));
1231}
1232
[email protected]842936a2009-10-14 06:00:361233void RenderView::OnQueryFormFieldAutofillAck(
[email protected]acca2a1f2009-10-16 03:53:391234 int query_id,
1235 const std::vector<string16>& suggestions,
[email protected]0ebf3872008-11-07 21:35:031236 int default_suggestion_index) {
[email protected]acca2a1f2009-10-16 03:53:391237 if (webview() && query_id == autofill_query_id_ && !suggestions.empty()) {
1238 webview()->applyAutofillSuggestions(
1239 autofill_query_node_, suggestions, default_suggestion_index);
1240 }
1241 autofill_query_node_.reset();
[email protected]0ebf3872008-11-07 21:35:031242}
1243
[email protected]2c4410d2009-05-06 23:46:221244void RenderView::OnPopupNotificationVisibilityChanged(bool visible) {
[email protected]634a6f92008-12-01 21:39:311245 popup_notification_visible_ = visible;
1246}
1247
initial.commit09911bf2008-07-26 23:55:291248uint32 RenderView::GetCPBrowsingContext() {
1249 uint32 context = 0;
1250 Send(new ViewHostMsg_GetCPBrowsingContext(&context));
1251 return context;
1252}
1253
initial.commit09911bf2008-07-26 23:55:291254void RenderView::AddSearchProvider(const std::string& url) {
1255 AddGURLSearchProvider(GURL(url),
1256 false); // not autodetected
1257}
1258
[email protected]f103ab72009-09-02 17:10:591259void RenderView::OnMissingPluginStatus(
1260 WebPluginDelegateProxy* delegate,
1261 int status) {
[email protected]6c8afae52009-01-22 02:24:571262#if defined(OS_WIN)
[email protected]f103ab72009-09-02 17:10:591263 if (!first_default_plugin_) {
initial.commit09911bf2008-07-26 23:55:291264 // Show the InfoBar for the first available plugin.
1265 if (status == default_plugin::MISSING_PLUGIN_AVAILABLE) {
[email protected]f103ab72009-09-02 17:10:591266 first_default_plugin_ = delegate->AsWeakPtr();
initial.commit09911bf2008-07-26 23:55:291267 Send(new ViewHostMsg_MissingPluginStatus(routing_id_, status));
1268 }
1269 } else {
1270 // Closes the InfoBar if user clicks on the plugin (instead of the InfoBar)
1271 // to start the download/install.
1272 if (status == default_plugin::MISSING_PLUGIN_USER_STARTED_DOWNLOAD) {
1273 Send(new ViewHostMsg_MissingPluginStatus(routing_id_, status));
1274 }
1275 }
[email protected]6c8afae52009-01-22 02:24:571276#else
1277 // TODO(port): plugins current not supported
1278 NOTIMPLEMENTED();
1279#endif
initial.commit09911bf2008-07-26 23:55:291280}
1281
[email protected]48c9cf2d2009-09-16 16:47:521282// WebKit::WebViewClient ------------------------------------------------------
1283
1284WebView* RenderView::createView(WebFrame* creator) {
1285 // Check to make sure we aren't overloading on popups.
1286 if (shared_popup_counter_->data > kMaximumNumberOfUnacknowledgedPopups)
1287 return NULL;
1288
1289 // This window can't be closed from a window.close() call until we receive a
1290 // message from the Browser process explicitly allowing it.
1291 popup_notification_visible_ = true;
1292
1293 int32 routing_id = MSG_ROUTING_NONE;
1294 bool user_gesture = creator->isProcessingUserGesture();
1295
[email protected]48c9cf2d2009-09-16 16:47:521296 render_thread_->Send(
[email protected]12636df2009-09-28 22:32:211297 new ViewHostMsg_CreateWindow(routing_id_, user_gesture, &routing_id));
1298 if (routing_id == MSG_ROUTING_NONE)
[email protected]48c9cf2d2009-09-16 16:47:521299 return NULL;
[email protected]48c9cf2d2009-09-16 16:47:521300
[email protected]48c9cf2d2009-09-16 16:47:521301 RenderView* view = RenderView::Create(render_thread_,
[email protected]659f73fa2009-10-13 13:43:421302 0,
[email protected]12636df2009-09-28 22:32:211303 routing_id_,
[email protected]48c9cf2d2009-09-16 16:47:521304 renderer_preferences_,
1305 webkit_preferences_,
[email protected]12636df2009-09-28 22:32:211306 shared_popup_counter_,
1307 routing_id);
[email protected]48c9cf2d2009-09-16 16:47:521308 view->opened_by_user_gesture_ = user_gesture;
1309
1310 // Record the security origin of the creator.
[email protected]91733b62009-09-18 06:21:091311 GURL creator_url(creator->securityOrigin().toString().utf8());
[email protected]48c9cf2d2009-09-16 16:47:521312 if (!creator_url.is_valid() || !creator_url.IsStandard())
1313 creator_url = GURL();
1314 view->creator_url_ = creator_url;
1315
1316 // Copy over the alternate error page URL so we can have alt error pages in
1317 // the new render view (we don't need the browser to send the URL back down).
1318 view->alternate_error_page_url_ = alternate_error_page_url_;
1319
1320 return view->webview();
1321}
1322
1323WebWidget* RenderView::createPopupMenu(bool activatable) {
1324 RenderWidget* widget = RenderWidget::Create(routing_id_,
1325 render_thread_,
1326 activatable);
1327 return widget->webwidget();
1328}
1329
1330WebWidget* RenderView::createPopupMenu(const WebPopupMenuInfo& info) {
1331 RenderWidget* widget = RenderWidget::Create(routing_id_,
1332 render_thread_,
1333 true);
1334 widget->ConfigureAsExternalPopupMenu(info);
1335 return widget->webwidget();
1336}
1337
1338void RenderView::didAddMessageToConsole(
1339 const WebConsoleMessage& message, const WebString& source_name,
1340 unsigned source_line) {
1341 Send(new ViewHostMsg_AddMessageToConsole(routing_id_,
1342 UTF16ToWideHack(message.text),
1343 static_cast<int32>(source_line),
1344 UTF16ToWideHack(source_name)));
1345}
1346
1347void RenderView::printPage(WebFrame* frame) {
[email protected]71a14262009-09-22 20:02:581348 DCHECK(frame);
1349 Print(frame, true);
[email protected]48c9cf2d2009-09-16 16:47:521350}
1351
1352void RenderView::didStartLoading() {
1353 if (is_loading_) {
1354 DLOG(WARNING) << "didStartLoading called while loading";
1355 return;
1356 }
1357
1358 is_loading_ = true;
1359 // Clear the pointer so that we can assign it only when there is an unknown
1360 // plugin on a page.
1361 first_default_plugin_.reset();
1362
1363 Send(new ViewHostMsg_DidStartLoading(routing_id_));
1364}
1365
1366void RenderView::didStopLoading() {
1367 if (!is_loading_) {
1368 DLOG(WARNING) << "DidStopLoading called while not loading";
1369 return;
1370 }
1371
1372 is_loading_ = false;
1373
1374 // NOTE: For now we're doing the safest thing, and sending out notification
1375 // when done loading. This currently isn't an issue as the favicon is only
1376 // displayed when done loading. Ideally we would send notification when
1377 // finished parsing the head, but webkit doesn't support that yet.
1378 // The feed discovery code would also benefit from access to the head.
[email protected]26aa0482009-09-30 16:55:271379 GURL favicon_url(webview()->mainFrame()->favIconURL());
[email protected]48c9cf2d2009-09-16 16:47:521380 if (!favicon_url.is_empty())
1381 Send(new ViewHostMsg_UpdateFavIconURL(routing_id_, page_id_, favicon_url));
1382
[email protected]26aa0482009-09-30 16:55:271383 AddGURLSearchProvider(webview()->mainFrame()->openSearchDescriptionURL(),
[email protected]48c9cf2d2009-09-16 16:47:521384 true); // autodetected
1385
1386 Send(new ViewHostMsg_DidStopLoading(routing_id_));
1387
1388 MessageLoop::current()->PostDelayedTask(FROM_HERE,
1389 method_factory_.NewRunnableMethod(&RenderView::CapturePageInfo, page_id_,
1390 false),
1391 kDelayForCaptureMs);
[email protected]48c9cf2d2009-09-16 16:47:521392}
1393
[email protected]04fc9482009-09-18 22:13:031394bool RenderView::shouldBeginEditing(const WebRange& range) {
1395 return true;
1396}
1397
1398bool RenderView::shouldEndEditing(const WebRange& range) {
1399 return true;
1400}
1401
1402bool RenderView::shouldInsertNode(const WebNode& node, const WebRange& range,
1403 WebEditingAction action) {
1404 return true;
1405}
1406
1407bool RenderView::shouldInsertText(const WebString& text, const WebRange& range,
1408 WebEditingAction action) {
1409 return true;
1410}
1411
1412bool RenderView::shouldChangeSelectedRange(const WebRange& from_range,
1413 const WebRange& to_range,
1414 WebTextAffinity affinity,
1415 bool still_selecting) {
1416 return true;
1417}
1418
1419bool RenderView::shouldDeleteRange(const WebRange& range) {
1420 return true;
1421}
1422
1423bool RenderView::shouldApplyStyle(const WebString& style,
1424 const WebRange& range) {
1425 return true;
1426}
1427
1428bool RenderView::isSmartInsertDeleteEnabled() {
1429 return true;
1430}
1431
1432bool RenderView::isSelectTrailingWhitespaceEnabled() {
1433#if defined(OS_WIN)
1434 return true;
1435#else
1436 return false;
1437#endif
1438}
1439
1440void RenderView::setInputMethodEnabled(bool enabled) {
1441 // Save the updated IME status and mark the input focus has been updated.
1442 // The IME status is to be sent to a browser process next time when
1443 // the input caret is rendered.
1444 if (!ime_control_busy_) {
1445 ime_control_updated_ = true;
1446 ime_control_new_state_ = enabled;
1447 }
1448}
1449
1450void RenderView::didChangeSelection(bool is_empty_selection) {
1451#if defined(OS_LINUX)
1452 if (!handling_input_event_)
1453 return;
1454 // TODO(estade): investigate incremental updates to the selection so that we
1455 // don't send the entire selection over IPC every time.
1456 if (!is_empty_selection) {
1457 // Sometimes we get repeated didChangeSelection calls from webkit when
1458 // the selection hasn't actually changed. We don't want to report these
1459 // because it will cause us to continually claim the X clipboard.
1460 const std::string& this_selection =
[email protected]26aa0482009-09-30 16:55:271461 webview()->focusedFrame()->selectionAsText().utf8();
[email protected]04fc9482009-09-18 22:13:031462 if (this_selection == last_selection_)
1463 return;
1464
1465 Send(new ViewHostMsg_SelectionChanged(routing_id_,
1466 this_selection));
1467 last_selection_ = this_selection;
1468 } else {
1469 last_selection_.clear();
1470 }
1471#endif
1472}
1473
1474void RenderView::didExecuteCommand(const WebString& command_name) {
1475 const std::wstring& name = UTF16ToWideHack(command_name);
1476 if (StartsWith(name, L"Move", true) ||
1477 StartsWith(name, L"Insert", true) ||
1478 StartsWith(name, L"Delete", true))
1479 return;
1480 UserMetricsRecordAction(name);
1481}
1482
[email protected]b2528b72009-09-24 06:57:101483bool RenderView::handleCurrentKeyboardEvent() {
1484 if (edit_commands_.empty())
1485 return false;
1486
[email protected]26aa0482009-09-30 16:55:271487 WebFrame* frame = webview()->focusedFrame();
[email protected]b2528b72009-09-24 06:57:101488 if (!frame)
1489 return false;
1490
1491 EditCommands::iterator it = edit_commands_.begin();
1492 EditCommands::iterator end = edit_commands_.end();
1493
[email protected]507b33ea2009-09-29 03:56:511494 bool did_execute_command = false;
[email protected]b2528b72009-09-24 06:57:101495 for (; it != end; ++it) {
[email protected]e6e15012009-09-30 14:59:331496 // In gtk and cocoa, it's possible to bind multiple edit commands to one
1497 // key (but it's the exception). Once one edit command is not executed, it
1498 // seems safest to not execute the rest.
[email protected]b2528b72009-09-24 06:57:101499 if (!frame->executeCommand(WebString::fromUTF8(it->name),
1500 WebString::fromUTF8(it->value)))
1501 break;
[email protected]507b33ea2009-09-29 03:56:511502 did_execute_command = true;
[email protected]b2528b72009-09-24 06:57:101503 }
1504
[email protected]507b33ea2009-09-29 03:56:511505 return did_execute_command;
[email protected]b2528b72009-09-24 06:57:101506}
1507
[email protected]2a3a7762009-10-19 19:17:321508void RenderView::spellCheck(const WebString& text,
1509 int& misspelled_offset,
1510 int& misspelled_length) {
[email protected]1dbafaf72009-09-23 19:43:561511 EnsureDocumentTag();
[email protected]2a3a7762009-10-19 19:17:321512 Send(new ViewHostMsg_SpellCheck(routing_id_, text, document_tag_,
1513 &misspelled_offset, &misspelled_length));
[email protected]1dbafaf72009-09-23 19:43:561514}
1515
1516WebString RenderView::autoCorrectWord(const WebKit::WebString& word) {
[email protected]2a3a7762009-10-19 19:17:321517 string16 autocorrect_word;
[email protected]1dbafaf72009-09-23 19:43:561518 const CommandLine& command_line = *CommandLine::ForCurrentProcess();
[email protected]b86c8c12009-10-05 22:01:261519 if (command_line.HasSwitch(switches::kExperimentalSpellcheckerFeatures)) {
[email protected]1dbafaf72009-09-23 19:43:561520 EnsureDocumentTag();
1521 Send(new ViewHostMsg_GetAutoCorrectWord(
[email protected]2a3a7762009-10-19 19:17:321522 routing_id_, word, document_tag_, &autocorrect_word));
[email protected]1dbafaf72009-09-23 19:43:561523 }
[email protected]2a3a7762009-10-19 19:17:321524 return autocorrect_word;
[email protected]1dbafaf72009-09-23 19:43:561525}
1526
[email protected]c49085c72009-10-02 16:28:561527void RenderView::showSpellingUI(bool show) {
1528 Send(new ViewHostMsg_ShowSpellingPanel(routing_id_, show));
1529}
1530
[email protected]8922e1f2009-10-03 05:01:261531bool RenderView::isShowingSpellingUI() {
1532 return spelling_panel_visible_;
1533}
1534
[email protected]1dbafaf72009-09-23 19:43:561535void RenderView::updateSpellingUIWithMisspelledWord(const WebString& word) {
[email protected]2a3a7762009-10-19 19:17:321536 Send(new ViewHostMsg_UpdateSpellingPanelWithMisspelledWord(routing_id_,
1537 word));
[email protected]1dbafaf72009-09-23 19:43:561538}
1539
[email protected]a1128322009-10-06 18:38:461540bool RenderView::runFileChooser(
1541 bool multi_select,
1542 const WebKit::WebString& title,
1543 const WebKit::WebString& initial_value,
1544 WebKit::WebFileChooserCompletion* chooser_completion) {
1545 if (file_chooser_completion_) {
1546 // TODO(brettw): bug 1235154: This should be a synchronous message to deal
1547 // with the fact that web pages can programatically trigger this. With the
1548 // asnychronous messages, we can get an additional call when one is pending,
1549 // which this test is for. For now, we just ignore the additional file
1550 // chooser request. WebKit doesn't do anything to expect the callback, so
1551 // we can just ignore calling it.
1552 return false;
1553 }
1554 file_chooser_completion_ = chooser_completion;
1555 Send(new ViewHostMsg_RunFileChooser(
1556 routing_id_, multi_select, title,
1557 webkit_glue::WebStringToFilePath(initial_value)));
1558 return true;
1559}
1560
[email protected]48c9cf2d2009-09-16 16:47:521561void RenderView::runModalAlertDialog(
1562 WebFrame* frame, const WebString& message) {
1563 RunJavaScriptMessage(MessageBoxFlags::kIsJavascriptAlert,
1564 UTF16ToWideHack(message),
1565 std::wstring(),
1566 frame->url(),
1567 NULL);
1568}
1569
1570bool RenderView::runModalConfirmDialog(
1571 WebFrame* frame, const WebString& message) {
1572 return RunJavaScriptMessage(MessageBoxFlags::kIsJavascriptConfirm,
1573 UTF16ToWideHack(message),
1574 std::wstring(),
1575 frame->url(),
1576 NULL);
1577}
1578
1579bool RenderView::runModalPromptDialog(
1580 WebFrame* frame, const WebString& message, const WebString& default_value,
1581 WebString* actual_value) {
1582 std::wstring result;
1583 bool ok = RunJavaScriptMessage(MessageBoxFlags::kIsJavascriptPrompt,
1584 UTF16ToWideHack(message),
1585 UTF16ToWideHack(default_value),
1586 frame->url(),
1587 &result);
1588 if (ok)
1589 actual_value->assign(WideToUTF16Hack(result));
1590 return ok;
1591}
1592
1593bool RenderView::runModalBeforeUnloadDialog(
1594 WebFrame* frame, const WebString& message) {
1595 bool success = false;
1596 // This is an ignored return value, but is included so we can accept the same
1597 // response as RunJavaScriptMessage.
1598 std::wstring ignored_result;
[email protected]12636df2009-09-28 22:32:211599 SendAndRunNestedMessageLoop(new ViewHostMsg_RunBeforeUnloadConfirm(
[email protected]48c9cf2d2009-09-16 16:47:521600 routing_id_, frame->url(), UTF16ToWideHack(message), &success,
[email protected]12636df2009-09-28 22:32:211601 &ignored_result));
[email protected]48c9cf2d2009-09-16 16:47:521602 return success;
1603}
1604
[email protected]79e37442009-10-09 18:17:441605void RenderView::showContextMenu(
1606 WebFrame* frame, const WebContextMenuData& data) {
1607 Send(new ViewHostMsg_ContextMenu(routing_id_, ContextMenuParams(data)));
1608}
1609
[email protected]48c9cf2d2009-09-16 16:47:521610void RenderView::setStatusText(const WebString& text) {
1611}
1612
1613void RenderView::setMouseOverURL(const WebURL& url) {
[email protected]8d32b9832009-09-17 06:21:011614 GURL latest_url(url);
[email protected]48c9cf2d2009-09-16 16:47:521615 if (latest_url == target_url_)
1616 return;
1617 // Tell the browser to display a destination link.
1618 if (target_url_status_ == TARGET_INFLIGHT ||
1619 target_url_status_ == TARGET_PENDING) {
1620 // If we have a request in-flight, save the URL to be sent when we
1621 // receive an ACK to the in-flight request. We can happily overwrite
1622 // any existing pending sends.
1623 pending_target_url_ = latest_url;
1624 target_url_status_ = TARGET_PENDING;
1625 } else {
1626 Send(new ViewHostMsg_UpdateTargetURL(routing_id_, page_id_, latest_url));
1627 target_url_ = latest_url;
1628 target_url_status_ = TARGET_INFLIGHT;
1629 }
1630}
1631
1632void RenderView::setToolTipText(const WebString& text, WebTextDirection hint) {
1633 Send(new ViewHostMsg_SetTooltipText(routing_id_, UTF16ToWideHack(text),
1634 hint));
1635}
1636
1637void RenderView::startDragging(const WebPoint& from, const WebDragData& data,
1638 WebDragOperationsMask allowed_ops) {
1639 Send(new ViewHostMsg_StartDragging(routing_id_,
1640 WebDropData(data),
1641 allowed_ops));
1642}
1643
[email protected]28b92df2009-09-25 17:35:451644bool RenderView::acceptsLoadDrops() {
1645 return renderer_preferences_.can_accept_load_drops;
1646}
1647
[email protected]48c9cf2d2009-09-16 16:47:521648void RenderView::focusNext() {
1649 Send(new ViewHostMsg_TakeFocus(routing_id_, false));
1650}
1651
1652void RenderView::focusPrevious() {
1653 Send(new ViewHostMsg_TakeFocus(routing_id_, true));
1654}
1655
1656void RenderView::navigateBackForwardSoon(int offset) {
1657 history_back_list_count_ += offset;
1658 history_forward_list_count_ -= offset;
1659
1660 Send(new ViewHostMsg_GoToEntryAtOffset(routing_id_, offset));
1661}
1662
1663int RenderView::historyBackListCount() {
1664 return history_back_list_count_;
1665}
1666
1667int RenderView::historyForwardListCount() {
1668 return history_forward_list_count_;
1669}
1670
1671void RenderView::didAddHistoryItem() {
1672 // We don't want to update the history length for the start page
1673 // navigation.
[email protected]26aa0482009-09-30 16:55:271674 WebFrame* main_frame = webview()->mainFrame();
[email protected]48c9cf2d2009-09-16 16:47:521675 DCHECK(main_frame != NULL);
1676
1677 WebDataSource* ds = main_frame->dataSource();
1678 DCHECK(ds != NULL);
1679
1680 NavigationState* navigation_state = NavigationState::FromDataSource(ds);
1681 DCHECK(navigation_state);
1682 if (navigation_state->transition_type() == PageTransition::START_PAGE)
1683 return;
1684
1685 history_back_list_count_++;
1686 history_forward_list_count_ = 0;
1687}
1688
[email protected]8922e1f2009-10-03 05:01:261689void RenderView::didUpdateInspectorSettings() {
1690 Send(new ViewHostMsg_UpdateInspectorSettings(
1691 routing_id_, webview()->inspectorSettings().utf8()));
1692}
1693
[email protected]cd1c89e82009-10-17 03:31:551694WebDevToolsAgentClient* RenderView::devToolsAgentClient() {
1695 return devtools_agent_.get();
1696}
1697
[email protected]acca2a1f2009-10-16 03:53:391698void RenderView::queryAutofillSuggestions(const WebNode& node,
1699 const WebString& name,
1700 const WebString& value) {
1701 static int query_counter = 0;
1702 autofill_query_id_ = query_counter++;
1703 autofill_query_node_ = node;
1704 Send(new ViewHostMsg_QueryFormFieldAutofill(
1705 routing_id_, autofill_query_id_, name, value));
1706}
1707
1708void RenderView::removeAutofillSuggestions(const WebString& name,
1709 const WebString& value) {
1710 Send(new ViewHostMsg_RemoveAutofillEntry(routing_id_, name, value));
1711}
1712
[email protected]79dbc662009-09-04 05:42:511713// WebKit::WebWidgetClient ----------------------------------------------------
1714
initial.commit09911bf2008-07-26 23:55:291715// We are supposed to get a single call to Show for a newly created RenderView
1716// that was created via RenderView::CreateWebView. So, we wait until this
1717// point to dispatch the ShowView message.
1718//
1719// This method provides us with the information about how to display the newly
1720// created RenderView (i.e., as a constrained popup or as a new tab).
1721//
[email protected]4873c7d2009-07-16 06:36:281722void RenderView::show(WebNavigationPolicy policy) {
initial.commit09911bf2008-07-26 23:55:291723 DCHECK(!did_show_) << "received extraneous Show call";
1724 DCHECK(opener_id_ != MSG_ROUTING_NONE);
1725
1726 if (did_show_)
1727 return;
1728 did_show_ = true;
1729
[email protected]28295ec2009-10-16 05:34:331730 // Force new windows to a popup if they were not opened with a user gesture.
1731 if (!opened_by_user_gesture_) {
1732 // We exempt background tabs for compat with older versions of Chrome.
1733 // TODO(darin): This seems bogus. These should have a user gesture, so
1734 // we probably don't need this check.
1735 if (policy != WebKit::WebNavigationPolicyNewBackgroundTab)
1736 policy = WebKit::WebNavigationPolicyNewPopup;
1737 }
1738
initial.commit09911bf2008-07-26 23:55:291739 // NOTE: initial_pos_ may still have its default values at this point, but
1740 // that's okay. It'll be ignored if disposition is not NEW_POPUP, or the
1741 // browser process will impose a default position otherwise.
[email protected]4873c7d2009-07-16 06:36:281742 Send(new ViewHostMsg_ShowView(opener_id_, routing_id_,
1743 NavigationPolicyToDisposition(policy), initial_pos_,
1744 opened_by_user_gesture_, creator_url_));
[email protected]2533ce12009-05-09 00:02:241745 SetPendingWindowRect(initial_pos_);
initial.commit09911bf2008-07-26 23:55:291746}
1747
[email protected]4873c7d2009-07-16 06:36:281748void RenderView::closeWidgetSoon() {
[email protected]2c4410d2009-05-06 23:46:221749 if (!popup_notification_visible_)
[email protected]4873c7d2009-07-16 06:36:281750 RenderWidget::closeWidgetSoon();
[email protected]634a6f92008-12-01 21:39:311751}
1752
[email protected]4873c7d2009-07-16 06:36:281753void RenderView::runModal() {
initial.commit09911bf2008-07-26 23:55:291754 DCHECK(did_show_) << "should already have shown the view";
1755
[email protected]12636df2009-09-28 22:32:211756 SendAndRunNestedMessageLoop(new ViewHostMsg_RunModal(routing_id_));
initial.commit09911bf2008-07-26 23:55:291757}
1758
[email protected]3d9689372009-09-10 04:29:171759// WebKit::WebFrameClient -----------------------------------------------------
1760
1761WebPlugin* RenderView::createPlugin(
1762 WebFrame* frame, const WebPluginParams& params) {
1763 return new webkit_glue::WebPluginImpl(frame, params, AsWeakPtr());
1764}
1765
1766WebWorker* RenderView::createWorker(WebFrame* frame, WebWorkerClient* client) {
1767 return new WebWorkerProxy(client, RenderThread::current(), routing_id_);
1768}
1769
1770WebMediaPlayer* RenderView::createMediaPlayer(
1771 WebFrame* frame, WebMediaPlayerClient* client) {
1772 scoped_refptr<media::FilterFactoryCollection> factory =
1773 new media::FilterFactoryCollection();
1774 // Add in any custom filter factories first.
1775 const CommandLine* cmd_line = CommandLine::ForCurrentProcess();
1776 if (!cmd_line->HasSwitch(switches::kDisableAudio)) {
1777 // Add the chrome specific audio renderer.
1778 factory->AddFactory(
1779 AudioRendererImpl::CreateFactory(audio_message_filter()));
1780 }
1781
1782 // TODO(hclam): obtain the following parameters from |client|.
1783 webkit_glue::MediaResourceLoaderBridgeFactory* bridge_factory =
1784 new webkit_glue::MediaResourceLoaderBridgeFactory(
1785 GURL::EmptyGURL(), // referrer
1786 "null", // frame origin
1787 "null", // main_frame_origin
1788 base::GetCurrentProcId(),
1789 appcache::kNoHostId,
1790 routing_id());
1791
[email protected]0436b9a2009-10-23 00:23:051792 // A simple data source that keeps all data in memory.
1793 media::FilterFactory* simple_data_source_factory =
1794 webkit_glue::SimpleDataSource::CreateFactory(MessageLoop::current(),
1795 bridge_factory);
1796 // A sophisticated data source that does memory caching.
1797 media::FilterFactory* buffered_data_source_factory =
1798 webkit_glue::BufferedDataSource::CreateFactory(MessageLoop::current(),
1799 bridge_factory);
1800 if (cmd_line->HasSwitch(switches::kSimpleDataSource)) {
1801 factory->AddFactory(simple_data_source_factory);
1802 factory->AddFactory(buffered_data_source_factory);
[email protected]3d9689372009-09-10 04:29:171803 } else {
[email protected]0436b9a2009-10-23 00:23:051804 factory->AddFactory(buffered_data_source_factory);
1805 factory->AddFactory(simple_data_source_factory);
[email protected]3d9689372009-09-10 04:29:171806 }
1807 return new webkit_glue::WebMediaPlayerImpl(client, factory);
1808}
1809
1810void RenderView::willClose(WebFrame* frame) {
1811 if (!frame->parent()) {
1812 const GURL& url = frame->url();
1813 if (url.SchemeIs("http") || url.SchemeIs("https"))
1814 DumpLoadHistograms();
1815 }
1816}
1817
1818void RenderView::loadURLExternally(
1819 WebFrame* frame, const WebURLRequest& request,
1820 WebNavigationPolicy policy) {
[email protected]efce17b2009-09-11 18:04:591821 GURL referrer(request.httpHeaderField(WebString::fromUTF8("Referer")));
1822 if (policy == WebKit::WebNavigationPolicyDownload) {
1823 Send(new ViewHostMsg_DownloadUrl(routing_id_, request.url(), referrer));
1824 } else {
1825 OpenURL(request.url(), referrer, policy);
1826 }
[email protected]3d9689372009-09-10 04:29:171827}
1828
1829WebNavigationPolicy RenderView::decidePolicyForNavigation(
1830 WebFrame* frame, const WebURLRequest& request, WebNavigationType type,
[email protected]65b95cd2009-10-09 05:10:221831 const WebNode&, WebNavigationPolicy default_policy, bool is_redirect) {
[email protected]3d9689372009-09-10 04:29:171832 // Webkit is asking whether to navigate to a new URL.
1833 // This is fine normally, except if we're showing UI from one security
1834 // context and they're trying to navigate to a different context.
1835 const GURL& url = request.url();
1836
1837 // If the browser is interested, then give it a chance to look at top level
1838 // navigations
1839 if (renderer_preferences_.browser_handles_top_level_requests &&
1840 // Only send once.
1841 last_top_level_navigation_page_id_ != page_id_ &&
1842 // Not interested in reloads.
1843 type != WebKit::WebNavigationTypeReload &&
1844 type != WebKit::WebNavigationTypeFormSubmitted &&
1845 // Must be a top level frame.
1846 frame->parent() == NULL) {
1847 // Skip if navigation is on the same page (using '#').
1848 GURL frame_origin = GURL(frame->url()).GetOrigin();
1849 if (url.GetOrigin() != frame_origin || url.ref().empty()) {
1850 last_top_level_navigation_page_id_ = page_id_;
[email protected]b36a9f92009-10-19 17:34:571851 GURL referrer(request.httpHeaderField(WebString::fromUTF8("Referer")));
1852 OpenURL(url, referrer, default_policy);
[email protected]3d9689372009-09-10 04:29:171853 return WebKit::WebNavigationPolicyIgnore; // Suppress the load here.
1854 }
1855 }
1856
1857 // A content initiated navigation may have originated from a link-click,
1858 // script, drag-n-drop operation, etc.
1859 bool is_content_initiated =
1860 NavigationState::FromDataSource(frame->provisionalDataSource())->
1861 is_content_initiated();
1862
1863 // We only care about navigations that are within the current tab (as opposed
1864 // to, for example, opening a new window).
1865 // But we sometimes navigate to about:blank to clear a tab, and we want to
1866 // still allow that.
1867 if (default_policy == WebKit::WebNavigationPolicyCurrentTab &&
1868 is_content_initiated && frame->parent() == NULL &&
1869 !url.SchemeIs(chrome::kAboutScheme)) {
1870 // When we received such unsolicited navigations, we sometimes want to
1871 // punt them up to the browser to handle.
1872 if (BindingsPolicy::is_dom_ui_enabled(enabled_bindings_) ||
1873 BindingsPolicy::is_extension_enabled(enabled_bindings_) ||
1874 frame->isViewSourceModeEnabled() ||
1875 url.SchemeIs(chrome::kViewSourceScheme) ||
1876 url.SchemeIs(chrome::kPrintScheme)) {
1877 OpenURL(url, GURL(), default_policy);
1878 return WebKit::WebNavigationPolicyIgnore; // Suppress the load here.
1879 }
1880 }
1881
1882 // Detect when a page is "forking" a new tab that can be safely rendered in
1883 // its own process. This is done by sites like Gmail that try to open links
1884 // in new windows without script connections back to the original page. We
1885 // treat such cases as browser navigations (in which we will create a new
1886 // renderer for a cross-site navigation), rather than WebKit navigations.
1887 //
1888 // We use the following heuristic to decide whether to fork a new page in its
1889 // own process:
1890 // The parent page must open a new tab to about:blank, set the new tab's
1891 // window.opener to null, and then redirect the tab to a cross-site URL using
1892 // JavaScript.
1893 bool is_fork =
1894 // Must start from a tab showing about:blank, which is later redirected.
[email protected]e0d481582009-09-15 21:06:251895 GURL(frame->url()) == GURL(chrome::kAboutBlankURL) &&
[email protected]3d9689372009-09-10 04:29:171896 // Must be the first real navigation of the tab.
[email protected]48c9cf2d2009-09-16 16:47:521897 historyBackListCount() < 1 &&
1898 historyForwardListCount() < 1 &&
[email protected]3d9689372009-09-10 04:29:171899 // The parent page must have set the child's window.opener to null before
1900 // redirecting to the desired URL.
1901 frame->opener() == NULL &&
1902 // Must be a top-level frame.
1903 frame->parent() == NULL &&
1904 // Must not have issued the request from this page.
1905 is_content_initiated &&
1906 // Must be targeted at the current tab.
1907 default_policy == WebKit::WebNavigationPolicyCurrentTab &&
1908 // Must be a JavaScript navigation, which appears as "other".
1909 type == WebKit::WebNavigationTypeOther;
[email protected]69d51f92009-10-22 19:03:431910 if (is_fork) {
[email protected]3d9689372009-09-10 04:29:171911 // Open the URL via the browser, not via WebKit.
1912 OpenURL(url, GURL(), default_policy);
1913 return WebKit::WebNavigationPolicyIgnore;
1914 }
1915
1916 return default_policy;
1917}
1918
[email protected]6069da8c2009-10-20 20:33:491919bool RenderView::canHandleRequest(
1920 WebFrame* frame, const WebURLRequest& request) {
1921 // We allow WebKit to think that everything can be handled even though
1922 // browser-side we limit what we load.
[email protected]7b7a7dc2009-10-19 02:23:341923 return true;
1924}
1925
[email protected]6069da8c2009-10-20 20:33:491926WebURLError RenderView::cannotHandleRequestError(
1927 WebFrame* frame, const WebURLRequest& request) {
1928 NOTREACHED(); // Since we said we can handle all requests.
1929 return WebURLError();
1930}
1931
1932WebURLError RenderView::cancelledError(
1933 WebFrame* frame, const WebURLRequest& request) {
1934 WebURLError error;
1935 error.domain = WebString::fromUTF8(net::kErrorDomain);
1936 error.reason = net::ERR_ABORTED;
1937 error.unreachableURL = request.url();
1938 return error;
[email protected]7b7a7dc2009-10-19 02:23:341939}
1940
1941void RenderView::unableToImplementPolicyWithError(
[email protected]6069da8c2009-10-20 20:33:491942 WebFrame*, const WebURLError&) {
1943 NOTREACHED(); // Since we said we can handle all requests.
[email protected]7b7a7dc2009-10-19 02:23:341944}
1945
[email protected]3d9689372009-09-10 04:29:171946void RenderView::willSubmitForm(WebFrame* frame, const WebForm& form) {
1947 NavigationState* navigation_state =
1948 NavigationState::FromDataSource(frame->provisionalDataSource());
1949
1950 if (navigation_state->transition_type() == PageTransition::LINK)
1951 navigation_state->set_transition_type(PageTransition::FORM_SUBMIT);
1952
1953 // Save these to be processed when the ensuing navigation is committed.
1954 navigation_state->set_searchable_form_data(
1955 SearchableFormData::Create(form));
1956 navigation_state->set_password_form_data(
1957 PasswordFormDomManager::CreatePasswordForm(form));
1958
1959 if (form.isAutoCompleteEnabled()) {
[email protected]c54d269e2009-10-21 18:07:381960 scoped_ptr<FormFieldValues> form_values(FormFieldValues::Create(form));
1961 if (form_values.get())
[email protected]51bd36612009-10-20 22:49:471962 Send(new ViewHostMsg_FormFieldValuesSubmitted(routing_id_,
[email protected]c54d269e2009-10-21 18:07:381963 *form_values));
[email protected]3d9689372009-09-10 04:29:171964 }
1965}
1966
1967void RenderView::willPerformClientRedirect(
1968 WebFrame* frame, const WebURL& from, const WebURL& to, double interval,
1969 double fire_time) {
1970 // Ignore
1971}
1972
1973void RenderView::didCancelClientRedirect(WebFrame* frame) {
1974 // Ignore
1975}
1976
1977void RenderView::didCompleteClientRedirect(
1978 WebFrame* frame, const WebURL& from) {
1979 if (!frame->parent())
1980 completed_client_redirect_src_ = from;
1981}
1982
1983void RenderView::didCreateDataSource(WebFrame* frame, WebDataSource* ds) {
1984 // The rest of RenderView assumes that a WebDataSource will always have a
1985 // non-null NavigationState.
1986 if (pending_navigation_state_.get()) {
1987 ds->setExtraData(pending_navigation_state_.release());
1988 } else {
1989 ds->setExtraData(NavigationState::CreateContentInitiated());
1990 }
1991}
1992
1993void RenderView::didStartProvisionalLoad(WebFrame* frame) {
1994 WebDataSource* ds = frame->provisionalDataSource();
1995 NavigationState* navigation_state = NavigationState::FromDataSource(ds);
1996
1997 navigation_state->set_start_load_time(Time::Now());
1998
1999 // Update the request time if WebKit has better knowledge of it.
2000 if (navigation_state->request_time().is_null()) {
2001 double event_time = ds->triggeringEventTime();
2002 if (event_time != 0.0)
2003 navigation_state->set_request_time(Time::FromDoubleT(event_time));
2004 }
2005
2006 bool is_top_most = !frame->parent();
2007 if (is_top_most) {
2008 navigation_gesture_ = frame->isProcessingUserGesture() ?
2009 NavigationGestureUnknown : NavigationGestureAuto;
2010
2011 // Make sure redirect tracking state is clear for the new load.
2012 completed_client_redirect_src_ = GURL();
2013 } else if (frame->parent()->isLoading()) {
2014 // Take note of AUTO_SUBFRAME loads here, so that we can know how to
2015 // load an error page. See DidFailProvisionalLoadWithError.
2016 navigation_state->set_transition_type(PageTransition::AUTO_SUBFRAME);
2017 }
2018
2019 Send(new ViewHostMsg_DidStartProvisionalLoadForFrame(
2020 routing_id_, is_top_most, ds->request().url()));
2021}
2022
2023void RenderView::didReceiveServerRedirectForProvisionalLoad(WebFrame* frame) {
2024 if (frame->parent())
2025 return;
2026 // Received a redirect on the main frame.
2027 WebDataSource* data_source = frame->provisionalDataSource();
2028 if (!data_source) {
2029 // Should only be invoked when we have a data source.
2030 NOTREACHED();
2031 return;
2032 }
2033 std::vector<GURL> redirects;
2034 GetRedirectChain(data_source, &redirects);
2035 if (redirects.size() >= 2) {
2036 Send(new ViewHostMsg_DidRedirectProvisionalLoad(
2037 routing_id_, page_id_, redirects[redirects.size() - 2],
2038 redirects[redirects.size() - 1]));
2039 }
2040}
2041
2042void RenderView::didFailProvisionalLoad(
2043 WebFrame* frame, const WebURLError& error) {
2044 // Notify the browser that we failed a provisional load with an error.
2045 //
2046 // Note: It is important this notification occur before DidStopLoading so the
2047 // SSL manager can react to the provisional load failure before being
2048 // notified the load stopped.
2049 //
2050 WebDataSource* ds = frame->provisionalDataSource();
2051 DCHECK(ds);
2052
2053 const WebURLRequest& failed_request = ds->request();
2054
2055 bool show_repost_interstitial =
2056 (error.reason == net::ERR_CACHE_MISS &&
2057 EqualsASCII(failed_request.httpMethod(), "POST"));
2058 Send(new ViewHostMsg_DidFailProvisionalLoadWithError(
2059 routing_id_, !frame->parent(), error.reason, error.unreachableURL,
2060 show_repost_interstitial));
2061
2062 // Don't display an error page if this is simply a cancelled load. Aside
2063 // from being dumb, WebCore doesn't expect it and it will cause a crash.
2064 if (error.reason == net::ERR_ABORTED)
2065 return;
2066
2067 // Make sure we never show errors in view source mode.
2068 frame->enableViewSourceMode(false);
2069
2070 NavigationState* navigation_state = NavigationState::FromDataSource(ds);
2071
2072 // If this is a failed back/forward/reload navigation, then we need to do a
2073 // 'replace' load. This is necessary to avoid messing up session history.
2074 // Otherwise, we do a normal load, which simulates a 'go' navigation as far
2075 // as session history is concerned.
2076 //
2077 // AUTO_SUBFRAME loads should always be treated as loads that do not advance
2078 // the page id.
2079 //
2080 bool replace =
2081 navigation_state->pending_page_id() != -1 ||
2082 navigation_state->transition_type() == PageTransition::AUTO_SUBFRAME;
2083
2084 // If we failed on a browser initiated request, then make sure that our error
2085 // page load is regarded as the same browser initiated request.
2086 if (!navigation_state->is_content_initiated()) {
2087 pending_navigation_state_.reset(NavigationState::CreateBrowserInitiated(
2088 navigation_state->pending_page_id(),
2089 navigation_state->transition_type(),
2090 navigation_state->request_time()));
2091 }
2092
2093 // Provide the user with a more helpful error page?
2094 if (MaybeLoadAlternateErrorPage(frame, error, replace))
2095 return;
2096
2097 // Fallback to a local error page.
2098 LoadNavigationErrorPage(frame, failed_request, error, std::string(),
2099 replace);
2100}
2101
2102void RenderView::didReceiveDocumentData(
2103 WebFrame* frame, const char* data, size_t data_len,
2104 bool& prevent_default) {
2105 NavigationState* navigation_state =
2106 NavigationState::FromDataSource(frame->dataSource());
2107 if (!navigation_state->postpone_loading_data())
2108 return;
2109
2110 // We're going to call commitDocumentData ourselves...
2111 prevent_default = true;
2112
2113 // Continue buffering the response data for the original 404 page. If it
2114 // grows too large, then we'll just let it through.
2115 navigation_state->append_postponed_data(data, data_len);
2116 if (navigation_state->postponed_data().size() >= 512) {
2117 navigation_state->set_postpone_loading_data(false);
2118 frame->commitDocumentData(navigation_state->postponed_data().data(),
2119 navigation_state->postponed_data().size());
2120 navigation_state->clear_postponed_data();
2121 }
2122}
2123
2124void RenderView::didCommitProvisionalLoad(
2125 WebFrame* frame, bool is_new_navigation) {
2126 NavigationState* navigation_state =
2127 NavigationState::FromDataSource(frame->dataSource());
2128
2129 navigation_state->set_commit_load_time(Time::Now());
2130 if (is_new_navigation) {
2131 // When we perform a new navigation, we need to update the previous session
2132 // history entry with state for the page we are leaving.
2133 UpdateSessionHistory(frame);
2134
2135 // We bump our Page ID to correspond with the new session history entry.
2136 page_id_ = next_page_id_++;
2137
2138 MessageLoop::current()->PostDelayedTask(FROM_HERE,
2139 method_factory_.NewRunnableMethod(&RenderView::CapturePageInfo,
2140 page_id_, true),
2141 kDelayForForcedCaptureMs);
2142 } else {
2143 // Inspect the navigation_state on this frame to see if the navigation
2144 // corresponds to a session history navigation... Note: |frame| may or
2145 // may not be the toplevel frame, but for the case of capturing session
2146 // history, the first committed frame suffices. We keep track of whether
2147 // we've seen this commit before so that only capture session history once
2148 // per navigation.
2149 //
2150 // Note that we need to check if the page ID changed. In the case of a
2151 // reload, the page ID doesn't change, and UpdateSessionHistory gets the
2152 // previous URL and the current page ID, which would be wrong.
2153 if (navigation_state->pending_page_id() != -1 &&
2154 navigation_state->pending_page_id() != page_id_ &&
2155 !navigation_state->request_committed()) {
2156 // This is a successful session history navigation!
2157 UpdateSessionHistory(frame);
2158 page_id_ = navigation_state->pending_page_id();
2159 }
2160 }
2161
2162 // Remember that we've already processed this request, so we don't update
2163 // the session history again. We do this regardless of whether this is
2164 // a session history navigation, because if we attempted a session history
2165 // navigation without valid HistoryItem state, WebCore will think it is a
2166 // new navigation.
2167 navigation_state->set_request_committed(true);
2168
2169 UpdateURL(frame);
2170
2171 // If this committed load was initiated by a client redirect, we're
2172 // at the last stop now, so clear it.
2173 completed_client_redirect_src_ = GURL();
2174
2175 // Check whether we have new encoding name.
[email protected]26aa0482009-09-30 16:55:272176 UpdateEncoding(frame, frame->view()->pageEncoding().utf8());
[email protected]3d9689372009-09-10 04:29:172177}
2178
2179void RenderView::didClearWindowObject(WebFrame* frame) {
2180 if (BindingsPolicy::is_dom_automation_enabled(enabled_bindings_))
2181 BindDOMAutomationController(frame);
2182 if (BindingsPolicy::is_dom_ui_enabled(enabled_bindings_)) {
2183 dom_ui_bindings_.set_message_sender(this);
2184 dom_ui_bindings_.set_routing_id(routing_id_);
2185 dom_ui_bindings_.BindToJavascript(frame, L"chrome");
2186 }
2187 if (BindingsPolicy::is_external_host_enabled(enabled_bindings_)) {
2188 external_host_bindings_.set_message_sender(this);
2189 external_host_bindings_.set_routing_id(routing_id_);
2190 external_host_bindings_.BindToJavascript(frame, L"externalHost");
2191 }
2192}
2193
2194void RenderView::didCreateDocumentElement(WebFrame* frame) {
2195 if (RenderThread::current()) { // Will be NULL during unit tests.
2196 RenderThread::current()->user_script_slave()->InjectScripts(
2197 frame, UserScript::DOCUMENT_START);
2198 }
[email protected]078b34612009-09-19 19:31:512199 if (view_type_ == ViewType::EXTENSION_TOOLSTRIP ||
2200 view_type_ == ViewType::EXTENSION_MOLE) {
2201 InjectToolstripCSS();
2202 ExtensionProcessBindings::SetViewType(webview(), view_type_);
2203 }
[email protected]3d9689372009-09-10 04:29:172204
[email protected]912256b32009-09-18 09:47:352205 while (!pending_code_execution_queue_.empty()) {
2206 scoped_refptr<CodeExecutionInfo> info =
2207 pending_code_execution_queue_.front();
2208 OnExecuteCode(info->request_id, info->extension_id, info->is_js_code,
2209 info->code_string);
2210 pending_code_execution_queue_.pop();
2211 }
2212
[email protected]3d9689372009-09-10 04:29:172213 // Notify the browser about non-blank documents loading in the top frame.
2214 GURL url = frame->url();
[email protected]e0d481582009-09-15 21:06:252215 if (url.is_valid() && url.spec() != chrome::kAboutBlankURL) {
[email protected]26aa0482009-09-30 16:55:272216 if (frame == webview()->mainFrame())
[email protected]3d9689372009-09-10 04:29:172217 Send(new ViewHostMsg_DocumentAvailableInMainFrame(routing_id_));
2218 }
2219}
2220
2221void RenderView::didReceiveTitle(WebFrame* frame, const WebString& title) {
2222 UpdateTitle(frame, title);
2223
2224 // Also check whether we have new encoding name.
[email protected]26aa0482009-09-30 16:55:272225 UpdateEncoding(frame, frame->view()->pageEncoding().utf8());
[email protected]3d9689372009-09-10 04:29:172226}
2227
2228void RenderView::didFinishDocumentLoad(WebFrame* frame) {
2229 WebDataSource* ds = frame->dataSource();
2230 NavigationState* navigation_state = NavigationState::FromDataSource(ds);
2231 DCHECK(navigation_state);
2232 navigation_state->set_finish_document_load_time(Time::Now());
2233
2234 Send(new ViewHostMsg_DocumentLoadedInFrame(routing_id_));
2235
2236 // The document has now been fully loaded. Scan for password forms to be
2237 // sent up to the browser.
2238 SendPasswordForms(frame);
2239
2240 // Check whether we have new encoding name.
[email protected]26aa0482009-09-30 16:55:272241 UpdateEncoding(frame, frame->view()->pageEncoding().utf8());
[email protected]3d9689372009-09-10 04:29:172242
2243 if (RenderThread::current()) { // Will be NULL during unit tests.
2244 RenderThread::current()->user_script_slave()->InjectScripts(
2245 frame, UserScript::DOCUMENT_END);
2246 }
2247}
2248
2249void RenderView::didHandleOnloadEvents(WebFrame* frame) {
2250 // Ignore
2251}
2252
2253void RenderView::didFailLoad(WebFrame* frame, const WebURLError& error) {
2254 // Ignore
2255}
2256
2257void RenderView::didFinishLoad(WebFrame* frame) {
2258 WebDataSource* ds = frame->dataSource();
2259 NavigationState* navigation_state = NavigationState::FromDataSource(ds);
2260 DCHECK(navigation_state);
2261 navigation_state->set_finish_load_time(Time::Now());
2262}
2263
2264void RenderView::didChangeLocationWithinPage(
2265 WebFrame* frame, bool is_new_navigation) {
2266 // If this was a reference fragment navigation that we initiated, then we
2267 // could end up having a non-null pending navigation state. We just need to
2268 // update the ExtraData on the datasource so that others who read the
2269 // ExtraData will get the new NavigationState. Similarly, if we did not
2270 // initiate this navigation, then we need to take care to reset any pre-
2271 // existing navigation state to a content-initiated navigation state.
2272 // DidCreateDataSource conveniently takes care of this for us.
2273 didCreateDataSource(frame, frame->dataSource());
2274
2275 didCommitProvisionalLoad(frame, is_new_navigation);
2276
[email protected]26aa0482009-09-30 16:55:272277 UpdateTitle(frame, frame->view()->mainFrame()->dataSource()->pageTitle());
[email protected]3d9689372009-09-10 04:29:172278}
2279
[email protected]476b6f82009-09-10 21:00:592280void RenderView::didUpdateCurrentHistoryItem(WebFrame* frame) {
2281 if (!nav_state_sync_timer_.IsRunning()) {
2282 nav_state_sync_timer_.Start(
2283 TimeDelta::FromSeconds(delay_seconds_for_form_state_sync_), this,
2284 &RenderView::SyncNavigationState);
2285 }
2286}
2287
[email protected]3d9689372009-09-10 04:29:172288void RenderView::assignIdentifierToRequest(
2289 WebFrame* frame, unsigned identifier, const WebURLRequest& request) {
2290 // Ignore
2291}
2292
2293void RenderView::willSendRequest(
2294 WebFrame* frame, unsigned identifier, WebURLRequest& request,
2295 const WebURLResponse& redirect_response) {
2296 request.setRequestorID(routing_id_);
2297}
2298
2299void RenderView::didReceiveResponse(
2300 WebFrame* frame, unsigned identifier, const WebURLResponse& response) {
2301 // Consider loading an alternate error page for 404 responses.
2302 if (response.httpStatusCode() != 404)
2303 return;
2304
2305 // Only do this for responses that correspond to a provisional data source
2306 // of the top-most frame. If we have a provisional data source, then we
2307 // can't have any sub-resources yet, so we know that this response must
2308 // correspond to a frame load.
2309 if (!frame->provisionalDataSource() || frame->parent())
2310 return;
2311
2312 // If we are in view source mode, then just let the user see the source of
2313 // the server's 404 error page.
2314 if (frame->isViewSourceModeEnabled())
2315 return;
2316
2317 // Can we even load an alternate error page for this URL?
2318 if (!GetAlternateErrorPageURL(response.url(), HTTP_404).is_valid())
2319 return;
2320
2321 NavigationState* navigation_state =
2322 NavigationState::FromDataSource(frame->provisionalDataSource());
2323 navigation_state->set_postpone_loading_data(true);
2324 navigation_state->clear_postponed_data();
2325}
2326
2327void RenderView::didFinishResourceLoad(
2328 WebFrame* frame, unsigned identifier) {
2329 NavigationState* navigation_state =
2330 NavigationState::FromDataSource(frame->dataSource());
2331 if (!navigation_state->postpone_loading_data())
2332 return;
2333
2334 // The server returned a 404 and the content was < 512 bytes (which we
2335 // suppressed). Go ahead and fetch the alternate page content.
2336
2337 const GURL& frame_url = frame->url();
2338
2339 const GURL& error_page_url = GetAlternateErrorPageURL(frame_url, HTTP_404);
2340 DCHECK(error_page_url.is_valid());
2341
2342 WebURLError original_error;
2343 original_error.unreachableURL = frame_url;
2344
2345 navigation_state->set_alt_error_page_fetcher(
2346 new AltErrorPageResourceFetcher(
2347 error_page_url, frame, original_error,
2348 NewCallback(this, &RenderView::AltErrorPageFinished)));
2349}
2350
2351void RenderView::didFailResourceLoad(
2352 WebFrame* frame, unsigned identifier, const WebURLError& error) {
2353 // Ignore
2354}
2355
2356void RenderView::didLoadResourceFromMemoryCache(
2357 WebFrame* frame, const WebURLRequest& request,
2358 const WebURLResponse& response) {
2359 // Let the browser know we loaded a resource from the memory cache. This
2360 // message is needed to display the correct SSL indicators.
2361 Send(new ViewHostMsg_DidLoadResourceFromMemoryCache(
2362 routing_id_,
2363 request.url(),
[email protected]91733b62009-09-18 06:21:092364 frame->securityOrigin().toString().utf8(),
2365 frame->top()->securityOrigin().toString().utf8(),
[email protected]3d9689372009-09-10 04:29:172366 response.securityInfo()));
2367}
2368
[email protected]6069da8c2009-10-20 20:33:492369void RenderView::didDisplayInsecureContent(WebFrame* frame) {
[email protected]e3d60e5d2009-09-25 21:08:292370 Send(new ViewHostMsg_DidDisplayInsecureContent(routing_id_));
2371}
2372
2373void RenderView::didRunInsecureContent(
2374 WebFrame* frame, const WebSecurityOrigin& origin) {
2375 Send(new ViewHostMsg_DidRunInsecureContent(
2376 routing_id_,
2377 origin.toString().utf8()));
2378}
2379
[email protected]3d9689372009-09-10 04:29:172380void RenderView::didExhaustMemoryAvailableForScript(WebFrame* frame) {
2381 Send(new ViewHostMsg_JSOutOfMemory(routing_id_));
2382}
2383
[email protected]0c882b282009-10-07 17:01:282384void RenderView::didCreateScriptContext(WebFrame* frame) {
2385 EventBindings::HandleContextCreated(frame, false);
2386}
2387
2388void RenderView::didDestroyScriptContext(WebFrame* frame) {
2389 EventBindings::HandleContextDestroyed(frame);
2390}
2391
2392void RenderView::didCreateIsolatedScriptContext(WebFrame* frame) {
2393 EventBindings::HandleContextCreated(frame, true);
2394}
2395
[email protected]3d9689372009-09-10 04:29:172396void RenderView::didChangeContentsSize(WebFrame* frame, const WebSize& size) {
2397 // We don't always want to send the change messages over IPC, only if we've
[email protected]ab32b16c2009-10-16 14:57:252398 // be put in that mode by getting a |ViewMsg_EnablePreferredSizeChangedMode|
[email protected]3d9689372009-09-10 04:29:172399 // message.
[email protected]ab32b16c2009-10-16 14:57:252400 if (send_preferred_size_changes_) {
[email protected]3d9689372009-09-10 04:29:172401 // WebCore likes to tell us things have changed even when they haven't, so
[email protected]ab32b16c2009-10-16 14:57:252402 // cache the width and height and only send the IPC message when we're sure
2403 // they're different.
[email protected]26aa0482009-09-30 16:55:272404 int width = webview()->mainFrame()->contentsPreferredWidth();
[email protected]ab32b16c2009-10-16 14:57:252405 if (width != preferred_size_.width() ||
2406 size.height != preferred_size_.height()) {
2407 preferred_size_.set_width(width);
2408
2409 // TODO(erikkay) the contents size is not really the same as the
2410 // preferred size. It's just the current size. This means that for
2411 // height, it will only ever grow, it will never shrink.
2412 preferred_size_.set_height(size.height);
2413 Send(new ViewHostMsg_DidContentsPreferredSizeChange(routing_id_,
2414 preferred_size_));
[email protected]3d9689372009-09-10 04:29:172415 }
2416 }
2417}
2418
[email protected]8922e1f2009-10-03 05:01:262419void RenderView::reportFindInPageMatchCount(int request_id, int count,
2420 bool final_update) {
2421 // If we have a message that has been queued up, then we should just replace
2422 // it. The ACK from the browser will make sure it gets sent when the browser
2423 // wants it.
2424 if (queued_find_reply_message_.get()) {
2425 IPC::Message* msg = new ViewHostMsg_Find_Reply(
2426 routing_id_,
2427 request_id,
2428 count,
2429 gfx::Rect(),
2430 -1, // Don't update active match ordinal.
2431 final_update);
2432 queued_find_reply_message_.reset(msg);
2433 } else {
2434 // Send the search result over to the browser process.
2435 Send(new ViewHostMsg_Find_Reply(
2436 routing_id_,
2437 request_id,
2438 count,
2439 gfx::Rect(),
2440 -1, // // Don't update active match ordinal.
2441 final_update));
2442 }
2443}
2444
2445void RenderView::reportFindInPageSelection(int request_id,
2446 int active_match_ordinal,
2447 const WebRect& selection_rect) {
2448 // Send the search result over to the browser process.
2449 Send(new ViewHostMsg_Find_Reply(routing_id_,
2450 request_id,
2451 -1,
2452 selection_rect,
2453 active_match_ordinal,
2454 false));
2455}
2456
[email protected]79dbc662009-09-04 05:42:512457// webkit_glue::WebPluginPageDelegate -----------------------------------------
2458
[email protected]f103ab72009-09-02 17:10:592459webkit_glue::WebPluginDelegate* RenderView::CreatePluginDelegate(
2460 const GURL& url,
2461 const std::string& mime_type,
[email protected]f103ab72009-09-02 17:10:592462 std::string* actual_mime_type) {
2463 if (!PluginChannelHost::IsListening())
2464 return NULL;
2465
2466 GURL policy_url;
[email protected]26aa0482009-09-30 16:55:272467 WebFrame* main_frame = webview()->mainFrame();
[email protected]f103ab72009-09-02 17:10:592468 if (main_frame)
2469 policy_url = main_frame->url();
2470
2471 FilePath path;
[email protected]610c0892009-09-08 19:46:182472 render_thread_->Send(new ViewHostMsg_GetPluginPath(
2473 url, policy_url, mime_type, &path, actual_mime_type));
[email protected]f103ab72009-09-02 17:10:592474 if (path.value().empty())
2475 return NULL;
2476
2477 const std::string* mime_type_to_use;
2478 if (!actual_mime_type->empty())
2479 mime_type_to_use = actual_mime_type;
2480 else
2481 mime_type_to_use = &mime_type;
2482
[email protected]26e8d5e2009-10-13 02:47:162483#if defined(PEPPER_APIS_ENABLED)
2484 const char kPepperPrefix[] = "pepper-";
2485 if (StartsWithASCII(*mime_type_to_use, kPepperPrefix, true)) {
[email protected]d439ba072009-10-17 22:32:292486 return WebPluginDelegatePepper::Create(
[email protected]26e8d5e2009-10-13 02:47:162487 path, *mime_type_to_use, gfx::NativeViewFromId(host_window_));
2488 }
2489#endif
2490
[email protected]d032f492009-09-29 00:33:462491 bool in_process_plugin = RenderProcess::current()->in_process_plugins();
2492 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kInternalNaCl)) {
2493 if (mime_type == "application/x-nacl-srpc") {
2494 in_process_plugin = true;
2495 }
2496 }
2497 if (in_process_plugin) {
[email protected]f103ab72009-09-02 17:10:592498#if defined(OS_WIN) // In-proc plugins aren't supported on Linux or Mac.
[email protected]8a3b7962009-09-04 05:53:232499 return WebPluginDelegateImpl::Create(
[email protected]f103ab72009-09-02 17:10:592500 path, *mime_type_to_use, gfx::NativeViewFromId(host_window_));
2501#else
2502 NOTIMPLEMENTED();
2503 return NULL;
2504#endif
2505 }
2506
[email protected]610c0892009-09-08 19:46:182507 return new WebPluginDelegateProxy(*mime_type_to_use, AsWeakPtr());
[email protected]f103ab72009-09-02 17:10:592508}
2509
2510void RenderView::CreatedPluginWindow(gfx::PluginWindowHandle window) {
2511#if defined(OS_LINUX)
2512 RenderThread::current()->Send(new ViewHostMsg_CreatePluginContainer(
2513 routing_id(), window));
2514#endif
2515}
2516
2517void RenderView::WillDestroyPluginWindow(gfx::PluginWindowHandle window) {
2518#if defined(OS_LINUX)
2519 RenderThread::current()->Send(new ViewHostMsg_DestroyPluginContainer(
2520 routing_id(), window));
2521#endif
2522 CleanupWindowInPluginMoves(window);
2523}
2524
2525void RenderView::DidMovePlugin(const webkit_glue::WebPluginGeometry& move) {
2526 SchedulePluginMove(move);
2527}
2528
2529void RenderView::DidStartLoadingForPlugin() {
2530 // TODO(darin): Make is_loading_ be a counter!
[email protected]48c9cf2d2009-09-16 16:47:522531 didStartLoading();
[email protected]f103ab72009-09-02 17:10:592532}
2533
2534void RenderView::DidStopLoadingForPlugin() {
2535 // TODO(darin): Make is_loading_ be a counter!
[email protected]48c9cf2d2009-09-16 16:47:522536 didStopLoading();
[email protected]f103ab72009-09-02 17:10:592537}
2538
2539void RenderView::ShowModalHTMLDialogForPlugin(
2540 const GURL& url,
2541 const gfx::Size& size,
2542 const std::string& json_arguments,
2543 std::string* json_retval) {
[email protected]12636df2009-09-28 22:32:212544 SendAndRunNestedMessageLoop(new ViewHostMsg_ShowModalHTMLDialog(
[email protected]f103ab72009-09-02 17:10:592545 routing_id_, url, size.width(), size.height(), json_arguments,
[email protected]12636df2009-09-28 22:32:212546 json_retval));
[email protected]f103ab72009-09-02 17:10:592547}
2548
initial.commit09911bf2008-07-26 23:55:292549void RenderView::SyncNavigationState() {
2550 if (!webview())
2551 return;
2552
[email protected]26aa0482009-09-30 16:55:272553 const WebHistoryItem& item = webview()->mainFrame()->currentHistoryItem();
[email protected]ca948a22009-06-25 19:36:172554 if (item.isNull())
initial.commit09911bf2008-07-26 23:55:292555 return;
[email protected]ca948a22009-06-25 19:36:172556
2557 Send(new ViewHostMsg_UpdateState(
2558 routing_id_, page_id_, webkit_glue::HistoryItemToString(item)));
initial.commit09911bf2008-07-26 23:55:292559}
2560
[email protected]b0950a72009-09-29 23:16:172561bool RenderView::DownloadImage(int id, const GURL& image_url, int image_size) {
2562 // Make sure webview was not shut down.
2563 if (!webview())
2564 return false;
2565 // Create an image resource fetcher and assign it with a call back object.
2566 image_fetchers_.insert(new ImageResourceFetcher(
[email protected]26aa0482009-09-30 16:55:272567 image_url, webview()->mainFrame(), id, image_size,
[email protected]b0950a72009-09-29 23:16:172568 NewCallback(this, &RenderView::DidDownloadImage)));
2569 return true;
2570}
2571
2572void RenderView::DidDownloadImage(ImageResourceFetcher* fetcher,
initial.commit09911bf2008-07-26 23:55:292573 const SkBitmap& image) {
[email protected]b0950a72009-09-29 23:16:172574 // Notify requester of image download status.
[email protected]51bd36612009-10-20 22:49:472575 Send(new ViewHostMsg_DidDownloadFavIcon(routing_id_,
2576 fetcher->id(),
2577 fetcher->image_url(),
2578 image.isNull(),
2579 image));
[email protected]b0950a72009-09-29 23:16:172580 // Dispose of the image fetcher.
2581 DCHECK(image_fetchers_.find(fetcher) != image_fetchers_.end());
2582 image_fetchers_.erase(fetcher);
2583 // We're in the callback from the ImageResourceFetcher, best to delay
2584 // deletion.
2585 MessageLoop::current()->DeleteSoon(FROM_HERE, fetcher);
initial.commit09911bf2008-07-26 23:55:292586}
2587
[email protected]bf5c2ff392009-07-08 16:24:332588void RenderView::OnDownloadFavIcon(int id,
2589 const GURL& image_url,
2590 int image_size) {
[email protected]f11ca0732009-04-11 00:09:342591 bool data_image_failed = false;
2592 if (image_url.SchemeIs("data")) {
2593 SkBitmap data_image = ImageFromDataUrl(image_url);
2594 data_image_failed = data_image.empty();
2595 if (!data_image_failed) {
[email protected]bf5c2ff392009-07-08 16:24:332596 Send(new ViewHostMsg_DidDownloadFavIcon(routing_id_, id, image_url, false,
2597 data_image));
[email protected]f11ca0732009-04-11 00:09:342598 }
2599 }
2600
[email protected]bf5c2ff392009-07-08 16:24:332601 if (data_image_failed ||
[email protected]b0950a72009-09-29 23:16:172602 !DownloadImage(id, image_url, image_size)) {
[email protected]bf5c2ff392009-07-08 16:24:332603 Send(new ViewHostMsg_DidDownloadFavIcon(routing_id_, id, image_url, true,
2604 SkBitmap()));
2605 }
initial.commit09911bf2008-07-26 23:55:292606}
2607
[email protected]f11ca0732009-04-11 00:09:342608SkBitmap RenderView::ImageFromDataUrl(const GURL& url) const {
2609 std::string mime_type, char_set, data;
2610 if (net::DataURL::Parse(url, &mime_type, &char_set, &data) && !data.empty()) {
2611 // Decode the favicon using WebKit's image decoder.
2612 webkit_glue::ImageDecoder decoder(gfx::Size(kFavIconSize, kFavIconSize));
2613 const unsigned char* src_data =
2614 reinterpret_cast<const unsigned char*>(&data[0]);
2615
2616 return decoder.Decode(src_data, data.size());
2617 }
2618 return SkBitmap();
2619}
2620
initial.commit09911bf2008-07-26 23:55:292621void RenderView::OnGetApplicationInfo(int page_id) {
2622 webkit_glue::WebApplicationInfo app_info;
2623 if (page_id == page_id_)
2624 webkit_glue::GetApplicationInfo(webview(), &app_info);
2625
2626 // Prune out any data URLs in the set of icons. The browser process expects
2627 // any icon with a data URL to have originated from a favicon. We don't want
2628 // to decode arbitrary data URLs in the browser process. See
2629 // http://b/issue?id=1162972
2630 for (size_t i = 0; i < app_info.icons.size(); ++i) {
[email protected]6de74452009-02-25 18:04:592631 if (app_info.icons[i].url.SchemeIs(chrome::kDataScheme)) {
initial.commit09911bf2008-07-26 23:55:292632 app_info.icons.erase(app_info.icons.begin() + i);
2633 --i;
2634 }
2635 }
2636
2637 Send(new ViewHostMsg_DidGetApplicationInfo(routing_id_, page_id, app_info));
2638}
2639
[email protected]7ccddb8c2009-08-04 17:36:552640GURL RenderView::GetAlternateErrorPageURL(const GURL& failed_url,
initial.commit09911bf2008-07-26 23:55:292641 ErrorPageType error_type) {
[email protected]7ccddb8c2009-08-04 17:36:552642 if (failed_url.SchemeIsSecure()) {
initial.commit09911bf2008-07-26 23:55:292643 // If the URL that failed was secure, then the embedding web page was not
2644 // expecting a network attacker to be able to manipulate its contents. As
2645 // we fetch alternate error pages over HTTP, we would be allowing a network
2646 // attacker to manipulate the contents of the response if we tried to use
2647 // the link doctor here.
2648 return GURL::EmptyGURL();
2649 }
2650
2651 // Grab the base URL from the browser process.
2652 if (!alternate_error_page_url_.is_valid())
2653 return GURL::EmptyGURL();
2654
2655 // Strip query params from the failed URL.
2656 GURL::Replacements remove_params;
2657 remove_params.ClearUsername();
2658 remove_params.ClearPassword();
2659 remove_params.ClearQuery();
2660 remove_params.ClearRef();
[email protected]7ccddb8c2009-08-04 17:36:552661 const GURL url_to_send = failed_url.ReplaceComponents(remove_params);
initial.commit09911bf2008-07-26 23:55:292662
2663 // Construct the query params to send to link doctor.
2664 std::string params(alternate_error_page_url_.query());
2665 params.append("&url=");
2666 params.append(EscapeQueryParamValue(url_to_send.spec()));
2667 params.append("&sourceid=chrome");
2668 params.append("&error=");
2669 switch (error_type) {
2670 case DNS_ERROR:
2671 params.append("dnserror");
2672 break;
2673
2674 case HTTP_404:
2675 params.append("http404");
2676 break;
2677
[email protected]5df266ac2008-10-15 19:50:132678 case CONNECTION_ERROR:
[email protected]e1f934b2009-01-26 20:41:332679 params.append("connectionfailure");
[email protected]5df266ac2008-10-15 19:50:132680 break;
2681
initial.commit09911bf2008-07-26 23:55:292682 default:
2683 NOTREACHED() << "unknown ErrorPageType";
2684 }
2685
2686 // OK, build the final url to return.
2687 GURL::Replacements link_doctor_params;
2688 link_doctor_params.SetQueryStr(params);
2689 GURL url = alternate_error_page_url_.ReplaceComponents(link_doctor_params);
2690 return url;
2691}
2692
[email protected]6069da8c2009-10-20 20:33:492693void RenderView::OnFind(int request_id, const string16& search_text,
2694 const WebFindOptions& options) {
[email protected]26aa0482009-09-30 16:55:272695 WebFrame* main_frame = webview()->mainFrame();
[email protected]b4bb2502009-10-01 22:35:272696 WebFrame* frame_after_main = main_frame->traverseNext(true);
[email protected]26aa0482009-09-30 16:55:272697 WebFrame* focused_frame = webview()->focusedFrame();
initial.commit09911bf2008-07-26 23:55:292698 WebFrame* search_frame = focused_frame; // start searching focused frame.
2699
2700 bool multi_frame = (frame_after_main != main_frame);
2701
2702 // If we have multiple frames, we don't want to wrap the search within the
2703 // frame, so we check here if we only have main_frame in the chain.
2704 bool wrap_within_frame = !multi_frame;
2705
[email protected]b3f2b912009-04-09 16:18:522706 WebRect selection_rect;
initial.commit09911bf2008-07-26 23:55:292707 bool result = false;
2708
2709 do {
[email protected]dd7daa82009-08-10 05:46:452710 result = search_frame->find(
[email protected]7ea066a2009-04-06 20:21:592711 request_id, search_text, options, wrap_within_frame, &selection_rect);
initial.commit09911bf2008-07-26 23:55:292712
2713 if (!result) {
2714 // don't leave text selected as you move to the next frame.
[email protected]a100d76bb2009-08-14 17:50:222715 search_frame->executeCommand(WebString::fromUTF8("Unselect"));
initial.commit09911bf2008-07-26 23:55:292716
2717 // Find the next frame, but skip the invisible ones.
2718 do {
2719 // What is the next frame to search? (we might be going backwards). Note
2720 // that we specify wrap=true so that search_frame never becomes NULL.
[email protected]7ea066a2009-04-06 20:21:592721 search_frame = options.forward ?
[email protected]b4bb2502009-10-01 22:35:272722 search_frame->traverseNext(true) :
2723 search_frame->traversePrevious(true);
[email protected]dd7daa82009-08-10 05:46:452724 } while (!search_frame->hasVisibleContent() &&
2725 search_frame != focused_frame);
initial.commit09911bf2008-07-26 23:55:292726
[email protected]884db412008-11-24 23:46:502727 // Make sure selection doesn't affect the search operation in new frame.
[email protected]a100d76bb2009-08-14 17:50:222728 search_frame->executeCommand(WebString::fromUTF8("Unselect"));
initial.commit09911bf2008-07-26 23:55:292729
2730 // If we have multiple frames and we have wrapped back around to the
2731 // focused frame, we need to search it once more allowing wrap within
2732 // the frame, otherwise it will report 'no match' if the focused frame has
2733 // reported matches, but no frames after the focused_frame contain a
2734 // match for the search word(s).
2735 if (multi_frame && search_frame == focused_frame) {
[email protected]dd7daa82009-08-10 05:46:452736 result = search_frame->find(
[email protected]7ea066a2009-04-06 20:21:592737 request_id, search_text, options, true, // Force wrapping.
2738 &selection_rect);
initial.commit09911bf2008-07-26 23:55:292739 }
2740 }
2741
[email protected]26aa0482009-09-30 16:55:272742 webview()->setFocusedFrame(search_frame);
initial.commit09911bf2008-07-26 23:55:292743 } while (!result && search_frame != focused_frame);
2744
[email protected]7ea066a2009-04-06 20:21:592745 if (options.findNext) {
[email protected]4f3dc372009-02-24 00:10:292746 // Force the main_frame to report the actual count.
[email protected]dd7daa82009-08-10 05:46:452747 main_frame->increaseMatchCount(0, request_id);
[email protected]4f3dc372009-02-24 00:10:292748 } else {
2749 // If nothing is found, set result to "0 of 0", otherwise, set it to
2750 // "-1 of 1" to indicate that we found at least one item, but we don't know
2751 // yet what is active.
2752 int ordinal = result ? -1 : 0; // -1 here means, we might know more later.
2753 int match_count = result ? 1 : 0; // 1 here means possibly more coming.
initial.commit09911bf2008-07-26 23:55:292754
[email protected]4f3dc372009-02-24 00:10:292755 // If we find no matches then this will be our last status update.
2756 // Otherwise the scoping effort will send more results.
2757 bool final_status_update = !result;
initial.commit09911bf2008-07-26 23:55:292758
[email protected]4f3dc372009-02-24 00:10:292759 // Send the search result over to the browser process.
[email protected]4f999132009-03-31 18:08:402760 Send(new ViewHostMsg_Find_Reply(routing_id_,
[email protected]7ea066a2009-04-06 20:21:592761 request_id,
[email protected]4f3dc372009-02-24 00:10:292762 match_count,
2763 selection_rect,
2764 ordinal,
2765 final_status_update));
initial.commit09911bf2008-07-26 23:55:292766
initial.commit09911bf2008-07-26 23:55:292767 // Scoping effort begins, starting with the mainframe.
2768 search_frame = main_frame;
2769
[email protected]dd7daa82009-08-10 05:46:452770 main_frame->resetMatchCount();
initial.commit09911bf2008-07-26 23:55:292771
2772 do {
2773 // Cancel all old scoping requests before starting a new one.
[email protected]dd7daa82009-08-10 05:46:452774 search_frame->cancelPendingScopingEffort();
initial.commit09911bf2008-07-26 23:55:292775
2776 // We don't start another scoping effort unless at least one match has
2777 // been found.
2778 if (result) {
2779 // Start new scoping request. If the scoping function determines that it
2780 // needs to scope, it will defer until later.
[email protected]dd7daa82009-08-10 05:46:452781 search_frame->scopeStringMatches(request_id,
[email protected]7ea066a2009-04-06 20:21:592782 search_text,
2783 options,
initial.commit09911bf2008-07-26 23:55:292784 true); // reset the tickmarks
2785 }
2786
2787 // Iterate to the next frame. The frame will not necessarily scope, for
2788 // example if it is not visible.
[email protected]b4bb2502009-10-01 22:35:272789 search_frame = search_frame->traverseNext(true);
initial.commit09911bf2008-07-26 23:55:292790 } while (search_frame != main_frame);
2791 }
2792}
2793
[email protected]5c4266922009-07-10 16:41:272794void RenderView::OnDeterminePageText() {
2795 if (!is_loading_) {
2796 if (!webview())
2797 return;
[email protected]26aa0482009-09-30 16:55:272798 WebFrame* main_frame = webview()->mainFrame();
[email protected]5c4266922009-07-10 16:41:272799 std::wstring contents;
2800 CaptureText(main_frame, &contents);
2801 Send(new ViewMsg_DeterminePageText_Reply(routing_id_, contents));
2802 determine_page_text_after_loading_stops_ = false;
2803 return;
2804 }
2805
2806 // We set |determine_page_text_after_loading_stops_| true here so that,
2807 // after page has been loaded completely, the text in the page is captured.
2808 determine_page_text_after_loading_stops_ = true;
2809}
2810
initial.commit09911bf2008-07-26 23:55:292811void RenderView::DnsPrefetch(const std::vector<std::string>& host_names) {
2812 Send(new ViewHostMsg_DnsPrefetch(host_names));
2813}
2814
[email protected]630e26b2008-10-14 22:55:172815void RenderView::OnZoom(int function) {
2816 static const bool kZoomIsTextOnly = false;
2817 switch (function) {
2818 case PageZoom::SMALLER:
[email protected]26aa0482009-09-30 16:55:272819 webview()->zoomOut(kZoomIsTextOnly);
initial.commit09911bf2008-07-26 23:55:292820 break;
[email protected]630e26b2008-10-14 22:55:172821 case PageZoom::STANDARD:
[email protected]26aa0482009-09-30 16:55:272822 webview()->zoomDefault();
initial.commit09911bf2008-07-26 23:55:292823 break;
[email protected]630e26b2008-10-14 22:55:172824 case PageZoom::LARGER:
[email protected]26aa0482009-09-30 16:55:272825 webview()->zoomIn(kZoomIsTextOnly);
initial.commit09911bf2008-07-26 23:55:292826 break;
2827 default:
2828 NOTREACHED();
2829 }
2830}
2831
[email protected]41fc0322009-09-04 22:23:402832void RenderView::OnSetPageEncoding(const std::string& encoding_name) {
[email protected]26aa0482009-09-30 16:55:272833 webview()->setPageEncoding(WebString::fromUTF8(encoding_name));
initial.commit09911bf2008-07-26 23:55:292834}
2835
[email protected]a697f4c2009-09-14 22:30:182836void RenderView::OnResetPageEncodingToDefault() {
[email protected]26aa0482009-09-30 16:55:272837 WebString no_encoding;
2838 webview()->setPageEncoding(no_encoding);
[email protected]a697f4c2009-09-14 22:30:182839}
2840
[email protected]dd7daa82009-08-10 05:46:452841WebFrame* RenderView::GetChildFrame(const std::wstring& xpath) const {
2842 if (xpath.empty())
[email protected]26aa0482009-09-30 16:55:272843 return webview()->mainFrame();
[email protected]dd7daa82009-08-10 05:46:452844
2845 // xpath string can represent a frame deep down the tree (across multiple
2846 // frame DOMs).
2847 // Example, /html/body/table/tbody/tr/td/iframe\n/frameset/frame[0]
2848 // should break into 2 xpaths
2849 // /html/body/table/tbody/tr/td/iframe & /frameset/frame[0]
2850
[email protected]26aa0482009-09-30 16:55:272851 WebFrame* frame = webview()->mainFrame();
[email protected]dd7daa82009-08-10 05:46:452852
2853 std::wstring xpath_remaining = xpath;
2854 while (!xpath_remaining.empty()) {
2855 std::wstring::size_type delim_pos = xpath_remaining.find_first_of(L'\n');
2856 std::wstring xpath_child;
2857 if (delim_pos != std::wstring::npos) {
2858 xpath_child = xpath_remaining.substr(0, delim_pos);
2859 xpath_remaining.erase(0, delim_pos + 1);
2860 } else {
2861 xpath_remaining.swap(xpath_child);
2862 }
2863 frame = frame->findChildByExpression(WideToUTF16Hack(xpath_child));
initial.commit09911bf2008-07-26 23:55:292864 }
2865
[email protected]dd7daa82009-08-10 05:46:452866 return frame;
initial.commit09911bf2008-07-26 23:55:292867}
2868
[email protected]f29acf52008-11-03 20:08:332869void RenderView::EvaluateScript(const std::wstring& frame_xpath,
2870 const std::wstring& script) {
initial.commit09911bf2008-07-26 23:55:292871 WebFrame* web_frame = GetChildFrame(frame_xpath);
2872 if (!web_frame)
2873 return;
2874
[email protected]dd7daa82009-08-10 05:46:452875 web_frame->executeScript(WebScriptSource(WideToUTF16Hack(script)));
initial.commit09911bf2008-07-26 23:55:292876}
2877
[email protected]1810e132009-03-24 23:35:482878void RenderView::InsertCSS(const std::wstring& frame_xpath,
[email protected]ffaef0c2009-09-15 17:08:082879 const std::string& css,
2880 const std::string& id) {
[email protected]1810e132009-03-24 23:35:482881 WebFrame* web_frame = GetChildFrame(frame_xpath);
2882 if (!web_frame)
2883 return;
2884
[email protected]ffaef0c2009-09-15 17:08:082885 web_frame->insertStyleText(WebString::fromUTF8(css), WebString::fromUTF8(id));
[email protected]1810e132009-03-24 23:35:482886}
2887
initial.commit09911bf2008-07-26 23:55:292888void RenderView::OnScriptEvalRequest(const std::wstring& frame_xpath,
2889 const std::wstring& jscript) {
[email protected]f29acf52008-11-03 20:08:332890 EvaluateScript(frame_xpath, jscript);
initial.commit09911bf2008-07-26 23:55:292891}
2892
[email protected]1810e132009-03-24 23:35:482893void RenderView::OnCSSInsertRequest(const std::wstring& frame_xpath,
[email protected]ffaef0c2009-09-15 17:08:082894 const std::string& css,
2895 const std::string& id) {
2896 InsertCSS(frame_xpath, css, id);
[email protected]ae461542009-06-19 19:03:412897
2898 // Notify RenderViewHost that css has been inserted into the frame.
2899 Send(new ViewHostMsg_OnCSSInserted(routing_id_));
[email protected]1810e132009-03-24 23:35:482900}
2901
[email protected]7ea066a2009-04-06 20:21:592902void RenderView::OnAddMessageToConsole(
2903 const string16& frame_xpath,
2904 const string16& message,
2905 const WebConsoleMessage::Level& level) {
2906 WebFrame* web_frame = GetChildFrame(UTF16ToWideHack(frame_xpath));
[email protected]0dea3ea2009-03-31 23:30:592907 if (web_frame)
[email protected]dd7daa82009-08-10 05:46:452908 web_frame->addMessageToConsole(WebConsoleMessage(level, message));
initial.commit09911bf2008-07-26 23:55:292909}
2910
[email protected]81e63782009-02-27 19:35:092911void RenderView::OnAllowBindings(int enabled_bindings_flags) {
2912 enabled_bindings_ |= enabled_bindings_flags;
initial.commit09911bf2008-07-26 23:55:292913}
2914
2915void RenderView::OnSetDOMUIProperty(const std::string& name,
2916 const std::string& value) {
[email protected]81e63782009-02-27 19:35:092917 DCHECK(BindingsPolicy::is_dom_ui_enabled(enabled_bindings_));
initial.commit09911bf2008-07-26 23:55:292918 dom_ui_bindings_.SetProperty(name, value);
2919}
2920
2921void RenderView::OnReservePageIDRange(int size_of_range) {
2922 next_page_id_ += size_of_range + 1;
2923}
2924
[email protected]e80c73b2009-04-07 23:24:582925void RenderView::OnDragSourceEndedOrMoved(const gfx::Point& client_point,
2926 const gfx::Point& screen_point,
[email protected]1d9f4132009-09-08 17:29:252927 bool ended,
2928 WebDragOperation op) {
[email protected]5f9ae6c2009-07-08 02:38:032929 if (ended) {
[email protected]26aa0482009-09-30 16:55:272930 webview()->dragSourceEndedAt(client_point, screen_point, op);
[email protected]5f9ae6c2009-07-08 02:38:032931 } else {
[email protected]26aa0482009-09-30 16:55:272932 webview()->dragSourceMovedTo(client_point, screen_point);
[email protected]5f9ae6c2009-07-08 02:38:032933 }
initial.commit09911bf2008-07-26 23:55:292934}
2935
2936void RenderView::OnDragSourceSystemDragEnded() {
[email protected]26aa0482009-09-30 16:55:272937 webview()->dragSourceSystemDragEnded();
initial.commit09911bf2008-07-26 23:55:292938}
2939
initial.commit09911bf2008-07-26 23:55:292940void RenderView::OnFormFill(const FormData& form) {
2941 webkit_glue::FillForm(this->webview(), form);
2942}
2943
2944void RenderView::OnFillPasswordForm(
[email protected]daa8c58e2009-06-15 17:21:102945 const webkit_glue::PasswordFormDomManager::FillData& form_data) {
initial.commit09911bf2008-07-26 23:55:292946 webkit_glue::FillPasswordForm(this->webview(), form_data);
2947}
2948
2949void RenderView::OnDragTargetDragEnter(const WebDropData& drop_data,
[email protected]e80c73b2009-04-07 23:24:582950 const gfx::Point& client_point,
[email protected]1d9f4132009-09-08 17:29:252951 const gfx::Point& screen_point,
2952 WebDragOperationsMask ops) {
[email protected]26aa0482009-09-30 16:55:272953 WebDragOperation operation = webview()->dragTargetDragEnter(
[email protected]e80c73b2009-04-07 23:24:582954 drop_data.ToDragData(),
2955 drop_data.identity,
2956 client_point,
[email protected]1d9f4132009-09-08 17:29:252957 screen_point,
2958 ops);
initial.commit09911bf2008-07-26 23:55:292959
[email protected]1d9f4132009-09-08 17:29:252960 Send(new ViewHostMsg_UpdateDragCursor(routing_id_, operation));
initial.commit09911bf2008-07-26 23:55:292961}
2962
[email protected]e80c73b2009-04-07 23:24:582963void RenderView::OnDragTargetDragOver(const gfx::Point& client_point,
[email protected]1d9f4132009-09-08 17:29:252964 const gfx::Point& screen_point,
2965 WebDragOperationsMask ops) {
[email protected]26aa0482009-09-30 16:55:272966 WebDragOperation operation = webview()->dragTargetDragOver(
[email protected]1d9f4132009-09-08 17:29:252967 client_point,
2968 screen_point,
2969 ops);
initial.commit09911bf2008-07-26 23:55:292970
[email protected]1d9f4132009-09-08 17:29:252971 Send(new ViewHostMsg_UpdateDragCursor(routing_id_, operation));
initial.commit09911bf2008-07-26 23:55:292972}
2973
2974void RenderView::OnDragTargetDragLeave() {
[email protected]26aa0482009-09-30 16:55:272975 webview()->dragTargetDragLeave();
initial.commit09911bf2008-07-26 23:55:292976}
2977
[email protected]e80c73b2009-04-07 23:24:582978void RenderView::OnDragTargetDrop(const gfx::Point& client_point,
2979 const gfx::Point& screen_point) {
[email protected]26aa0482009-09-30 16:55:272980 webview()->dragTargetDrop(client_point, screen_point);
initial.commit09911bf2008-07-26 23:55:292981}
2982
2983void RenderView::OnUpdateWebPreferences(const WebPreferences& prefs) {
[email protected]2fab253a2009-08-17 23:00:592984 webkit_preferences_ = prefs;
2985 webkit_preferences_.Apply(webview());
initial.commit09911bf2008-07-26 23:55:292986}
2987
2988void RenderView::OnSetAltErrorPageURL(const GURL& url) {
2989 alternate_error_page_url_ = url;
2990}
2991
initial.commit09911bf2008-07-26 23:55:292992void RenderView::OnInstallMissingPlugin() {
2993 // This could happen when the first default plugin is deleted.
[email protected]f103ab72009-09-02 17:10:592994 if (first_default_plugin_)
2995 first_default_plugin_->InstallMissingPlugin();
initial.commit09911bf2008-07-26 23:55:292996}
2997
[email protected]b62d1a8c2009-01-13 23:54:572998void RenderView::OnFileChooserResponse(
[email protected]561abe62009-04-06 18:08:342999 const std::vector<FilePath>& file_names) {
[email protected]8029f5672009-03-20 22:33:363000 // This could happen if we navigated to a different page before the user
3001 // closed the chooser.
[email protected]a1128322009-10-06 18:38:463002 if (!file_chooser_completion_)
[email protected]8029f5672009-03-20 22:33:363003 return;
3004
[email protected]6069da8c2009-10-20 20:33:493005 WebVector<WebString> ws_file_names(file_names.size());
[email protected]a1128322009-10-06 18:38:463006 for (size_t i = 0; i < file_names.size(); ++i) {
3007 ws_file_names[i] = webkit_glue::FilePathToWebString(file_names[i]);
3008 }
3009
3010 file_chooser_completion_->didChooseFile(ws_file_names);
3011 // Reset the chooser pointer
3012 file_chooser_completion_ = NULL;
initial.commit09911bf2008-07-26 23:55:293013}
3014
3015void RenderView::OnEnableViewSourceMode() {
3016 if (!webview())
3017 return;
[email protected]26aa0482009-09-30 16:55:273018 WebFrame* main_frame = webview()->mainFrame();
initial.commit09911bf2008-07-26 23:55:293019 if (!main_frame)
3020 return;
3021
[email protected]dd7daa82009-08-10 05:46:453022 main_frame->enableViewSourceMode(true);
initial.commit09911bf2008-07-26 23:55:293023}
3024
[email protected]ab32b16c2009-10-16 14:57:253025void RenderView::OnEnablePreferredSizeChangedMode() {
3026 send_preferred_size_changes_ = true;
[email protected]0666aef2009-05-13 19:48:083027}
3028
[email protected]80d96fa2009-06-10 22:34:513029void RenderView::OnSetRendererPrefs(const RendererPreferences& renderer_prefs) {
3030 renderer_preferences_ = renderer_prefs;
[email protected]6e282c92009-07-24 01:19:373031 UpdateFontRenderingFromRendererPrefs();
[email protected]033970a2009-10-14 16:45:053032#if defined(OS_LINUX) && !defined(TOOLKIT_VIEWS)
[email protected]1c83eb42009-09-11 21:08:413033 WebColorName name = WebKit::WebColorWebkitFocusRingColor;
3034 WebKit::setNamedColors(&name, &renderer_prefs.focus_ring_color, 1);
[email protected]7a74e102009-09-03 00:16:563035#endif
[email protected]80d96fa2009-06-10 22:34:513036}
3037
[email protected]952cb702009-10-07 05:50:283038void RenderView::OnMediaPlayerActionAt(const gfx::Point& location,
3039 const WebMediaPlayerAction& action) {
3040 if (webview())
3041 webview()->performMediaPlayerAction(action, location);
[email protected]581b87eb2009-07-23 23:06:563042}
3043
[email protected]7b291f92009-08-14 05:43:533044void RenderView::OnNotifyRendererViewType(ViewType::Type type) {
[email protected]078b34612009-09-19 19:31:513045 // When this is first set, the bindings aren't fully loaded. We only need
3046 // to call through this API after the page has already been loaded. It's
3047 // also called in didCreateDocumentElement to bootstrap.
3048 if (view_type_ != ViewType::INVALID) {
3049 if (type == ViewType::EXTENSION_MOLE ||
3050 type == ViewType::EXTENSION_TOOLSTRIP) {
3051 ExtensionProcessBindings::SetViewType(webview(), type);
3052 }
3053 }
[email protected]7b291f92009-08-14 05:43:533054 view_type_ = type;
3055}
3056
3057void RenderView::OnUpdateBrowserWindowId(int window_id) {
3058 browser_window_id_ = window_id;
3059}
3060
initial.commit09911bf2008-07-26 23:55:293061void RenderView::OnUpdateBackForwardListCount(int back_list_count,
3062 int forward_list_count) {
3063 history_back_list_count_ = back_list_count;
3064 history_forward_list_count_ = forward_list_count;
3065}
3066
[email protected]266eb6f2008-09-30 23:56:503067void RenderView::OnGetAccessibilityInfo(
[email protected]6a983b42009-03-20 20:12:253068 const webkit_glue::WebAccessibility::InParams& in_params,
3069 webkit_glue::WebAccessibility::OutParams* out_params) {
[email protected]6c8afae52009-01-22 02:24:573070#if defined(OS_WIN)
[email protected]6a983b42009-03-20 20:12:253071 if (!web_accessibility_manager_.get()) {
3072 web_accessibility_manager_.reset(
3073 webkit_glue::WebAccessibilityManager::Create());
3074 }
[email protected]266eb6f2008-09-30 23:56:503075
[email protected]6a983b42009-03-20 20:12:253076 if (!web_accessibility_manager_->GetAccObjInfo(webview(), in_params,
3077 out_params)) {
[email protected]266eb6f2008-09-30 23:56:503078 return;
3079 }
[email protected]6c8afae52009-01-22 02:24:573080#else // defined(OS_WIN)
3081 // TODO(port): accessibility not yet implemented
3082 NOTIMPLEMENTED();
3083#endif
[email protected]266eb6f2008-09-30 23:56:503084}
3085
[email protected]6a983b42009-03-20 20:12:253086void RenderView::OnClearAccessibilityInfo(int acc_obj_id, bool clear_all) {
[email protected]6c8afae52009-01-22 02:24:573087#if defined(OS_WIN)
[email protected]6a983b42009-03-20 20:12:253088 if (!web_accessibility_manager_.get()) {
[email protected]266eb6f2008-09-30 23:56:503089 // If accessibility is not activated, ignore clearing message.
3090 return;
3091 }
[email protected]e846d0d2009-05-20 00:53:063092
[email protected]6a983b42009-03-20 20:12:253093 if (!web_accessibility_manager_->ClearAccObjMap(acc_obj_id, clear_all))
[email protected]266eb6f2008-09-30 23:56:503094 return;
[email protected]e846d0d2009-05-20 00:53:063095
[email protected]6c8afae52009-01-22 02:24:573096#else // defined(OS_WIN)
3097 // TODO(port): accessibility not yet implemented
3098 NOTIMPLEMENTED();
3099#endif
[email protected]266eb6f2008-09-30 23:56:503100}
3101
initial.commit09911bf2008-07-26 23:55:293102void RenderView::OnGetAllSavableResourceLinksForCurrentPage(
3103 const GURL& page_url) {
3104 // Prepare list to storage all savable resource links.
3105 std::vector<GURL> resources_list;
3106 std::vector<GURL> referrers_list;
3107 std::vector<GURL> frames_list;
3108 webkit_glue::SavableResourcesResult result(&resources_list,
3109 &referrers_list,
3110 &frames_list);
3111
[email protected]dbeb3952009-10-13 18:01:183112 if (!webkit_glue::GetAllSavableResourceLinksForCurrentPage(
3113 webview(),
3114 page_url,
3115 &result,
3116 chrome::kSavableSchemes)) {
initial.commit09911bf2008-07-26 23:55:293117 // If something is wrong when collecting all savable resource links,
3118 // send empty list to embedder(browser) to tell it failed.
3119 referrers_list.clear();
3120 resources_list.clear();
3121 frames_list.clear();
3122 }
3123
3124 // Send result of all savable resource links to embedder.
3125 Send(new ViewHostMsg_SendCurrentPageAllSavableResourceLinks(routing_id_,
3126 resources_list,
3127 referrers_list,
3128 frames_list));
3129}
3130
3131void RenderView::OnGetSerializedHtmlDataForCurrentPageWithLocalLinks(
[email protected]f6b48532009-02-12 01:56:323132 const std::vector<GURL>& links,
[email protected]fde6714d12009-02-18 22:39:313133 const std::vector<FilePath>& local_paths,
3134 const FilePath& local_directory_name) {
[email protected]26aa0482009-09-30 16:55:273135 webkit_glue::DomSerializer dom_serializer(webview()->mainFrame(),
initial.commit09911bf2008-07-26 23:55:293136 true,
3137 this,
3138 links,
3139 local_paths,
3140 local_directory_name);
3141 dom_serializer.SerializeDom();
3142}
3143
3144void RenderView::DidSerializeDataForFrame(const GURL& frame_url,
3145 const std::string& data, PageSavingSerializationStatus status) {
3146 Send(new ViewHostMsg_SendSerializedHtmlData(routing_id_,
3147 frame_url, data, static_cast<int32>(status)));
3148}
3149
[email protected]04b4a6c2008-08-02 00:44:473150void RenderView::OnMsgShouldClose() {
[email protected]26aa0482009-09-30 16:55:273151 bool should_close = webview()->dispatchBeforeUnloadEvent();
[email protected]04b4a6c2008-08-02 00:44:473152 Send(new ViewHostMsg_ShouldClose_ACK(routing_id_, should_close));
initial.commit09911bf2008-07-26 23:55:293153}
3154
[email protected]eb6b87a2009-07-24 15:57:393155void RenderView::OnClosePage(const ViewMsg_ClosePage_Params& params) {
initial.commit09911bf2008-07-26 23:55:293156 // TODO(creis): We'd rather use webview()->Close() here, but that currently
3157 // sets the WebView's delegate_ to NULL, preventing any JavaScript dialogs
3158 // in the onunload handler from appearing. For now, we're bypassing that and
3159 // calling the FrameLoader's CloseURL method directly. This should be
3160 // revisited to avoid having two ways to close a page. Having a single way
3161 // to close that can run onunload is also useful for fixing
3162 // http://b/issue?id=753080.
[email protected]26aa0482009-09-30 16:55:273163 WebFrame* main_frame = webview()->mainFrame();
[email protected]7a9b51f2009-06-29 21:28:293164 if (main_frame) {
[email protected]dd7daa82009-08-10 05:46:453165 const GURL& url = main_frame->url();
[email protected]3d9689372009-09-10 04:29:173166 // TODO(davemoore) this code should be removed once willClose() gets
[email protected]7a9b51f2009-06-29 21:28:293167 // called when a page is destroyed. DumpLoadHistograms() is safe to call
3168 // multiple times for the same frame, but it will simplify things.
[email protected]dd7daa82009-08-10 05:46:453169 if (url.SchemeIs(chrome::kHttpScheme) ||
3170 url.SchemeIs(chrome::kHttpsScheme))
[email protected]7a9b51f2009-06-29 21:28:293171 DumpLoadHistograms();
[email protected]7a9b51f2009-06-29 21:28:293172 }
[email protected]26aa0482009-09-30 16:55:273173 webview()->dispatchUnloadEvent();
initial.commit09911bf2008-07-26 23:55:293174
[email protected]eb6b87a2009-07-24 15:57:393175 // Just echo back the params in the ACK.
3176 Send(new ViewHostMsg_ClosePage_ACK(routing_id_, params));
initial.commit09911bf2008-07-26 23:55:293177}
3178
3179void RenderView::OnThemeChanged() {
[email protected]6c8afae52009-01-22 02:24:573180#if defined(OS_WIN)
initial.commit09911bf2008-07-26 23:55:293181 gfx::NativeTheme::instance()->CloseHandles();
3182 gfx::Rect view_rect(0, 0, size_.width(), size_.height());
[email protected]4873c7d2009-07-16 06:36:283183 didInvalidateRect(view_rect);
[email protected]6c8afae52009-01-22 02:24:573184#else // defined(OS_WIN)
3185 // TODO(port): we don't support theming on non-Windows platforms yet
3186 NOTIMPLEMENTED();
3187#endif
initial.commit09911bf2008-07-26 23:55:293188}
3189
[email protected]28790922009-03-09 19:48:373190void RenderView::OnMessageFromExternalHost(const std::string& message,
3191 const std::string& origin,
3192 const std::string& target) {
[email protected]3ac14a052008-08-15 21:22:153193 if (message.empty())
3194 return;
3195
[email protected]28790922009-03-09 19:48:373196 external_host_bindings_.ForwardMessageFromExternalHost(message, origin,
3197 target);
[email protected]3ac14a052008-08-15 21:22:153198}
3199
[email protected]0aa55312008-10-17 21:53:083200void RenderView::OnDisassociateFromPopupCount() {
3201 if (decrement_shared_popup_at_destruction_)
3202 shared_popup_counter_->data--;
3203 shared_popup_counter_ = new SharedRenderViewCounter(0);
3204 decrement_shared_popup_at_destruction_ = false;
3205}
3206
[email protected]15d79e12009-08-02 19:23:453207bool RenderView::MaybeLoadAlternateErrorPage(WebFrame* frame,
3208 const WebURLError& error,
3209 bool replace) {
3210 // We only show alternate error pages in the main frame. They are
3211 // intended to assist the user when navigating, so there is not much
3212 // value in showing them for failed subframes. Ideally, we would be
3213 // able to use the TYPED transition type for this, but that flag is
3214 // not preserved across page reloads.
[email protected]dd7daa82009-08-10 05:46:453215 if (frame->parent())
[email protected]15d79e12009-08-02 19:23:453216 return false;
3217
3218 // Use the alternate error page service if this is a DNS failure or
[email protected]c53976d52009-08-07 18:58:373219 // connection failure.
[email protected]15d79e12009-08-02 19:23:453220 int ec = error.reason;
3221 if (ec != net::ERR_NAME_NOT_RESOLVED &&
3222 ec != net::ERR_CONNECTION_FAILED &&
3223 ec != net::ERR_CONNECTION_REFUSED &&
3224 ec != net::ERR_ADDRESS_UNREACHABLE &&
[email protected]c53976d52009-08-07 18:58:373225 ec != net::ERR_CONNECTION_TIMED_OUT)
[email protected]15d79e12009-08-02 19:23:453226 return false;
3227
3228 const GURL& error_page_url = GetAlternateErrorPageURL(error.unreachableURL,
[email protected]7ccddb8c2009-08-04 17:36:553229 ec == net::ERR_NAME_NOT_RESOLVED ? DNS_ERROR : CONNECTION_ERROR);
[email protected]15d79e12009-08-02 19:23:453230 if (!error_page_url.is_valid())
3231 return false;
3232
3233 // Load an empty page first so there is an immediate response to the error,
3234 // and then kick off a request for the alternate error page.
[email protected]dd7daa82009-08-10 05:46:453235 frame->loadHTMLString(std::string(),
[email protected]15d79e12009-08-02 19:23:453236 GURL(kUnreachableWebDataURL),
3237 error.unreachableURL,
3238 replace);
3239
3240 // Now, create a fetcher for the error page and associate it with the data
3241 // source we just created via the LoadHTMLString call. That way if another
3242 // navigation occurs, the fetcher will get destroyed.
3243 NavigationState* navigation_state =
[email protected]dd7daa82009-08-10 05:46:453244 NavigationState::FromDataSource(frame->provisionalDataSource());
[email protected]15d79e12009-08-02 19:23:453245 navigation_state->set_alt_error_page_fetcher(
3246 new AltErrorPageResourceFetcher(
3247 error_page_url, frame, error,
3248 NewCallback(this, &RenderView::AltErrorPageFinished)));
3249 return true;
3250}
3251
initial.commit09911bf2008-07-26 23:55:293252std::string RenderView::GetAltHTMLForTemplate(
3253 const DictionaryValue& error_strings, int template_resource_id) const {
[email protected]8a16266e2009-09-10 21:08:393254 const base::StringPiece template_html(
initial.commit09911bf2008-07-26 23:55:293255 ResourceBundle::GetSharedInstance().GetRawDataResource(
3256 template_resource_id));
3257
3258 if (template_html.empty()) {
3259 NOTREACHED() << "unable to load template. ID: " << template_resource_id;
3260 return "";
3261 }
[email protected]7cd22a52009-07-14 00:40:253262
initial.commit09911bf2008-07-26 23:55:293263 // "t" is the id of the templates root node.
[email protected]7cd22a52009-07-14 00:40:253264 return jstemplate_builder::GetTemplatesHtml(
initial.commit09911bf2008-07-26 23:55:293265 template_html, &error_strings, "t");
3266}
[email protected]0e79b9e2009-02-13 04:20:483267
[email protected]15d79e12009-08-02 19:23:453268void RenderView::AltErrorPageFinished(WebFrame* frame,
3269 const WebURLError& original_error,
3270 const std::string& html) {
3271 // Here, we replace the blank page we loaded previously.
[email protected]7ccddb8c2009-08-04 17:36:553272
3273 // If we failed to download the alternate error page, fall back to the
3274 // original error page if present. Otherwise, LoadNavigationErrorPage
3275 // will simply display a default error page.
3276 const std::string* html_to_load = &html;
3277 if (html.empty()) {
3278 NavigationState* navigation_state =
[email protected]dd7daa82009-08-10 05:46:453279 NavigationState::FromDataSource(frame->dataSource());
[email protected]7ccddb8c2009-08-04 17:36:553280 html_to_load = &navigation_state->postponed_data();
3281 }
3282 LoadNavigationErrorPage(
3283 frame, WebURLRequest(), original_error, *html_to_load, true);
[email protected]15d79e12009-08-02 19:23:453284}
3285
[email protected]30f75e62009-02-25 22:01:003286void RenderView::OnMoveOrResizeStarted() {
3287 if (webview())
[email protected]acca2a1f2009-10-16 03:53:393288 webview()->hideAutofillPopup();
[email protected]30f75e62009-02-25 22:01:003289}
3290
[email protected]30f75e62009-02-25 22:01:003291void RenderView::OnResize(const gfx::Size& new_size,
3292 const gfx::Rect& resizer_rect) {
3293 if (webview())
[email protected]acca2a1f2009-10-16 03:53:393294 webview()->hideAutofillPopup();
[email protected]30f75e62009-02-25 22:01:003295 RenderWidget::OnResize(new_size, resizer_rect);
3296}
[email protected]0aa477bd2009-03-23 22:21:433297
[email protected]05d478752009-04-08 23:38:163298void RenderView::OnClearFocusedNode() {
3299 if (webview())
[email protected]26aa0482009-09-30 16:55:273300 webview()->clearFocusedNode();
[email protected]05d478752009-04-08 23:38:163301}
3302
[email protected]699ab0d2009-04-23 23:19:143303void RenderView::OnSetBackground(const SkBitmap& background) {
3304 if (webview())
[email protected]b4bb2502009-10-01 22:35:273305 webview()->setIsTransparent(!background.empty());
[email protected]699ab0d2009-04-23 23:19:143306
3307 SetBackground(background);
3308}
3309
[email protected]8c66c5a2009-07-22 17:26:343310void RenderView::OnSetActive(bool active) {
3311 if (webview())
[email protected]b4bb2502009-10-01 22:35:273312 webview()->setIsActive(active);
[email protected]8c66c5a2009-07-22 17:26:343313}
3314
[email protected]309d7a282009-03-24 09:18:273315void RenderView::SendExtensionRequest(const std::string& name,
[email protected]e4dad9fb2009-10-06 18:15:583316 const ListValue& args,
[email protected]c6619182009-05-12 14:59:323317 int request_id,
[email protected]2f25d7b92009-06-10 00:06:473318 bool has_callback) {
[email protected]c6619182009-05-12 14:59:323319 Send(new ViewHostMsg_ExtensionRequest(routing_id_, name, args, request_id,
[email protected]2f25d7b92009-06-10 00:06:473320 has_callback));
[email protected]309d7a282009-03-24 09:18:273321}
3322
[email protected]c6619182009-05-12 14:59:323323void RenderView::OnExtensionResponse(int request_id,
3324 bool success,
3325 const std::string& response,
3326 const std::string& error) {
[email protected]0f6053962009-07-09 19:26:353327 ExtensionProcessBindings::HandleResponse(
3328 request_id, success, response, error);
[email protected]309d7a282009-03-24 09:18:273329}
[email protected]c20210e62009-04-03 21:39:263330
[email protected]078b34612009-09-19 19:31:513331void RenderView::InjectToolstripCSS() {
3332 if (view_type_ != ViewType::EXTENSION_TOOLSTRIP)
3333 return;
3334
3335 static const base::StringPiece toolstrip_css(
3336 ResourceBundle::GetSharedInstance().GetRawDataResource(
3337 IDR_EXTENSION_TOOLSTRIP_CSS));
3338 std::string css = toolstrip_css.as_string();
3339 InsertCSS(L"", css, "ToolstripDefaultCSS");
3340}
3341
[email protected]7120f132009-07-20 21:05:373342void RenderView::OnExtensionMessageInvoke(const std::string& function_name,
3343 const ListValue& args) {
3344 RendererExtensionBindings::Invoke(function_name, args, this);
3345}
3346
[email protected]e7e4f3c2009-04-21 15:24:083347// Dump all load time histograms.
[email protected]c20210e62009-04-03 21:39:263348//
[email protected]7a9b51f2009-06-29 21:28:293349// There are 13 histograms measuring various times.
[email protected]c20210e62009-04-03 21:39:263350// The time points we keep are
3351// request: time document was requested by user
3352// start: time load of document started
[email protected]a2f6bc112009-06-27 16:27:253353// commit: time load of document started
[email protected]7a9b51f2009-06-29 21:28:293354// finish_document: main document loaded, before onload()
[email protected]c20210e62009-04-03 21:39:263355// finish: after onload() and all resources are loaded
[email protected]7a9b51f2009-06-29 21:28:293356// first_paint: first paint performed
3357// first_paint_after_load: first paint performed after load is finished
3358// begin: request if it was user requested, start otherwise
3359//
[email protected]c20210e62009-04-03 21:39:263360// The times that we histogram are
[email protected]a2f6bc112009-06-27 16:27:253361// request->start,
[email protected]7a9b51f2009-06-29 21:28:293362// start->commit,
3363// commit->finish_document,
3364// finish_document->finish,
3365// begin->commit,
3366// begin->finishDoc,
3367// begin->finish,
3368// begin->first_paint,
3369// begin->first_paint_after_load
3370// commit->finishDoc,
3371// commit->first_paint,
3372// commit->first_paint_after_load,
3373// finish->first_paint_after_load,
[email protected]c20210e62009-04-03 21:39:263374//
[email protected]e7e4f3c2009-04-21 15:24:083375// It's possible for the request time not to be set, if a client
3376// redirect had been done (the user never requested the page)
3377// Also, it's possible to load a page without ever laying it out
[email protected]7a9b51f2009-06-29 21:28:293378// so first_paint and first_paint_after_load can be 0.
[email protected]c20210e62009-04-03 21:39:263379void RenderView::DumpLoadHistograms() const {
[email protected]26aa0482009-09-30 16:55:273380 WebFrame* main_frame = webview()->mainFrame();
[email protected]ed3fb032009-06-16 19:50:563381 NavigationState* navigation_state =
[email protected]dd7daa82009-08-10 05:46:453382 NavigationState::FromDataSource(main_frame->dataSource());
[email protected]7a9b51f2009-06-29 21:28:293383 Time finish = navigation_state->finish_load_time();
[email protected]ed3fb032009-06-16 19:50:563384
[email protected]7a9b51f2009-06-29 21:28:293385 // If we've already dumped or we haven't finished loading, do nothing.
3386 if (navigation_state->load_histograms_recorded() || finish.is_null())
3387 return;
[email protected]ed3fb032009-06-16 19:50:563388
[email protected]7a9b51f2009-06-29 21:28:293389 Time request = navigation_state->request_time();
3390 Time start = navigation_state->start_load_time();
3391 Time commit = navigation_state->commit_load_time();
3392 Time finish_doc = navigation_state->finish_document_load_time();
3393 Time first_paint = navigation_state->first_paint_time();
3394 Time first_paint_after_load =
3395 navigation_state->first_paint_after_load_time();
[email protected]c20210e62009-04-03 21:39:263396
[email protected]7a9b51f2009-06-29 21:28:293397 Time begin;
3398 // Client side redirects will have no request time.
3399 if (request.is_null()) {
3400 begin = start;
3401 } else {
3402 begin = request;
3403 UMA_HISTOGRAM_MEDIUM_TIMES("Renderer4.RequestToStart", start - request);
[email protected]e7e4f3c2009-04-21 15:24:083404 }
[email protected]7a9b51f2009-06-29 21:28:293405 UMA_HISTOGRAM_MEDIUM_TIMES("Renderer4.StartToCommit", commit - start);
3406 UMA_HISTOGRAM_MEDIUM_TIMES(
3407 "Renderer4.CommitToFinishDoc", finish_doc - commit);
3408 UMA_HISTOGRAM_MEDIUM_TIMES(
3409 "Renderer4.FinishDocToFinish", finish - finish_doc);
3410
3411 UMA_HISTOGRAM_MEDIUM_TIMES("Renderer4.BeginToCommit", commit - begin);
3412 UMA_HISTOGRAM_MEDIUM_TIMES("Renderer4.BeginToFinishDoc", finish_doc - begin);
[email protected]e695fbd62009-06-30 16:31:543413
3414 static const TimeDelta kBeginToFinishMin(TimeDelta::FromMilliseconds(10));
3415 static const TimeDelta kBeginToFinishMax(TimeDelta::FromMinutes(10));
3416 static const size_t kBeginToFinishBucketCount(100);
3417
3418 UMA_HISTOGRAM_CUSTOM_TIMES("Renderer4.BeginToFinish",
3419 finish - begin, kBeginToFinishMin,
3420 kBeginToFinishMax, kBeginToFinishBucketCount);
[email protected]0a32257a2009-07-09 18:10:413421 UMA_HISTOGRAM_CUSTOM_TIMES("Renderer4.StartToFinish",
3422 finish - start, kBeginToFinishMin,
3423 kBeginToFinishMax, kBeginToFinishBucketCount);
3424 if (!request.is_null())
3425 UMA_HISTOGRAM_CUSTOM_TIMES("Renderer4.RequestToFinish",
3426 finish - request, kBeginToFinishMin,
3427 kBeginToFinishMax, kBeginToFinishBucketCount);
[email protected]e695fbd62009-06-30 16:31:543428
[email protected]36285b52009-06-30 19:10:003429 static bool use_dns_histogram(FieldTrialList::Find("DnsImpact") &&
3430 !FieldTrialList::Find("DnsImpact")->group_name().empty());
[email protected]0a32257a2009-07-09 18:10:413431 if (use_dns_histogram) {
[email protected]36285b52009-06-30 19:10:003432 UMA_HISTOGRAM_CUSTOM_TIMES(
3433 FieldTrial::MakeName("Renderer4.BeginToFinish", "DnsImpact").data(),
3434 finish - begin, kBeginToFinishMin,
3435 kBeginToFinishMax, kBeginToFinishBucketCount);
[email protected]0a32257a2009-07-09 18:10:413436 UMA_HISTOGRAM_CUSTOM_TIMES(
3437 FieldTrial::MakeName("Renderer4.StartToFinish", "DnsImpact").data(),
3438 finish - start, kBeginToFinishMin,
3439 kBeginToFinishMax, kBeginToFinishBucketCount);
3440 if (!request.is_null())
3441 UMA_HISTOGRAM_CUSTOM_TIMES(
3442 FieldTrial::MakeName("Renderer4.RequestToFinish", "DnsImpact").data(),
3443 finish - request, kBeginToFinishMin,
3444 kBeginToFinishMax, kBeginToFinishBucketCount);
3445 }
[email protected]e695fbd62009-06-30 16:31:543446
[email protected]36285b52009-06-30 19:10:003447 static bool use_sdch_histogram(FieldTrialList::Find("GlobalSdch") &&
3448 !FieldTrialList::Find("GlobalSdch")->group_name().empty());
[email protected]0a32257a2009-07-09 18:10:413449 if (use_sdch_histogram) {
[email protected]36285b52009-06-30 19:10:003450 UMA_HISTOGRAM_CUSTOM_TIMES(
3451 FieldTrial::MakeName("Renderer4.BeginToFinish", "GlobalSdch").data(),
3452 finish - begin, kBeginToFinishMin,
3453 kBeginToFinishMax, kBeginToFinishBucketCount);
[email protected]0a32257a2009-07-09 18:10:413454 UMA_HISTOGRAM_CUSTOM_TIMES(
3455 FieldTrial::MakeName("Renderer4.StartToFinish", "GlobalSdch").data(),
3456 finish - start, kBeginToFinishMin,
3457 kBeginToFinishMax, kBeginToFinishBucketCount);
3458 if (!request.is_null())
3459 UMA_HISTOGRAM_CUSTOM_TIMES(
3460 FieldTrial::MakeName("Renderer4.RequestToFinish",
3461 "GlobalSdch").data(),
3462 finish - request, kBeginToFinishMin,
3463 kBeginToFinishMax, kBeginToFinishBucketCount);
3464 }
[email protected]7a9b51f2009-06-29 21:28:293465
[email protected]5fff93f2009-08-02 04:27:343466 static bool use_socket_late_binding_histogram =
3467 FieldTrialList::Find("SocketLateBinding") &&
3468 !FieldTrialList::Find("SocketLateBinding")->group_name().empty();
3469 if (use_socket_late_binding_histogram) {
3470 UMA_HISTOGRAM_CUSTOM_TIMES(
3471 FieldTrial::MakeName("Renderer4.BeginToFinish",
3472 "SocketLateBinding").data(),
3473 finish - begin, kBeginToFinishMin,
3474 kBeginToFinishMax, kBeginToFinishBucketCount);
3475 UMA_HISTOGRAM_CUSTOM_TIMES(
3476 FieldTrial::MakeName("Renderer4.StartToFinish",
3477 "SocketLateBinding").data(),
3478 finish - start, kBeginToFinishMin,
3479 kBeginToFinishMax, kBeginToFinishBucketCount);
3480 if (!request.is_null())
3481 UMA_HISTOGRAM_CUSTOM_TIMES(
3482 FieldTrial::MakeName("Renderer4.RequestToFinish",
3483 "SocketLateBinding").data(),
3484 finish - request, kBeginToFinishMin,
3485 kBeginToFinishMax, kBeginToFinishBucketCount);
3486 }
3487
[email protected]7e05f6c42009-07-11 01:50:483488 static bool use_cache_histogram1(FieldTrialList::Find("CacheSize") &&
3489 !FieldTrialList::Find("CacheSize")->group_name().empty());
3490 if (use_cache_histogram1)
3491 UMA_HISTOGRAM_CUSTOM_TIMES(
3492 FieldTrial::MakeName("Renderer4.StartToFinish", "CacheSize").data(),
3493 finish - start, kBeginToFinishMin,
3494 kBeginToFinishMax, kBeginToFinishBucketCount);
3495
3496 static bool use_cache_histogram2(FieldTrialList::Find("NewEviction") &&
3497 !FieldTrialList::Find("NewEviction")->group_name().empty());
3498 if (use_cache_histogram2)
3499 UMA_HISTOGRAM_CUSTOM_TIMES(
3500 FieldTrial::MakeName("Renderer4.StartToFinish", "NewEviction").data(),
3501 finish - start, kBeginToFinishMin,
3502 kBeginToFinishMax, kBeginToFinishBucketCount);
3503
[email protected]ab0729e2009-09-30 04:42:463504 static bool use_async_tcp(FieldTrialList::Find("AsyncSlowStart") &&
3505 !FieldTrialList::Find("AsyncSlowStart")->group_name().empty());
3506 if (use_async_tcp) {
3507 UMA_HISTOGRAM_CUSTOM_TIMES(
3508 FieldTrial::MakeName("Renderer4.StartToFinish",
3509 "AsyncSlowStart").data(),
3510 finish - start, kBeginToFinishMin,
3511 kBeginToFinishMax, kBeginToFinishBucketCount);
3512 }
3513
[email protected]7a9b51f2009-06-29 21:28:293514 UMA_HISTOGRAM_MEDIUM_TIMES("Renderer4.CommitToFinish", finish - commit);
3515
3516 if (!first_paint.is_null()) {
3517 UMA_HISTOGRAM_MEDIUM_TIMES(
3518 "Renderer4.BeginToFirstPaint", first_paint - begin);
3519 UMA_HISTOGRAM_MEDIUM_TIMES(
3520 "Renderer4.CommitToFirstPaint", first_paint - commit);
[email protected]c20210e62009-04-03 21:39:263521 }
[email protected]7a9b51f2009-06-29 21:28:293522
3523 if (!first_paint_after_load.is_null()) {
3524 UMA_HISTOGRAM_MEDIUM_TIMES(
3525 "Renderer4.BeginToFirstPaintAfterLoad", first_paint_after_load - begin);
3526 UMA_HISTOGRAM_MEDIUM_TIMES(
3527 "Renderer4.CommitToFirstPaintAfterLoad",
3528 first_paint_after_load - commit);
3529 UMA_HISTOGRAM_MEDIUM_TIMES(
3530 "Renderer4.FinishToFirstPaintAfterLoad",
3531 first_paint_after_load - finish);
3532 }
3533
3534 navigation_state->set_load_histograms_recorded(true);
[email protected]c20210e62009-04-03 21:39:263535}
[email protected]e846d0d2009-05-20 00:53:063536
[email protected]cc0445f2009-10-13 16:09:083537void RenderView::focusAccessibilityObject(
3538 const WebAccessibilityObject& acc_obj) {
[email protected]e846d0d2009-05-20 00:53:063539#if defined(OS_WIN)
3540 if (!web_accessibility_manager_.get()) {
3541 web_accessibility_manager_.reset(
3542 webkit_glue::WebAccessibilityManager::Create());
3543 }
3544
3545 // Retrieve the accessibility object id of the AccessibilityObject.
3546 int acc_obj_id = web_accessibility_manager_->FocusAccObj(acc_obj);
3547
3548 // If id is valid, alert the browser side that an accessibility focus change
3549 // occurred.
3550 if (acc_obj_id >= 0)
3551 Send(new ViewHostMsg_AccessibilityFocusChange(routing_id_, acc_obj_id));
3552
3553#else // defined(OS_WIN)
3554 // TODO(port): accessibility not yet implemented
3555 NOTIMPLEMENTED();
3556#endif
3557}
[email protected]daa8c58e2009-06-15 17:21:103558
3559void RenderView::SendPasswordForms(WebFrame* frame) {
[email protected]dd7daa82009-08-10 05:46:453560 WebVector<WebForm> forms;
3561 frame->forms(forms);
[email protected]daa8c58e2009-06-15 17:21:103562
3563 std::vector<PasswordForm> password_forms;
3564 for (size_t i = 0; i < forms.size(); ++i) {
3565 const WebForm& form = forms[i];
3566
3567 // Respect autocomplete=off.
3568 if (form.isAutoCompleteEnabled()) {
3569 scoped_ptr<PasswordForm> password_form(
3570 PasswordFormDomManager::CreatePasswordForm(form));
3571 if (password_form.get())
3572 password_forms.push_back(*password_form);
3573 }
3574 }
3575
3576 if (!password_forms.empty())
3577 Send(new ViewHostMsg_PasswordFormsSeen(routing_id_, password_forms));
3578}
[email protected]0fda7272009-06-26 15:49:333579
3580void RenderView::Print(WebFrame* frame, bool script_initiated) {
3581 DCHECK(frame);
3582 if (print_helper_.get() == NULL) {
3583 print_helper_.reset(new PrintWebViewHelper(this));
3584 }
3585 print_helper_->Print(frame, script_initiated);
3586}
[email protected]446705872009-09-10 07:22:483587
3588void RenderView::OnSetEditCommandsForNextKeyEvent(
3589 const EditCommands& edit_commands) {
3590 edit_commands_ = edit_commands;
3591}
3592
[email protected]912256b32009-09-18 09:47:353593void RenderView::OnExecuteCode(int request_id, const std::string& extension_id,
3594 bool is_js_code,
3595 const std::string& code_string) {
3596 if (is_loading_) {
3597 scoped_refptr<CodeExecutionInfo> info = new CodeExecutionInfo(
3598 request_id, extension_id, is_js_code, code_string);
3599 pending_code_execution_queue_.push(info);
3600 return;
3601 }
[email protected]26aa0482009-09-30 16:55:273602 WebFrame* main_frame = webview() ? webview()->mainFrame() : NULL;
[email protected]912256b32009-09-18 09:47:353603 if (!main_frame) {
3604 Send(new ViewMsg_ExecuteCodeFinished(routing_id_, request_id, false));
3605 return;
3606 }
3607
3608 if (is_js_code) {
3609 std::vector<WebScriptSource> sources;
3610 sources.push_back(
3611 WebScriptSource(WebString::fromUTF8(code_string)));
3612 UserScriptSlave::InsertInitExtensionCode(&sources, extension_id);
[email protected]146486ff2009-10-08 01:52:563613 main_frame->executeScriptInIsolatedWorld(
3614 UserScriptSlave::GetIsolatedWorldId(extension_id),
3615 &sources.front(), sources.size(), EXTENSION_GROUP_CONTENT_SCRIPTS);
[email protected]912256b32009-09-18 09:47:353616 } else {
3617 main_frame->insertStyleText(WebString::fromUTF8(code_string), WebString());
3618 }
3619
3620 Send(new ViewMsg_ExecuteCodeFinished(routing_id_, request_id, true));
3621}
3622
[email protected]60c42a8c72009-10-09 04:08:593623void RenderView::Close() {
3624 // We need to grab a pointer to the doomed WebView before we destroy it.
3625 WebView* doomed = webview();
3626 RenderWidget::Close();
3627 Singleton<ViewMap>::get()->erase(doomed);
3628}
3629
[email protected]446705872009-09-10 07:22:483630void RenderView::DidHandleKeyEvent() {
3631 edit_commands_.clear();
3632}
3633
[email protected]83dde542009-09-11 20:59:553634void RenderView::EnsureDocumentTag() {
3635 // TODO(darin): There's actually no reason for this to be here. We should
3636 // have the browser side manage the document tag.
3637#if defined(OS_MACOSX)
3638 if (!has_document_tag_) {
3639 // Make the call to get the tag.
3640 Send(new ViewHostMsg_GetDocumentTag(routing_id_, &document_tag_));
3641 has_document_tag_ = true;
3642 }
3643#endif
3644}
[email protected]12636df2009-09-28 22:32:213645
3646bool RenderView::SendAndRunNestedMessageLoop(IPC::SyncMessage* message) {
[email protected]8beff0762009-09-29 02:18:303647 PluginChannelHost::Broadcast(
3648 new PluginMsg_SignalModalDialogEvent(host_window_));
[email protected]12636df2009-09-28 22:32:213649
3650 message->EnableMessagePumping(); // Runs a nested message loop.
3651 bool rv = Send(message);
3652
[email protected]8beff0762009-09-29 02:18:303653 PluginChannelHost::Broadcast(
3654 new PluginMsg_ResetModalDialogEvent(host_window_));
[email protected]12636df2009-09-28 22:32:213655
3656 return rv;
3657}