blob: bfc427dedb2f1fa51daf542f152f57b0a0c6b931 [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
[email protected]a79a3f8d2009-11-02 21:07:355#if defined(ENABLE_PEPPER)
6#define PEPPER_APIS_ENABLED
7#endif
8
initial.commit09911bf2008-07-26 23:55:299#include "chrome/renderer/render_view.h"
10
11#include <algorithm>
12#include <string>
13#include <vector>
14
[email protected]91e81ae2009-05-08 22:14:3815#include "app/gfx/color_utils.h"
[email protected]37126212009-05-06 02:23:3116#include "app/gfx/favicon_size.h"
[email protected]010ea08a2009-10-11 20:21:3217#include "app/gfx/native_widget_types.h"
[email protected]a92b8642009-05-05 23:38:5618#include "app/l10n_util.h"
[email protected]37126212009-05-06 02:23:3119#include "app/message_box_flags.h"
[email protected]9929da92009-05-05 02:05:1120#include "app/resource_bundle.h"
initial.commit09911bf2008-07-26 23:55:2921#include "base/command_line.h"
[email protected]bb063b72009-03-27 23:18:5022#include "base/compiler_specific.h"
[email protected]4646f292009-05-20 03:49:0523#include "base/field_trial.h"
[email protected]8380c092009-06-25 17:45:5124#include "base/process_util.h"
[email protected]7b291f92009-08-14 05:43:5325#include "base/singleton.h"
initial.commit09911bf2008-07-26 23:55:2926#include "base/string_piece.h"
27#include "base/string_util.h"
[email protected]6c8afae52009-01-22 02:24:5728#include "build/build_config.h"
[email protected]81e63782009-02-27 19:35:0929#include "chrome/common/bindings_policy.h"
[email protected]ef916272009-07-08 21:40:5530#include "chrome/common/child_process_logging.h"
initial.commit09911bf2008-07-26 23:55:2931#include "chrome/common/chrome_switches.h"
[email protected]f0af6a72009-05-30 05:25:1732#include "chrome/common/chrome_constants.h"
initial.commit09911bf2008-07-26 23:55:2933#include "chrome/common/jstemplate_builder.h"
[email protected]630e26b2008-10-14 22:55:1734#include "chrome/common/page_zoom.h"
[email protected]8beff0762009-09-29 02:18:3035#include "chrome/common/plugin_messages.h"
[email protected]e09ba552009-02-05 03:26:2936#include "chrome/common/render_messages.h"
[email protected]9b6f40e2009-06-11 15:54:2637#include "chrome/common/renderer_preferences.h"
initial.commit09911bf2008-07-26 23:55:2938#include "chrome/common/thumbnail_score.h"
[email protected]6de74452009-02-25 18:04:5939#include "chrome/common/url_constants.h"
initial.commit09911bf2008-07-26 23:55:2940#include "chrome/renderer/about_handler.h"
[email protected]5fb88962009-04-16 19:03:2541#include "chrome/renderer/audio_message_filter.h"
[email protected]e4ac5df2009-03-17 15:33:1142#include "chrome/renderer/devtools_agent.h"
43#include "chrome/renderer/devtools_client.h"
[email protected]912256b32009-09-18 09:47:3544#include "chrome/renderer/extension_groups.h"
[email protected]f816c012009-06-26 21:48:3245#include "chrome/renderer/extensions/event_bindings.h"
[email protected]0f6053962009-07-09 19:26:3546#include "chrome/renderer/extensions/extension_process_bindings.h"
[email protected]7120f132009-07-20 21:05:3747#include "chrome/renderer/extensions/renderer_extension_bindings.h"
initial.commit09911bf2008-07-26 23:55:2948#include "chrome/renderer/localized_error.h"
[email protected]6f56d482009-02-20 05:02:5649#include "chrome/renderer/media/audio_renderer_impl.h"
[email protected]ed3fb032009-06-16 19:50:5650#include "chrome/renderer/navigation_state.h"
[email protected]90e908552009-10-05 01:40:1251#include "chrome/renderer/notification_provider.h"
[email protected]8beff0762009-09-29 02:18:3052#include "chrome/renderer/plugin_channel_host.h"
[email protected]d81c1e52009-06-03 22:09:5053#include "chrome/renderer/print_web_view_helper.h"
[email protected]39008c02009-02-11 23:59:2554#include "chrome/renderer/render_process.h"
[email protected]85c55dc2009-11-06 03:05:4655#if defined(SPELLCHECKER_IN_RENDERER)
56#include "chrome/renderer/spellchecker/spellcheck.h"
57#endif
[email protected]0938d3c2009-01-09 20:37:3558#include "chrome/renderer/user_script_slave.h"
initial.commit09911bf2008-07-26 23:55:2959#include "chrome/renderer/visitedlink_slave.h"
[email protected]d439ba072009-10-17 22:32:2960#include "chrome/renderer/webplugin_delegate_pepper.h"
[email protected]ba4b17f2009-02-11 21:32:2961#include "chrome/renderer/webplugin_delegate_proxy.h"
[email protected]9c00f002009-11-05 22:37:4262#include "chrome/renderer/websharedworker_proxy.h"
[email protected]eb47a132009-03-04 00:39:5663#include "chrome/renderer/webworker_proxy.h"
[email protected]34ac8f32009-02-22 23:03:2764#include "grit/generated_resources.h"
65#include "grit/renderer_resources.h"
[email protected]f11ca0732009-04-11 00:09:3466#include "net/base/data_url.h"
initial.commit09911bf2008-07-26 23:55:2967#include "net/base/escape.h"
68#include "net/base/net_errors.h"
[email protected]c399a8a2008-11-22 19:38:0069#include "skia/ext/bitmap_platform_device.h"
[email protected]83c9e6552008-12-03 16:22:1070#include "skia/ext/image_operations.h"
[email protected]418ed5ab2009-11-12 01:14:4971#include "third_party/WebKit/WebKit/chromium/public/WebAccessibilityCache.h"
72#include "third_party/WebKit/WebKit/chromium/public/WebAccessibilityObject.h"
73#include "third_party/WebKit/WebKit/chromium/public/WebDataSource.h"
74#include "third_party/WebKit/WebKit/chromium/public/WebDevToolsAgent.h"
75#include "third_party/WebKit/WebKit/chromium/public/WebDragData.h"
76#include "third_party/WebKit/WebKit/chromium/public/WebFormElement.h"
77#include "third_party/WebKit/WebKit/chromium/public/WebFrame.h"
78#include "third_party/WebKit/WebKit/chromium/public/WebHistoryItem.h"
79#include "third_party/WebKit/WebKit/chromium/public/WebNode.h"
80#include "third_party/WebKit/WebKit/chromium/public/WebPoint.h"
81#include "third_party/WebKit/WebKit/chromium/public/WebRange.h"
82#include "third_party/WebKit/WebKit/chromium/public/WebRect.h"
83#include "third_party/WebKit/WebKit/chromium/public/WebScriptSource.h"
84#include "third_party/WebKit/WebKit/chromium/public/WebSearchableFormData.h"
85#include "third_party/WebKit/WebKit/chromium/public/WebSecurityOrigin.h"
86#include "third_party/WebKit/WebKit/chromium/public/WebSize.h"
87#include "third_party/WebKit/WebKit/chromium/public/WebString.h"
88#include "third_party/WebKit/WebKit/chromium/public/WebURL.h"
89#include "third_party/WebKit/WebKit/chromium/public/WebURLError.h"
90#include "third_party/WebKit/WebKit/chromium/public/WebURLRequest.h"
91#include "third_party/WebKit/WebKit/chromium/public/WebURLResponse.h"
92#include "third_party/WebKit/WebKit/chromium/public/WebVector.h"
[email protected]f430b5712009-08-21 21:46:3193#include "webkit/appcache/appcache_interfaces.h"
[email protected]ba4b17f2009-02-11 21:32:2994#include "webkit/default_plugin/default_plugin_shared.h"
[email protected]ca948a22009-06-25 19:36:1795#include "webkit/glue/glue_serialize.h"
[email protected]79e37442009-10-09 18:17:4496#include "webkit/glue/glue_util.h"
initial.commit09911bf2008-07-26 23:55:2997#include "webkit/glue/dom_operations.h"
98#include "webkit/glue/dom_serializer.h"
[email protected]f11ca0732009-04-11 00:09:3499#include "webkit/glue/image_decoder.h"
[email protected]8e296bbd2009-07-22 21:37:17100#include "webkit/glue/media/buffered_data_source.h"
[email protected]8380c092009-06-25 17:45:51101#include "webkit/glue/media/simple_data_source.h"
initial.commit09911bf2008-07-26 23:55:29102#include "webkit/glue/password_form.h"
[email protected]ba4b17f2009-02-11 21:32:29103#include "webkit/glue/plugins/plugin_list.h"
[email protected]8a3b7962009-09-04 05:53:23104#include "webkit/glue/plugins/webplugin_delegate_impl.h"
initial.commit09911bf2008-07-26 23:55:29105#include "webkit/glue/webdropdata.h"
initial.commit09911bf2008-07-26 23:55:29106#include "webkit/glue/webkit_glue.h"
[email protected]add51772009-06-11 18:25:17107#include "webkit/glue/webmediaplayer_impl.h"
[email protected]f103ab72009-09-02 17:10:59108#include "webkit/glue/webplugin_impl.h"
initial.commit09911bf2008-07-26 23:55:29109
[email protected]6c8afae52009-01-22 02:24:57110#if defined(OS_WIN)
111// TODO(port): these files are currently Windows only because they concern:
[email protected]6c8afae52009-01-22 02:24:57112// * theming
[email protected]86281ad2009-10-07 20:07:17113#include "app/gfx/native_theme_win.h"
[email protected]6c8afae52009-01-22 02:24:57114#endif
115
[email protected]c20210e62009-04-03 21:39:26116using base::Time;
[email protected]e1acf6f2008-10-27 20:43:33117using base::TimeDelta;
[email protected]15d79e12009-08-02 19:23:45118using webkit_glue::AltErrorPageResourceFetcher;
[email protected]51bd36612009-10-20 22:49:47119using webkit_glue::FormFieldValues;
[email protected]b0950a72009-09-29 23:16:17120using webkit_glue::ImageResourceFetcher;
[email protected]ed3fb032009-06-16 19:50:56121using webkit_glue::PasswordForm;
[email protected]daa8c58e2009-06-15 17:21:10122using webkit_glue::PasswordFormDomManager;
[email protected]c7287a92009-11-04 20:06:15123using WebKit::WebAccessibilityCache;
[email protected]cc0445f2009-10-13 16:09:08124using WebKit::WebAccessibilityObject;
[email protected]1c83eb42009-09-11 21:08:41125using WebKit::WebColor;
126using WebKit::WebColorName;
[email protected]0dea3ea2009-03-31 23:30:59127using WebKit::WebConsoleMessage;
[email protected]79e37442009-10-09 18:17:44128using WebKit::WebContextMenuData;
[email protected]e6f546c32009-07-01 17:12:55129using WebKit::WebData;
[email protected]726985e22009-06-18 21:09:28130using WebKit::WebDataSource;
[email protected]2661b332009-11-03 18:42:29131using WebKit::WebDevToolsAgent;
[email protected]e80c73b2009-04-07 23:24:58132using WebKit::WebDragData;
[email protected]1d9f4132009-09-08 17:29:25133using WebKit::WebDragOperation;
134using WebKit::WebDragOperationsMask;
[email protected]79dbc662009-09-04 05:42:51135using WebKit::WebEditingAction;
[email protected]6069da8c2009-10-20 20:33:49136using WebKit::WebFindOptions;
[email protected]979c28b2009-11-07 01:30:48137using WebKit::WebFormElement;
[email protected]dd7daa82009-08-10 05:46:45138using WebKit::WebFrame;
[email protected]ca948a22009-06-25 19:36:17139using WebKit::WebHistoryItem;
[email protected]3d9689372009-09-10 04:29:17140using WebKit::WebMediaPlayer;
[email protected]952cb702009-10-07 05:50:28141using WebKit::WebMediaPlayerAction;
[email protected]3d9689372009-09-10 04:29:17142using WebKit::WebMediaPlayerClient;
[email protected]4873c7d2009-07-16 06:36:28143using WebKit::WebNavigationPolicy;
[email protected]726985e22009-06-18 21:09:28144using WebKit::WebNavigationType;
[email protected]79dbc662009-09-04 05:42:51145using WebKit::WebNode;
[email protected]3d9689372009-09-10 04:29:17146using WebKit::WebPlugin;
147using WebKit::WebPluginParams;
[email protected]48c9cf2d2009-09-16 16:47:52148using WebKit::WebPoint;
[email protected]88efb7ec2009-07-14 16:32:59149using WebKit::WebPopupMenuInfo;
[email protected]79dbc662009-09-04 05:42:51150using WebKit::WebRange;
[email protected]b3f2b912009-04-09 16:18:52151using WebKit::WebRect;
[email protected]4f999132009-03-31 18:08:40152using WebKit::WebScriptSource;
[email protected]ce0e250d2009-10-23 21:00:35153using WebKit::WebSearchableFormData;
[email protected]e3d60e5d2009-09-25 21:08:29154using WebKit::WebSecurityOrigin;
[email protected]2fab253a2009-08-17 23:00:59155using WebKit::WebSettings;
[email protected]9c00f002009-11-05 22:37:42156using WebKit::WebSharedWorker;
[email protected]8649fb32009-06-26 17:51:02157using WebKit::WebSize;
[email protected]726985e22009-06-18 21:09:28158using WebKit::WebString;
[email protected]79dbc662009-09-04 05:42:51159using WebKit::WebTextAffinity;
[email protected]de570ef2009-07-29 18:27:52160using WebKit::WebTextDirection;
[email protected]726985e22009-06-18 21:09:28161using WebKit::WebURL;
162using WebKit::WebURLError;
163using WebKit::WebURLRequest;
164using WebKit::WebURLResponse;
[email protected]4873c7d2009-07-16 06:36:28165using WebKit::WebVector;
[email protected]50ae00ef2009-10-19 05:11:03166using WebKit::WebView;
[email protected]4873c7d2009-07-16 06:36:28167using WebKit::WebWidget;
[email protected]27ba8532009-04-24 20:22:43168using WebKit::WebWorker;
169using WebKit::WebWorkerClient;
[email protected]e1acf6f2008-10-27 20:43:33170
initial.commit09911bf2008-07-26 23:55:29171//-----------------------------------------------------------------------------
172
173// define to write the time necessary for thumbnail/DOM text retrieval,
174// respectively, into the system debug log
175// #define TIME_BITMAP_RETRIEVAL
176// #define TIME_TEXT_RETRIEVAL
177
178// maximum number of characters in the document to index, any text beyond this
179// point will be clipped
[email protected]6c8afae52009-01-22 02:24:57180static const size_t kMaxIndexChars = 65535;
initial.commit09911bf2008-07-26 23:55:29181
182// Size of the thumbnails that we'll generate
[email protected]8b4f4892009-09-04 21:52:37183static const int kThumbnailWidth = 212;
184static const int kThumbnailHeight = 132;
initial.commit09911bf2008-07-26 23:55:29185
186// Delay in milliseconds that we'll wait before capturing the page contents
187// and thumbnail.
188static const int kDelayForCaptureMs = 500;
189
190// Typically, we capture the page data once the page is loaded.
191// Sometimes, the page never finishes to load, preventing the page capture
192// To workaround this problem, we always perform a capture after the following
193// delay.
194static const int kDelayForForcedCaptureMs = 6000;
195
[email protected]882daa92009-11-05 16:31:31196// Time, in seconds, we delay before sending content state changes (such as form
197// state and scroll position) to the browser. We delay sending changes to avoid
198// spamming the browser.
199// To avoid having tab/session restore require sending a message to get the
200// current content state during tab closing we use a shorter timeout for the
201// foreground renderer. This means there is a small window of time from which
202// content state is modified and not sent to session restore, but this is
203// better than having to wake up all renderers during shutdown.
204static const int kDelaySecondsForContentStateSyncHidden = 5;
205static const int kDelaySecondsForContentStateSync = 1;
initial.commit09911bf2008-07-26 23:55:29206
[email protected]0aa55312008-10-17 21:53:08207// The maximum number of popups that can be spawned from one page.
208static const int kMaximumNumberOfUnacknowledgedPopups = 25;
209
initial.commit09911bf2008-07-26 23:55:29210static const char* const kUnreachableWebDataURL =
[email protected]60e448982009-05-06 04:21:16211 "chrome://chromewebdata/";
initial.commit09911bf2008-07-26 23:55:29212
[email protected]50b691c2008-10-31 19:08:35213static const char* const kBackForwardNavigationScheme = "history";
214
[email protected]726985e22009-06-18 21:09:28215static void GetRedirectChain(WebDataSource* ds, std::vector<GURL>* result) {
216 WebVector<WebURL> urls;
217 ds->redirectChain(urls);
218 result->reserve(urls.size());
219 for (size_t i = 0; i < urls.size(); ++i)
220 result->push_back(urls[i]);
221}
222
initial.commit09911bf2008-07-26 23:55:29223///////////////////////////////////////////////////////////////////////////////
224
[email protected]60c42a8c72009-10-09 04:08:59225int32 RenderView::next_page_id_ = 1;
226
[email protected]2fab253a2009-08-17 23:00:59227RenderView::RenderView(RenderThreadBase* render_thread,
228 const WebPreferences& webkit_preferences)
[email protected]81a34412009-01-05 19:17:24229 : RenderWidget(render_thread, true),
[email protected]81e63782009-02-27 19:35:09230 enabled_bindings_(0),
[email protected]e75cb49e2009-01-05 23:13:21231 target_url_status_(TARGET_NONE),
[email protected]81a34412009-01-05 19:17:24232 is_loading_(false),
[email protected]e75cb49e2009-01-05 23:13:21233 navigation_gesture_(NavigationGestureUnknown),
[email protected]81a34412009-01-05 19:17:24234 page_id_(-1),
235 last_page_id_sent_to_browser_(-1),
236 last_indexed_page_id_(-1),
[email protected]81a34412009-01-05 19:17:24237 opened_by_user_gesture_(true),
[email protected]007a848b2009-10-26 15:55:46238 opener_suppressed_(false),
[email protected]bb063b72009-03-27 23:18:50239 ALLOW_THIS_IN_INITIALIZER_LIST(method_factory_(this)),
[email protected]e4ac5df2009-03-17 15:33:11240 devtools_agent_(NULL),
241 devtools_client_(NULL),
[email protected]a1128322009-10-06 18:38:46242 file_chooser_completion_(NULL),
[email protected]81a34412009-01-05 19:17:24243 history_back_list_count_(0),
244 history_forward_list_count_(0),
[email protected]81a34412009-01-05 19:17:24245 has_unload_listener_(false),
246 decrement_shared_popup_at_destruction_(false),
[email protected]acca2a1f2009-10-16 03:53:39247 autofill_query_id_(0),
[email protected]81a34412009-01-05 19:17:24248 popup_notification_visible_(false),
[email protected]8922e1f2009-10-03 05:01:26249 spelling_panel_visible_(false),
[email protected]882daa92009-11-05 16:31:31250 send_content_state_immediately_(false),
[email protected]ab32b16c2009-10-16 14:57:25251 send_preferred_size_changes_(false),
[email protected]b6849bda2009-10-14 23:59:26252 ALLOW_THIS_IN_INITIALIZER_LIST(
253 notification_provider_(new NotificationProvider(this))),
[email protected]5f450e52009-07-28 13:28:11254 determine_page_text_after_loading_stops_(false),
[email protected]7b291f92009-08-14 05:43:53255 view_type_(ViewType::INVALID),
256 browser_window_id_(-1),
[email protected]83dde542009-09-11 20:59:55257 last_top_level_navigation_page_id_(-1),
258#if defined(OS_MACOSX)
259 has_document_tag_(false),
260#endif
[email protected]98324892009-09-09 21:16:05261 document_tag_(0),
[email protected]2fab253a2009-08-17 23:00:59262 webkit_preferences_(webkit_preferences) {
initial.commit09911bf2008-07-26 23:55:29263}
264
265RenderView::~RenderView() {
[email protected]0aa55312008-10-17 21:53:08266 if (decrement_shared_popup_at_destruction_)
267 shared_popup_counter_->data--;
268
[email protected]b0950a72009-09-29 23:16:17269 // Dispose of un-disposed image fetchers.
270 for (ImageResourceFetcherSet::iterator i = image_fetchers_.begin();
271 i != image_fetchers_.end(); ++i) {
272 delete *i;
273 }
274
[email protected]a1128322009-10-06 18:38:46275 // If file chooser is still waiting for answer, dispatch empty answer.
276 if (file_chooser_completion_)
277 file_chooser_completion_->didChooseFile(WebVector<WebString>());
278
[email protected]83dde542009-09-11 20:59:55279#if defined(OS_MACOSX)
[email protected]98324892009-09-09 21:16:05280 // Tell the spellchecker that the document is closed.
[email protected]83dde542009-09-11 20:59:55281 if (has_document_tag_)
282 Send(new ViewHostMsg_DocumentWithTagClosed(routing_id_, document_tag_));
283#endif
[email protected]98324892009-09-09 21:16:05284
[email protected]5fb88962009-04-16 19:03:25285 render_thread_->RemoveFilter(audio_message_filter_);
[email protected]60c42a8c72009-10-09 04:08:59286
287#ifndef NDEBUG
288 // Make sure we are no longer referenced by the ViewMap.
289 ViewMap* views = Singleton<ViewMap>::get();
290 for (ViewMap::iterator it = views->begin(); it != views->end(); ++it)
291 DCHECK_NE(this, it->second) << "Failed to call Close?";
292#endif
293}
294
295/*static*/
296void RenderView::ForEach(RenderViewVisitor* visitor) {
297 ViewMap* views = Singleton<ViewMap>::get();
298 for (ViewMap::iterator it = views->begin(); it != views->end(); ++it) {
299 if (!visitor->Visit(it->second))
300 return;
301 }
302}
303
304/*static*/
305RenderView* RenderView::FromWebView(WebView* webview) {
306 ViewMap* views = Singleton<ViewMap>::get();
307 ViewMap::iterator it = views->find(webview);
308 return it == views->end() ? NULL : it->second;
initial.commit09911bf2008-07-26 23:55:29309}
310
311/*static*/
[email protected]0aa55312008-10-17 21:53:08312RenderView* RenderView::Create(
[email protected]81a34412009-01-05 19:17:24313 RenderThreadBase* render_thread,
[email protected]18bcc3c2009-01-27 21:39:15314 gfx::NativeViewId parent_hwnd,
[email protected]0aa55312008-10-17 21:53:08315 int32 opener_id,
[email protected]80d96fa2009-06-10 22:34:51316 const RendererPreferences& renderer_prefs,
[email protected]0aa55312008-10-17 21:53:08317 const WebPreferences& webkit_prefs,
318 SharedRenderViewCounter* counter,
319 int32 routing_id) {
initial.commit09911bf2008-07-26 23:55:29320 DCHECK(routing_id != MSG_ROUTING_NONE);
[email protected]2fab253a2009-08-17 23:00:59321 scoped_refptr<RenderView> view = new RenderView(render_thread, webkit_prefs);
initial.commit09911bf2008-07-26 23:55:29322 view->Init(parent_hwnd,
initial.commit09911bf2008-07-26 23:55:29323 opener_id,
[email protected]80d96fa2009-06-10 22:34:51324 renderer_prefs,
[email protected]0aa55312008-10-17 21:53:08325 counter,
initial.commit09911bf2008-07-26 23:55:29326 routing_id); // adds reference
327 return view;
328}
329
330/*static*/
331void RenderView::SetNextPageID(int32 next_page_id) {
332 // This method should only be called during process startup, and the given
333 // page id had better not exceed our current next page id!
[email protected]4646f292009-05-20 03:49:05334 DCHECK_EQ(next_page_id_, 1);
initial.commit09911bf2008-07-26 23:55:29335 DCHECK(next_page_id >= next_page_id_);
336 next_page_id_ = next_page_id;
337}
338
[email protected]afe3a1672009-11-17 19:04:12339void RenderView::UserMetricsRecordAction(const std::string& action) {
[email protected]1dbafaf72009-09-23 19:43:56340 Send(new ViewHostMsg_UserMetricsRecordAction(routing_id_, action));
341}
342
[email protected]a3a8fb6d2009-10-22 20:12:51343void RenderView::PluginCrashed(const FilePath& plugin_path) {
344 Send(new ViewHostMsg_CrashedPlugin(routing_id_, plugin_path));
initial.commit09911bf2008-07-26 23:55:29345}
346
[email protected]18bcc3c2009-01-27 21:39:15347void RenderView::Init(gfx::NativeViewId parent_hwnd,
initial.commit09911bf2008-07-26 23:55:29348 int32 opener_id,
[email protected]80d96fa2009-06-10 22:34:51349 const RendererPreferences& renderer_prefs,
[email protected]0aa55312008-10-17 21:53:08350 SharedRenderViewCounter* counter,
initial.commit09911bf2008-07-26 23:55:29351 int32 routing_id) {
352 DCHECK(!webview());
353
354 if (opener_id != MSG_ROUTING_NONE)
355 opener_id_ = opener_id;
356
[email protected]0aa55312008-10-17 21:53:08357 if (counter) {
358 shared_popup_counter_ = counter;
359 shared_popup_counter_->data++;
360 decrement_shared_popup_at_destruction_ = true;
361 } else {
362 shared_popup_counter_ = new SharedRenderViewCounter(0);
363 decrement_shared_popup_at_destruction_ = false;
364 }
365
[email protected]58bfc6b2009-06-24 09:45:02366 devtools_agent_.reset(new DevToolsAgent(routing_id, this));
[email protected]9b9d7282009-04-08 14:13:04367
[email protected]50ae00ef2009-10-19 05:11:03368 webwidget_ = WebView::create(this);
[email protected]60c42a8c72009-10-09 04:08:59369 Singleton<ViewMap>::get()->insert(std::make_pair(webview(), this));
[email protected]2fab253a2009-08-17 23:00:59370 webkit_preferences_.Apply(webview());
[email protected]b4bb2502009-10-01 22:35:27371 webview()->initializeMainFrame(this);
[email protected]2661b332009-11-03 18:42:29372 webview()->setDevToolsAgent(
373 WebDevToolsAgent::create(webview(), devtools_agent_.get()));
initial.commit09911bf2008-07-26 23:55:29374
[email protected]d3ba77272009-09-03 00:06:09375 OnSetRendererPrefs(renderer_prefs);
376
initial.commit09911bf2008-07-26 23:55:29377 routing_id_ = routing_id;
[email protected]81a34412009-01-05 19:17:24378 render_thread_->AddRoute(routing_id_, this);
initial.commit09911bf2008-07-26 23:55:29379 // Take a reference on behalf of the RenderThread. This will be balanced
380 // when we receive ViewMsg_Close.
381 AddRef();
382
383 // If this is a popup, we must wait for the CreatingNew_ACK message before
384 // completing initialization. Otherwise, we can finish it now.
385 if (opener_id == MSG_ROUTING_NONE) {
386 did_show_ = true;
387 CompleteInit(parent_hwnd);
388 }
389
390 host_window_ = parent_hwnd;
initial.commit09911bf2008-07-26 23:55:29391
[email protected]58bfc6b2009-06-24 09:45:02392 const CommandLine& command_line = *CommandLine::ForCurrentProcess();
[email protected]81e63782009-02-27 19:35:09393 if (command_line.HasSwitch(switches::kDomAutomationController))
394 enabled_bindings_ |= BindingsPolicy::DOM_AUTOMATION;
initial.commit09911bf2008-07-26 23:55:29395
[email protected]5fb88962009-04-16 19:03:25396 audio_message_filter_ = new AudioMessageFilter(routing_id_);
397 render_thread_->AddFilter(audio_message_filter_);
initial.commit09911bf2008-07-26 23:55:29398}
399
400void RenderView::OnMessageReceived(const IPC::Message& message) {
[email protected]26aa0482009-09-30 16:55:27401 WebFrame* main_frame = webview() ? webview()->mainFrame() : NULL;
[email protected]a9f607e2009-10-23 19:59:27402 if (main_frame)
403 child_process_logging::SetActiveURL(main_frame->url());
[email protected]f8b6b6f2009-03-10 16:48:26404
[email protected]b2abac72009-02-26 12:39:28405 // If this is developer tools renderer intercept tools messages first.
[email protected]e4ac5df2009-03-17 15:33:11406 if (devtools_client_.get() && devtools_client_->OnMessageReceived(message))
[email protected]b2abac72009-02-26 12:39:28407 return;
[email protected]b4b967e2009-04-22 11:33:05408 if (devtools_agent_.get() && devtools_agent_->OnMessageReceived(message))
409 return;
[email protected]b6849bda2009-10-14 23:59:26410 if (notification_provider_->OnMessageReceived(message))
411 return;
[email protected]b2abac72009-02-26 12:39:28412
initial.commit09911bf2008-07-26 23:55:29413 IPC_BEGIN_MESSAGE_MAP(RenderView, message)
initial.commit09911bf2008-07-26 23:55:29414 IPC_MESSAGE_HANDLER(ViewMsg_CaptureThumbnail, SendThumbnail)
initial.commit09911bf2008-07-26 23:55:29415 IPC_MESSAGE_HANDLER(ViewMsg_PrintPages, OnPrintPages)
[email protected]82270452009-06-19 15:58:01416 IPC_MESSAGE_HANDLER(ViewMsg_PrintingDone, OnPrintingDone)
initial.commit09911bf2008-07-26 23:55:29417 IPC_MESSAGE_HANDLER(ViewMsg_Navigate, OnNavigate)
418 IPC_MESSAGE_HANDLER(ViewMsg_Stop, OnStop)
419 IPC_MESSAGE_HANDLER(ViewMsg_LoadAlternateHTMLText, OnLoadAlternateHTMLText)
420 IPC_MESSAGE_HANDLER(ViewMsg_StopFinding, OnStopFinding)
421 IPC_MESSAGE_HANDLER(ViewMsg_Undo, OnUndo)
422 IPC_MESSAGE_HANDLER(ViewMsg_Redo, OnRedo)
423 IPC_MESSAGE_HANDLER(ViewMsg_Cut, OnCut)
424 IPC_MESSAGE_HANDLER(ViewMsg_Copy, OnCopy)
[email protected]c0cc3092009-09-12 08:27:27425#if defined(OS_MACOSX)
[email protected]a954bf72009-09-12 07:30:35426 IPC_MESSAGE_HANDLER(ViewMsg_CopyToFindPboard, OnCopyToFindPboard)
[email protected]c0cc3092009-09-12 08:27:27427#endif
initial.commit09911bf2008-07-26 23:55:29428 IPC_MESSAGE_HANDLER(ViewMsg_Paste, OnPaste)
429 IPC_MESSAGE_HANDLER(ViewMsg_Replace, OnReplace)
[email protected]98324892009-09-09 21:16:05430 IPC_MESSAGE_HANDLER(ViewMsg_ToggleSpellPanel, OnToggleSpellPanel)
431 IPC_MESSAGE_HANDLER(ViewMsg_AdvanceToNextMisspelling,
432 OnAdvanceToNextMisspelling)
[email protected]bbbd545c2008-12-15 20:18:04433 IPC_MESSAGE_HANDLER(ViewMsg_ToggleSpellCheck, OnToggleSpellCheck)
initial.commit09911bf2008-07-26 23:55:29434 IPC_MESSAGE_HANDLER(ViewMsg_Delete, OnDelete)
435 IPC_MESSAGE_HANDLER(ViewMsg_SelectAll, OnSelectAll)
436 IPC_MESSAGE_HANDLER(ViewMsg_CopyImageAt, OnCopyImageAt)
[email protected]4b59ae602009-06-23 20:58:15437 IPC_MESSAGE_HANDLER(ViewMsg_ExecuteEditCommand, OnExecuteEditCommand)
initial.commit09911bf2008-07-26 23:55:29438 IPC_MESSAGE_HANDLER(ViewMsg_Find, OnFind)
[email protected]5c4266922009-07-10 16:41:27439 IPC_MESSAGE_HANDLER(ViewMsg_DeterminePageText, OnDeterminePageText)
[email protected]630e26b2008-10-14 22:55:17440 IPC_MESSAGE_HANDLER(ViewMsg_Zoom, OnZoom)
initial.commit09911bf2008-07-26 23:55:29441 IPC_MESSAGE_HANDLER(ViewMsg_SetPageEncoding, OnSetPageEncoding)
[email protected]a697f4c2009-09-14 22:30:18442 IPC_MESSAGE_HANDLER(ViewMsg_ResetPageEncodingToDefault,
443 OnResetPageEncodingToDefault)
[email protected]b2abac72009-02-26 12:39:28444 IPC_MESSAGE_HANDLER(ViewMsg_SetupDevToolsClient, OnSetupDevToolsClient)
[email protected]bf5c2ff392009-07-08 16:24:33445 IPC_MESSAGE_HANDLER(ViewMsg_DownloadFavIcon, OnDownloadFavIcon)
initial.commit09911bf2008-07-26 23:55:29446 IPC_MESSAGE_HANDLER(ViewMsg_ScriptEvalRequest, OnScriptEvalRequest)
[email protected]1810e132009-03-24 23:35:48447 IPC_MESSAGE_HANDLER(ViewMsg_CSSInsertRequest, OnCSSInsertRequest)
initial.commit09911bf2008-07-26 23:55:29448 IPC_MESSAGE_HANDLER(ViewMsg_AddMessageToConsole, OnAddMessageToConsole)
initial.commit09911bf2008-07-26 23:55:29449 IPC_MESSAGE_HANDLER(ViewMsg_ReservePageIDRange, OnReservePageIDRange)
initial.commit09911bf2008-07-26 23:55:29450 IPC_MESSAGE_HANDLER(ViewMsg_FormFill, OnFormFill)
451 IPC_MESSAGE_HANDLER(ViewMsg_FillPasswordForm, OnFillPasswordForm)
452 IPC_MESSAGE_HANDLER(ViewMsg_DragTargetDragEnter, OnDragTargetDragEnter)
453 IPC_MESSAGE_HANDLER(ViewMsg_DragTargetDragOver, OnDragTargetDragOver)
454 IPC_MESSAGE_HANDLER(ViewMsg_DragTargetDragLeave, OnDragTargetDragLeave)
455 IPC_MESSAGE_HANDLER(ViewMsg_DragTargetDrop, OnDragTargetDrop)
[email protected]18cb2572008-08-21 20:34:45456 IPC_MESSAGE_HANDLER(ViewMsg_AllowBindings, OnAllowBindings)
initial.commit09911bf2008-07-26 23:55:29457 IPC_MESSAGE_HANDLER(ViewMsg_SetDOMUIProperty, OnSetDOMUIProperty)
[email protected]266eb6f2008-09-30 23:56:50458 IPC_MESSAGE_HANDLER(ViewMsg_DragSourceEndedOrMoved,
459 OnDragSourceEndedOrMoved)
initial.commit09911bf2008-07-26 23:55:29460 IPC_MESSAGE_HANDLER(ViewMsg_DragSourceSystemDragEnded,
461 OnDragSourceSystemDragEnded)
462 IPC_MESSAGE_HANDLER(ViewMsg_SetInitialFocus, OnSetInitialFocus)
463 IPC_MESSAGE_HANDLER(ViewMsg_FindReplyACK, OnFindReplyAck)
464 IPC_MESSAGE_HANDLER(ViewMsg_UpdateTargetURL_ACK, OnUpdateTargetURLAck)
465 IPC_MESSAGE_HANDLER(ViewMsg_UpdateWebPreferences, OnUpdateWebPreferences)
466 IPC_MESSAGE_HANDLER(ViewMsg_SetAltErrorPageURL, OnSetAltErrorPageURL)
467 IPC_MESSAGE_HANDLER(ViewMsg_InstallMissingPlugin, OnInstallMissingPlugin)
468 IPC_MESSAGE_HANDLER(ViewMsg_RunFileChooserResponse, OnFileChooserResponse)
469 IPC_MESSAGE_HANDLER(ViewMsg_EnableViewSourceMode, OnEnableViewSourceMode)
470 IPC_MESSAGE_HANDLER(ViewMsg_UpdateBackForwardListCount,
471 OnUpdateBackForwardListCount)
472 IPC_MESSAGE_HANDLER(ViewMsg_GetAllSavableResourceLinksForCurrentPage,
473 OnGetAllSavableResourceLinksForCurrentPage)
[email protected]f09c7182009-03-10 12:54:04474 IPC_MESSAGE_HANDLER(
475 ViewMsg_GetSerializedHtmlDataForCurrentPageWithLocalLinks,
476 OnGetSerializedHtmlDataForCurrentPageWithLocalLinks)
initial.commit09911bf2008-07-26 23:55:29477 IPC_MESSAGE_HANDLER(ViewMsg_GetApplicationInfo, OnGetApplicationInfo)
[email protected]266eb6f2008-09-30 23:56:50478 IPC_MESSAGE_HANDLER(ViewMsg_GetAccessibilityInfo, OnGetAccessibilityInfo)
479 IPC_MESSAGE_HANDLER(ViewMsg_ClearAccessibilityInfo,
480 OnClearAccessibilityInfo)
initial.commit09911bf2008-07-26 23:55:29481 IPC_MESSAGE_HANDLER(ViewMsg_ShouldClose, OnMsgShouldClose)
482 IPC_MESSAGE_HANDLER(ViewMsg_ClosePage, OnClosePage)
483 IPC_MESSAGE_HANDLER(ViewMsg_ThemeChanged, OnThemeChanged)
[email protected]18cb2572008-08-21 20:34:45484 IPC_MESSAGE_HANDLER(ViewMsg_HandleMessageFromExternalHost,
485 OnMessageFromExternalHost)
[email protected]0aa55312008-10-17 21:53:08486 IPC_MESSAGE_HANDLER(ViewMsg_DisassociateFromPopupCount,
487 OnDisassociateFromPopupCount)
[email protected]842936a2009-10-14 06:00:36488 IPC_MESSAGE_HANDLER(ViewMsg_QueryFormFieldAutofill_ACK,
489 OnQueryFormFieldAutofillAck)
[email protected]2c4410d2009-05-06 23:46:22490 IPC_MESSAGE_HANDLER(ViewMsg_PopupNotificationVisibilityChanged,
491 OnPopupNotificationVisibilityChanged)
[email protected]30f75e62009-02-25 22:01:00492 IPC_MESSAGE_HANDLER(ViewMsg_MoveOrResizeStarted, OnMoveOrResizeStarted)
[email protected]309d7a282009-03-24 09:18:27493 IPC_MESSAGE_HANDLER(ViewMsg_ExtensionResponse, OnExtensionResponse)
[email protected]7120f132009-07-20 21:05:37494 IPC_MESSAGE_HANDLER(ViewMsg_ExtensionMessageInvoke,
495 OnExtensionMessageInvoke)
[email protected]05d478752009-04-08 23:38:16496 IPC_MESSAGE_HANDLER(ViewMsg_ClearFocusedNode, OnClearFocusedNode)
[email protected]699ab0d2009-04-23 23:19:14497 IPC_MESSAGE_HANDLER(ViewMsg_SetBackground, OnSetBackground)
[email protected]ab32b16c2009-10-16 14:57:25498 IPC_MESSAGE_HANDLER(ViewMsg_EnablePreferredSizeChangedMode,
499 OnEnablePreferredSizeChangedMode)
[email protected]80d96fa2009-06-10 22:34:51500 IPC_MESSAGE_HANDLER(ViewMsg_SetRendererPrefs, OnSetRendererPrefs)
[email protected]7b291f92009-08-14 05:43:53501 IPC_MESSAGE_HANDLER(ViewMsg_UpdateBrowserWindowId,
502 OnUpdateBrowserWindowId)
503 IPC_MESSAGE_HANDLER(ViewMsg_NotifyRenderViewType,
504 OnNotifyRendererViewType)
[email protected]581b87eb2009-07-23 23:06:56505 IPC_MESSAGE_HANDLER(ViewMsg_MediaPlayerActionAt, OnMediaPlayerActionAt)
[email protected]8c66c5a2009-07-22 17:26:34506 IPC_MESSAGE_HANDLER(ViewMsg_SetActive, OnSetActive)
[email protected]446705872009-09-10 07:22:48507 IPC_MESSAGE_HANDLER(ViewMsg_SetEditCommandsForNextKeyEvent,
508 OnSetEditCommandsForNextKeyEvent);
[email protected]912256b32009-09-18 09:47:35509 IPC_MESSAGE_HANDLER(ViewMsg_ExecuteCode,
510 OnExecuteCode)
[email protected]634a6f92008-12-01 21:39:31511
initial.commit09911bf2008-07-26 23:55:29512 // Have the super handle all other messages.
513 IPC_MESSAGE_UNHANDLED(RenderWidget::OnMessageReceived(message))
514 IPC_END_MESSAGE_MAP()
515}
516
initial.commit09911bf2008-07-26 23:55:29517void RenderView::SendThumbnail() {
[email protected]26aa0482009-09-30 16:55:27518 WebFrame* main_frame = webview()->mainFrame();
initial.commit09911bf2008-07-26 23:55:29519 if (!main_frame)
520 return;
521
522 // get the URL for this page
[email protected]dd7daa82009-08-10 05:46:45523 GURL url(main_frame->url());
initial.commit09911bf2008-07-26 23:55:29524 if (url.is_empty())
525 return;
526
527 if (size_.IsEmpty())
528 return; // Don't create an empty thumbnail!
529
530 ThumbnailScore score;
531 SkBitmap thumbnail;
[email protected]8649fb32009-06-26 17:51:02532 if (!CaptureThumbnail(webview(), kThumbnailWidth, kThumbnailHeight,
[email protected]b6e4bec2008-11-12 01:17:15533 &thumbnail, &score))
534 return;
535
initial.commit09911bf2008-07-26 23:55:29536 // send the thumbnail message to the browser process
[email protected]674741932009-02-04 23:44:46537 Send(new ViewHostMsg_Thumbnail(routing_id_, url, score, thumbnail));
initial.commit09911bf2008-07-26 23:55:29538}
539
[email protected]068637222009-01-29 16:58:07540void RenderView::OnPrintPages() {
initial.commit09911bf2008-07-26 23:55:29541 DCHECK(webview());
[email protected]aa82249f2009-07-16 17:23:58542 if (webview()) {
543 // If the user has selected text in the currently focused frame we print
544 // only that frame (this makes print selection work for multiple frames).
[email protected]26aa0482009-09-30 16:55:27545 if (webview()->focusedFrame()->hasSelection())
546 Print(webview()->focusedFrame(), false);
[email protected]aa82249f2009-07-16 17:23:58547 else
[email protected]26aa0482009-09-30 16:55:27548 Print(webview()->mainFrame(), false);
[email protected]aa82249f2009-07-16 17:23:58549 }
initial.commit09911bf2008-07-26 23:55:29550}
551
[email protected]82270452009-06-19 15:58:01552void RenderView::OnPrintingDone(int document_cookie, bool success) {
553 // Ignoring document cookie here since only one print job can be outstanding
554 // per renderer and document_cookie is 0 when printing is successful.
555 DCHECK(print_helper_.get());
556 if (print_helper_.get() != NULL) {
557 print_helper_->DidFinishPrinting(success);
558 }
559}
560
initial.commit09911bf2008-07-26 23:55:29561void RenderView::CapturePageInfo(int load_id, bool preliminary_capture) {
562 if (load_id != page_id_)
563 return; // this capture call is no longer relevant due to navigation
564 if (load_id == last_indexed_page_id_)
565 return; // we already indexed this page
566
567 if (!webview())
568 return;
569
[email protected]26aa0482009-09-30 16:55:27570 WebFrame* main_frame = webview()->mainFrame();
initial.commit09911bf2008-07-26 23:55:29571 if (!main_frame)
572 return;
573
574 // Don't index/capture pages that are in view source mode.
[email protected]dd7daa82009-08-10 05:46:45575 if (main_frame->isViewSourceModeEnabled())
initial.commit09911bf2008-07-26 23:55:29576 return;
577
578 // Don't index/capture pages that failed to load. This only checks the top
579 // level frame so the thumbnail may contain a frame that failed to load.
[email protected]dd7daa82009-08-10 05:46:45580 WebDataSource* ds = main_frame->dataSource();
[email protected]726985e22009-06-18 21:09:28581 if (ds && ds->hasUnreachableURL())
initial.commit09911bf2008-07-26 23:55:29582 return;
583
584 if (!preliminary_capture)
585 last_indexed_page_id_ = load_id;
586
587 // get the URL for this page
[email protected]dd7daa82009-08-10 05:46:45588 GURL url(main_frame->url());
initial.commit09911bf2008-07-26 23:55:29589 if (url.is_empty())
590 return;
591
592 // full text
593 std::wstring contents;
594 CaptureText(main_frame, &contents);
595 if (contents.size()) {
596 // Send the text to the browser for indexing.
597 Send(new ViewHostMsg_PageContents(url, load_id, contents));
598 }
599
[email protected]5c4266922009-07-10 16:41:27600 // Send over text content of this page to the browser.
601 if (determine_page_text_after_loading_stops_) {
602 determine_page_text_after_loading_stops_ = false;
603 Send(new ViewMsg_DeterminePageText_Reply(routing_id_, contents));
604 }
605
initial.commit09911bf2008-07-26 23:55:29606 // thumbnail
607 SendThumbnail();
608}
609
610void RenderView::CaptureText(WebFrame* frame, std::wstring* contents) {
611 contents->clear();
612 if (!frame)
613 return;
614
[email protected]0faf0bd92008-09-09 20:53:27615 // Don't index any https pages. People generally don't want their bank
616 // accounts, etc. indexed on their computer, especially since some of these
617 // things are not marked cachable.
618 // TODO(brettw) we may want to consider more elaborate heuristics such as
619 // the cachability of the page. We may also want to consider subframes (this
620 // test will still index subframes if the subframe is SSL).
[email protected]dd7daa82009-08-10 05:46:45621 if (GURL(frame->url()).SchemeIsSecure())
[email protected]0faf0bd92008-09-09 20:53:27622 return;
623
initial.commit09911bf2008-07-26 23:55:29624#ifdef TIME_TEXT_RETRIEVAL
625 double begin = time_util::GetHighResolutionTimeNow();
626#endif
627
628 // get the contents of the frame
[email protected]dd7daa82009-08-10 05:46:45629 *contents = UTF16ToWideHack(frame->contentAsText(kMaxIndexChars));
initial.commit09911bf2008-07-26 23:55:29630
631#ifdef TIME_TEXT_RETRIEVAL
632 double end = time_util::GetHighResolutionTimeNow();
633 char buf[128];
634 sprintf_s(buf, "%d chars retrieved for indexing in %gms\n",
635 contents.size(), (end - begin)*1000);
636 OutputDebugStringA(buf);
637#endif
638
639 // When the contents are clipped to the maximum, we don't want to have a
640 // partial word indexed at the end that might have been clipped. Therefore,
641 // terminate the string at the last space to ensure no words are clipped.
642 if (contents->size() == kMaxIndexChars) {
643 size_t last_space_index = contents->find_last_of(kWhitespaceWide);
644 if (last_space_index == std::wstring::npos)
645 return; // don't index if we got a huge block of text with no spaces
646 contents->resize(last_space_index);
647 }
648}
649
[email protected]8649fb32009-06-26 17:51:02650bool RenderView::CaptureThumbnail(WebView* view,
initial.commit09911bf2008-07-26 23:55:29651 int w,
652 int h,
653 SkBitmap* thumbnail,
654 ThumbnailScore* score) {
655#ifdef TIME_BITMAP_RETRIEVAL
656 double begin = time_util::GetHighResolutionTimeNow();
657#endif
658
[email protected]4873c7d2009-07-16 06:36:28659 view->layout();
660 const WebSize& size = view->size();
[email protected]b6e4bec2008-11-12 01:17:15661
[email protected]8649fb32009-06-26 17:51:02662 skia::PlatformCanvas canvas;
663 if (!canvas.initialize(size.width, size.height, true))
664 return false;
[email protected]8c89e7792009-08-19 21:18:34665 view->paint(webkit_glue::ToWebCanvas(&canvas),
666 WebRect(0, 0, size.width, size.height));
[email protected]8649fb32009-06-26 17:51:02667
668 skia::BitmapPlatformDevice& device =
669 static_cast<skia::BitmapPlatformDevice&>(canvas.getTopPlatformDevice());
670
671 const SkBitmap& src_bmp = device.accessBitmap(false);
initial.commit09911bf2008-07-26 23:55:29672
[email protected]cab34d6a2009-09-24 01:14:52673 SkRect dest_rect = { 0, 0, SkIntToScalar(w), SkIntToScalar(h) };
initial.commit09911bf2008-07-26 23:55:29674 float dest_aspect = dest_rect.width() / dest_rect.height();
675
676 // Get the src rect so that we can preserve the aspect ratio while filling
677 // the destination.
678 SkIRect src_rect;
679 if (src_bmp.width() < dest_rect.width() ||
680 src_bmp.height() < dest_rect.height()) {
681 // Source image is smaller: we clip the part of source image within the
682 // dest rect, and then stretch it to fill the dest rect. We don't respect
683 // the aspect ratio in this case.
684 src_rect.set(0, 0, static_cast<S16CPU>(dest_rect.width()),
685 static_cast<S16CPU>(dest_rect.height()));
686 score->good_clipping = false;
687 } else {
688 float src_aspect = static_cast<float>(src_bmp.width()) / src_bmp.height();
689 if (src_aspect > dest_aspect) {
690 // Wider than tall, clip horizontally: we center the smaller thumbnail in
691 // the wider screen.
692 S16CPU new_width = static_cast<S16CPU>(src_bmp.height() * dest_aspect);
693 S16CPU x_offset = (src_bmp.width() - new_width) / 2;
694 src_rect.set(x_offset, 0, new_width + x_offset, src_bmp.height());
695 score->good_clipping = false;
696 } else {
697 src_rect.set(0, 0, src_bmp.width(),
698 static_cast<S16CPU>(src_bmp.width() / dest_aspect));
699 score->good_clipping = true;
700 }
701 }
702
[email protected]26aa0482009-09-30 16:55:27703 score->at_top = (view->mainFrame()->scrollOffset().height == 0);
initial.commit09911bf2008-07-26 23:55:29704
705 SkBitmap subset;
[email protected]8649fb32009-06-26 17:51:02706 device.accessBitmap(false).extractSubset(&subset, src_rect);
initial.commit09911bf2008-07-26 23:55:29707
708 // Resample the subset that we want to get it the right size.
[email protected]465b34b72008-12-12 20:19:14709 *thumbnail = skia::ImageOperations::Resize(
710 subset, skia::ImageOperations::RESIZE_LANCZOS3, w, h);
initial.commit09911bf2008-07-26 23:55:29711
712 score->boring_score = CalculateBoringScore(thumbnail);
713
714#ifdef TIME_BITMAP_RETRIEVAL
715 double end = time_util::GetHighResolutionTimeNow();
716 char buf[128];
717 sprintf_s(buf, "thumbnail in %gms\n", (end - begin) * 1000);
718 OutputDebugStringA(buf);
719#endif
[email protected]b6e4bec2008-11-12 01:17:15720 return true;
initial.commit09911bf2008-07-26 23:55:29721}
722
723double RenderView::CalculateBoringScore(SkBitmap* bitmap) {
724 int histogram[256] = {0};
725 color_utils::BuildLumaHistogram(bitmap, histogram);
726
727 int color_count = *std::max_element(histogram, histogram + 256);
728 int pixel_count = bitmap->width() * bitmap->height();
729 return static_cast<double>(color_count) / pixel_count;
730}
731
732void RenderView::OnNavigate(const ViewMsg_Navigate_Params& params) {
733 if (!webview())
734 return;
735
[email protected]8c785c62009-07-13 14:20:15736 if (devtools_agent_.get())
737 devtools_agent_->OnNavigate();
738
[email protected]a9f607e2009-10-23 19:59:27739 child_process_logging::SetActiveURL(params.url);
[email protected]f8b6b6f2009-03-10 16:48:26740
initial.commit09911bf2008-07-26 23:55:29741 AboutHandler::MaybeHandle(params.url);
742
[email protected]5e369672009-11-03 23:48:30743 bool is_reload = (params.navigation_type == ViewMsg_Navigate_Params::RELOAD);
initial.commit09911bf2008-07-26 23:55:29744
[email protected]26aa0482009-09-30 16:55:27745 WebFrame* main_frame = webview()->mainFrame();
[email protected]dd7daa82009-08-10 05:46:45746 if (is_reload && main_frame->currentHistoryItem().isNull()) {
initial.commit09911bf2008-07-26 23:55:29747 // We cannot reload if we do not have any history state. This happens, for
748 // example, when recovering from a crash. Our workaround here is a bit of
749 // a hack since it means that reload after a crashed tab does not cause an
750 // end-to-end cache validation.
751 is_reload = false;
752 }
753
[email protected]77f17a82009-05-21 04:42:54754 // A navigation resulting from loading a javascript URL should not be treated
755 // as a browser initiated event. Instead, we want it to look as if the page
756 // initiated any load resulting from JS execution.
757 if (!params.url.SchemeIs(chrome::kJavaScriptScheme)) {
[email protected]5e369672009-11-03 23:48:30758 NavigationState* state = NavigationState::CreateBrowserInitiated(
759 params.page_id, params.transition, params.request_time);
760 if (params.navigation_type == ViewMsg_Navigate_Params::RESTORE) {
761 // We're doing a load of a page that was restored from the last session.
762 // By default this prefers the cache over loading (LOAD_PREFERRING_CACHE)
763 // which can result in stale data for pages that are set to expire. We
764 // explicitly override that by setting the policy here so that as
765 // necessary we load from the network.
766 state->set_cache_policy_override(WebURLRequest::UseProtocolCachePolicy);
767 }
768 pending_navigation_state_.reset(state);
[email protected]77f17a82009-05-21 04:42:54769 }
initial.commit09911bf2008-07-26 23:55:29770
[email protected]04d3c6e2009-05-22 17:00:13771 // If we are reloading, then WebKit will use the history state of the current
772 // page, so we should just ignore any given history state. Otherwise, if we
773 // have history state, then we need to navigate to it, which corresponds to a
774 // back/forward navigation event.
[email protected]e6f546c32009-07-01 17:12:55775 if (is_reload) {
[email protected]dd7daa82009-08-10 05:46:45776 main_frame->reload();
[email protected]e6f546c32009-07-01 17:12:55777 } else if (!params.state.empty()) {
[email protected]04d3c6e2009-05-22 17:00:13778 // We must know the page ID of the page we are navigating back to.
[email protected]f929f2f22009-06-12 16:56:58779 DCHECK_NE(params.page_id, -1);
[email protected]dd7daa82009-08-10 05:46:45780 main_frame->loadHistoryItem(
[email protected]ca948a22009-06-25 19:36:17781 webkit_glue::HistoryItemFromString(params.state));
[email protected]04d3c6e2009-05-22 17:00:13782 } else {
783 // Navigate to the given URL.
[email protected]726985e22009-06-18 21:09:28784 WebURLRequest request(params.url);
initial.commit09911bf2008-07-26 23:55:29785
[email protected]e6f546c32009-07-01 17:12:55786 // A session history navigation should have been accompanied by state.
787 DCHECK_EQ(params.page_id, -1);
[email protected]04d3c6e2009-05-22 17:00:13788
[email protected]dd7daa82009-08-10 05:46:45789 if (main_frame->isViewSourceModeEnabled())
[email protected]e6f546c32009-07-01 17:12:55790 request.setCachePolicy(WebURLRequest::ReturnCacheDataElseLoad);
[email protected]04d3c6e2009-05-22 17:00:13791
[email protected]726985e22009-06-18 21:09:28792 if (params.referrer.is_valid()) {
793 request.setHTTPHeaderField(WebString::fromUTF8("Referer"),
794 WebString::fromUTF8(params.referrer.spec()));
795 }
[email protected]04d3c6e2009-05-22 17:00:13796
[email protected]dd7daa82009-08-10 05:46:45797 main_frame->loadRequest(request);
[email protected]c0588052008-10-27 23:01:50798 }
799
[email protected]77f17a82009-05-21 04:42:54800 // In case LoadRequest failed before DidCreateDataSource was called.
801 pending_navigation_state_.reset();
initial.commit09911bf2008-07-26 23:55:29802}
803
804// Stop loading the current page
805void RenderView::OnStop() {
806 if (webview())
[email protected]b4bb2502009-10-01 22:35:27807 webview()->mainFrame()->stopLoading();
initial.commit09911bf2008-07-26 23:55:29808}
809
[email protected]e6f546c32009-07-01 17:12:55810void RenderView::OnLoadAlternateHTMLText(const std::string& html,
initial.commit09911bf2008-07-26 23:55:29811 bool new_navigation,
812 const GURL& display_url,
813 const std::string& security_info) {
814 if (!webview())
815 return;
816
[email protected]e6f546c32009-07-01 17:12:55817 pending_navigation_state_.reset(NavigationState::CreateBrowserInitiated(
818 new_navigation ? -1 : page_id_, PageTransition::LINK, Time::Now()));
819 pending_navigation_state_->set_security_info(security_info);
initial.commit09911bf2008-07-26 23:55:29820
[email protected]26aa0482009-09-30 16:55:27821 webview()->mainFrame()->loadHTMLString(
822 html, GURL(kUnreachableWebDataURL), display_url, !new_navigation);
[email protected]e6f546c32009-07-01 17:12:55823
824 pending_navigation_state_.reset();
initial.commit09911bf2008-07-26 23:55:29825}
826
827void RenderView::OnCopyImageAt(int x, int y) {
[email protected]26aa0482009-09-30 16:55:27828 webview()->copyImageAt(WebPoint(x, y));
initial.commit09911bf2008-07-26 23:55:29829}
830
[email protected]68b1e922009-06-23 16:00:25831void RenderView::OnExecuteEditCommand(const std::string& name,
832 const std::string& value) {
[email protected]26aa0482009-09-30 16:55:27833 if (!webview() || !webview()->focusedFrame())
[email protected]68b1e922009-06-23 16:00:25834 return;
835
[email protected]26aa0482009-09-30 16:55:27836 webview()->focusedFrame()->executeCommand(
[email protected]dd7daa82009-08-10 05:46:45837 WebString::fromUTF8(name), WebString::fromUTF8(value));
[email protected]68b1e922009-06-23 16:00:25838}
839
[email protected]b2abac72009-02-26 12:39:28840void RenderView::OnSetupDevToolsClient() {
[email protected]e4ac5df2009-03-17 15:33:11841 DCHECK(!devtools_client_.get());
842 devtools_client_.reset(new DevToolsClient(this));
[email protected]b2abac72009-02-26 12:39:28843}
844
initial.commit09911bf2008-07-26 23:55:29845void RenderView::OnStopFinding(bool clear_selection) {
846 WebView* view = webview();
847 if (!view)
848 return;
849
850 if (clear_selection)
[email protected]26aa0482009-09-30 16:55:27851 view->focusedFrame()->executeCommand(WebString::fromUTF8("Unselect"));
initial.commit09911bf2008-07-26 23:55:29852
[email protected]26aa0482009-09-30 16:55:27853 WebFrame* frame = view->mainFrame();
initial.commit09911bf2008-07-26 23:55:29854 while (frame) {
[email protected]dd7daa82009-08-10 05:46:45855 frame->stopFinding(clear_selection);
[email protected]b4bb2502009-10-01 22:35:27856 frame = frame->traverseNext(false);
initial.commit09911bf2008-07-26 23:55:29857 }
858}
859
860void RenderView::OnFindReplyAck() {
861 // Check if there is any queued up request waiting to be sent.
862 if (queued_find_reply_message_.get()) {
863 // Send the search result over to the browser process.
864 Send(queued_find_reply_message_.get());
865 queued_find_reply_message_.release();
866 }
867}
868
869void RenderView::OnUpdateTargetURLAck() {
870 // Check if there is a targeturl waiting to be sent.
871 if (target_url_status_ == TARGET_PENDING) {
872 Send(new ViewHostMsg_UpdateTargetURL(routing_id_, page_id_,
873 pending_target_url_));
874 }
875
876 target_url_status_ = TARGET_NONE;
877}
878
879void RenderView::OnUndo() {
880 if (!webview())
881 return;
882
[email protected]26aa0482009-09-30 16:55:27883 webview()->focusedFrame()->executeCommand(WebString::fromUTF8("Undo"));
[email protected]afe3a1672009-11-17 19:04:12884 UserMetricsRecordAction("Undo");
initial.commit09911bf2008-07-26 23:55:29885}
886
887void RenderView::OnRedo() {
888 if (!webview())
889 return;
890
[email protected]26aa0482009-09-30 16:55:27891 webview()->focusedFrame()->executeCommand(WebString::fromUTF8("Redo"));
[email protected]afe3a1672009-11-17 19:04:12892 UserMetricsRecordAction("Redo");
initial.commit09911bf2008-07-26 23:55:29893}
894
895void RenderView::OnCut() {
896 if (!webview())
897 return;
898
[email protected]26aa0482009-09-30 16:55:27899 webview()->focusedFrame()->executeCommand(WebString::fromUTF8("Cut"));
[email protected]afe3a1672009-11-17 19:04:12900 UserMetricsRecordAction("Cut");
initial.commit09911bf2008-07-26 23:55:29901}
902
903void RenderView::OnCopy() {
904 if (!webview())
905 return;
906
[email protected]26aa0482009-09-30 16:55:27907 webview()->focusedFrame()->executeCommand(WebString::fromUTF8("Copy"));
[email protected]afe3a1672009-11-17 19:04:12908 UserMetricsRecordAction("Copy");
initial.commit09911bf2008-07-26 23:55:29909}
910
[email protected]c0cc3092009-09-12 08:27:27911#if defined(OS_MACOSX)
[email protected]a954bf72009-09-12 07:30:35912void RenderView::OnCopyToFindPboard() {
913 if (!webview())
914 return;
915
916 // Since the find pasteboard supports only plain text, this can be simpler
917 // than the |OnCopy()| case.
[email protected]26aa0482009-09-30 16:55:27918 WebFrame* frame = webview()->focusedFrame();
[email protected]a954bf72009-09-12 07:30:35919 if (frame->hasSelection()) {
920 string16 selection = frame->selectionAsText();
921 RenderThread::current()->Send(
922 new ViewHostMsg_ClipboardFindPboardWriteStringAsync(selection));
923 }
924
[email protected]afe3a1672009-11-17 19:04:12925 UserMetricsRecordAction("CopyToFindPboard");
[email protected]a954bf72009-09-12 07:30:35926}
[email protected]c0cc3092009-09-12 08:27:27927#endif
[email protected]a954bf72009-09-12 07:30:35928
initial.commit09911bf2008-07-26 23:55:29929void RenderView::OnPaste() {
930 if (!webview())
931 return;
932
[email protected]26aa0482009-09-30 16:55:27933 webview()->focusedFrame()->executeCommand(WebString::fromUTF8("Paste"));
[email protected]afe3a1672009-11-17 19:04:12934 UserMetricsRecordAction("Paste");
initial.commit09911bf2008-07-26 23:55:29935}
936
[email protected]2a3a7762009-10-19 19:17:32937void RenderView::OnReplace(const string16& text) {
initial.commit09911bf2008-07-26 23:55:29938 if (!webview())
939 return;
940
[email protected]2a3a7762009-10-19 19:17:32941 webview()->focusedFrame()->replaceSelection(text);
initial.commit09911bf2008-07-26 23:55:29942}
943
[email protected]98324892009-09-09 21:16:05944void RenderView::OnAdvanceToNextMisspelling() {
945 if (!webview())
946 return;
[email protected]26aa0482009-09-30 16:55:27947 webview()->focusedFrame()->executeCommand(
[email protected]98324892009-09-09 21:16:05948 WebString::fromUTF8("AdvanceToNextMisspelling"));
949}
950
951void RenderView::OnToggleSpellPanel(bool is_currently_visible) {
952 if (!webview())
953 return;
954 // We need to tell the webView whether the spelling panel is visible or not so
955 // that it won't need to make ipc calls later.
[email protected]8922e1f2009-10-03 05:01:26956 spelling_panel_visible_ = is_currently_visible;
[email protected]26aa0482009-09-30 16:55:27957 webview()->focusedFrame()->executeCommand(
[email protected]98324892009-09-09 21:16:05958 WebString::fromUTF8("ToggleSpellPanel"));
959}
960
[email protected]bbbd545c2008-12-15 20:18:04961void RenderView::OnToggleSpellCheck() {
962 if (!webview())
963 return;
964
[email protected]26aa0482009-09-30 16:55:27965 WebFrame* frame = webview()->focusedFrame();
[email protected]dd7daa82009-08-10 05:46:45966 frame->enableContinuousSpellChecking(
967 !frame->isContinuousSpellCheckingEnabled());
[email protected]bbbd545c2008-12-15 20:18:04968}
969
initial.commit09911bf2008-07-26 23:55:29970void RenderView::OnDelete() {
971 if (!webview())
972 return;
973
[email protected]26aa0482009-09-30 16:55:27974 webview()->focusedFrame()->executeCommand(WebString::fromUTF8("Delete"));
[email protected]afe3a1672009-11-17 19:04:12975 UserMetricsRecordAction("DeleteSelection");
initial.commit09911bf2008-07-26 23:55:29976}
977
978void RenderView::OnSelectAll() {
979 if (!webview())
980 return;
981
[email protected]26aa0482009-09-30 16:55:27982 webview()->focusedFrame()->executeCommand(
[email protected]a100d76bb2009-08-14 17:50:22983 WebString::fromUTF8("SelectAll"));
[email protected]afe3a1672009-11-17 19:04:12984 UserMetricsRecordAction("SelectAll");
initial.commit09911bf2008-07-26 23:55:29985}
986
987void RenderView::OnSetInitialFocus(bool reverse) {
988 if (!webview())
989 return;
[email protected]26aa0482009-09-30 16:55:27990 webview()->setInitialFocus(reverse);
initial.commit09911bf2008-07-26 23:55:29991}
992
993///////////////////////////////////////////////////////////////////////////////
994
995// Tell the embedding application that the URL of the active page has changed
996void RenderView::UpdateURL(WebFrame* frame) {
[email protected]dd7daa82009-08-10 05:46:45997 WebDataSource* ds = frame->dataSource();
initial.commit09911bf2008-07-26 23:55:29998 DCHECK(ds);
999
[email protected]726985e22009-06-18 21:09:281000 const WebURLRequest& request = ds->request();
1001 const WebURLRequest& original_request = ds->originalRequest();
1002 const WebURLResponse& response = ds->response();
initial.commit09911bf2008-07-26 23:55:291003
[email protected]daa8c58e2009-06-15 17:21:101004 NavigationState* navigation_state = NavigationState::FromDataSource(ds);
1005 DCHECK(navigation_state);
initial.commit09911bf2008-07-26 23:55:291006
1007 ViewHostMsg_FrameNavigate_Params params;
[email protected]726985e22009-06-18 21:09:281008 params.http_status_code = response.httpStatusCode();
initial.commit09911bf2008-07-26 23:55:291009 params.is_post = false;
1010 params.page_id = page_id_;
[email protected]726985e22009-06-18 21:09:281011 params.is_content_filtered = response.isContentFiltered();
[email protected]e6f546c32009-07-01 17:12:551012 if (!navigation_state->security_info().empty()) {
initial.commit09911bf2008-07-26 23:55:291013 // SSL state specified in the request takes precedence over the one in the
1014 // response.
1015 // So far this is only intended for error pages that are not expected to be
1016 // over ssl, so we should not get any clash.
[email protected]726985e22009-06-18 21:09:281017 DCHECK(response.securityInfo().isEmpty());
[email protected]e6f546c32009-07-01 17:12:551018 params.security_info = navigation_state->security_info();
initial.commit09911bf2008-07-26 23:55:291019 } else {
[email protected]726985e22009-06-18 21:09:281020 params.security_info = response.securityInfo();
initial.commit09911bf2008-07-26 23:55:291021 }
1022
1023 // Set the URL to be displayed in the browser UI to the user.
[email protected]726985e22009-06-18 21:09:281024 if (ds->hasUnreachableURL()) {
1025 params.url = ds->unreachableURL();
initial.commit09911bf2008-07-26 23:55:291026 } else {
[email protected]726985e22009-06-18 21:09:281027 params.url = request.url();
initial.commit09911bf2008-07-26 23:55:291028 }
1029
[email protected]726985e22009-06-18 21:09:281030 GetRedirectChain(ds, &params.redirects);
1031 params.should_update_history = !ds->hasUnreachableURL();
initial.commit09911bf2008-07-26 23:55:291032
[email protected]ce0e250d2009-10-23 21:00:351033 params.searchable_form_url = navigation_state->searchable_form_url();
1034 params.searchable_form_encoding =
1035 navigation_state->searchable_form_encoding();
initial.commit09911bf2008-07-26 23:55:291036
1037 const PasswordForm* password_form_data =
[email protected]daa8c58e2009-06-15 17:21:101038 navigation_state->password_form_data();
initial.commit09911bf2008-07-26 23:55:291039 if (password_form_data)
1040 params.password_form = *password_form_data;
1041
1042 params.gesture = navigation_gesture_;
1043 navigation_gesture_ = NavigationGestureUnknown;
1044
[email protected]dd7daa82009-08-10 05:46:451045 if (!frame->parent()) {
initial.commit09911bf2008-07-26 23:55:291046 // Top-level navigation.
1047
1048 // Update contents MIME type for main frame.
[email protected]9c5645b2009-08-11 03:37:551049 params.contents_mime_type = ds->response().mimeType().utf8();
initial.commit09911bf2008-07-26 23:55:291050
[email protected]daa8c58e2009-06-15 17:21:101051 params.transition = navigation_state->transition_type();
initial.commit09911bf2008-07-26 23:55:291052 if (!PageTransition::IsMainFrame(params.transition)) {
1053 // If the main frame does a load, it should not be reported as a subframe
1054 // navigation. This can occur in the following case:
1055 // 1. You're on a site with frames.
1056 // 2. You do a subframe navigation. This is stored with transition type
1057 // MANUAL_SUBFRAME.
1058 // 3. You navigate to some non-frame site, say, google.com.
1059 // 4. You navigate back to the page from step 2. Since it was initially
1060 // MANUAL_SUBFRAME, it will be that same transition type here.
1061 // We don't want that, because any navigation that changes the toplevel
1062 // frame should be tracked as a toplevel navigation (this allows us to
1063 // update the URL bar, etc).
1064 params.transition = PageTransition::LINK;
1065 }
1066
initial.commit09911bf2008-07-26 23:55:291067 // If we have a valid consumed client redirect source,
1068 // the page contained a client redirect (meta refresh, document.loc...),
1069 // so we set the referrer and transition to match.
1070 if (completed_client_redirect_src_.is_valid()) {
[email protected]77e09a92008-08-01 18:11:041071 DCHECK(completed_client_redirect_src_ == params.redirects[0]);
initial.commit09911bf2008-07-26 23:55:291072 params.referrer = completed_client_redirect_src_;
1073 params.transition = static_cast<PageTransition::Type>(
1074 params.transition | PageTransition::CLIENT_REDIRECT);
1075 } else {
1076 // Bug 654101: the referrer will be empty on https->http transitions. It
1077 // would be nice if we could get the real referrer from somewhere.
[email protected]726985e22009-06-18 21:09:281078 params.referrer = GURL(
1079 original_request.httpHeaderField(WebString::fromUTF8("Referer")));
initial.commit09911bf2008-07-26 23:55:291080 }
1081
[email protected]726985e22009-06-18 21:09:281082 string16 method = request.httpMethod();
1083 if (EqualsASCII(method, "POST"))
initial.commit09911bf2008-07-26 23:55:291084 params.is_post = true;
1085
[email protected]c2a797d2009-09-21 16:46:321086 // Save some histogram data so we can compute the average memory used per
1087 // page load of the glyphs.
1088 UMA_HISTOGRAM_COUNTS_10000("Memory.GlyphPagesPerLoad",
1089 webkit_glue::GetGlyphPageCount());
1090
initial.commit09911bf2008-07-26 23:55:291091 Send(new ViewHostMsg_FrameNavigate(routing_id_, params));
1092 } else {
1093 // Subframe navigation: the type depends on whether this navigation
1094 // generated a new session history entry. When they do generate a session
1095 // history entry, it means the user initiated the navigation and we should
1096 // mark it as such. This test checks if this is the first time UpdateURL
1097 // has been called since WillNavigateToURL was called to initiate the load.
1098 if (page_id_ > last_page_id_sent_to_browser_)
1099 params.transition = PageTransition::MANUAL_SUBFRAME;
1100 else
1101 params.transition = PageTransition::AUTO_SUBFRAME;
1102
initial.commit09911bf2008-07-26 23:55:291103 Send(new ViewHostMsg_FrameNavigate(routing_id_, params));
1104 }
1105
1106 last_page_id_sent_to_browser_ =
1107 std::max(last_page_id_sent_to_browser_, page_id_);
1108
1109 // If we end up reusing this WebRequest (for example, due to a #ref click),
[email protected]daa8c58e2009-06-15 17:21:101110 // we don't want the transition type to persist. Just clear it.
1111 navigation_state->set_transition_type(PageTransition::LINK);
[email protected]266eb6f2008-09-30 23:56:501112
[email protected]6c8afae52009-01-22 02:24:571113#if defined(OS_WIN)
[email protected]c7287a92009-11-04 20:06:151114 if (accessibility_.get()) {
[email protected]be645db2009-02-06 20:36:331115 // Clear accessibility info cache.
[email protected]c7287a92009-11-04 20:06:151116 accessibility_->clear();
[email protected]266eb6f2008-09-30 23:56:501117 }
[email protected]6c8afae52009-01-22 02:24:571118#else
[email protected]7d926f92009-03-03 14:26:541119 // TODO(port): accessibility not yet implemented. See http://crbug.com/8288.
[email protected]6c8afae52009-01-22 02:24:571120#endif
initial.commit09911bf2008-07-26 23:55:291121}
1122
1123// Tell the embedding application that the title of the active page has changed
[email protected]3d9689372009-09-10 04:29:171124void RenderView::UpdateTitle(WebFrame* frame, const string16& title) {
initial.commit09911bf2008-07-26 23:55:291125 // Ignore all but top level navigations...
[email protected]3d9689372009-09-10 04:29:171126 if (!frame->parent()) {
[email protected]f0af6a72009-05-30 05:25:171127 Send(new ViewHostMsg_UpdateTitle(
[email protected]3d9689372009-09-10 04:29:171128 routing_id_,
1129 page_id_,
1130 UTF16ToWideHack(title.length() > chrome::kMaxTitleChars ?
1131 title.substr(0, chrome::kMaxTitleChars) : title)));
[email protected]f0af6a72009-05-30 05:25:171132 }
initial.commit09911bf2008-07-26 23:55:291133}
1134
1135void RenderView::UpdateEncoding(WebFrame* frame,
[email protected]41fc0322009-09-04 22:23:401136 const std::string& encoding_name) {
initial.commit09911bf2008-07-26 23:55:291137 // Only update main frame's encoding_name.
[email protected]26aa0482009-09-30 16:55:271138 if (webview()->mainFrame() == frame &&
initial.commit09911bf2008-07-26 23:55:291139 last_encoding_name_ != encoding_name) {
[email protected]e38f40152008-09-12 23:08:301140 // Save the encoding name for later comparing.
initial.commit09911bf2008-07-26 23:55:291141 last_encoding_name_ = encoding_name;
1142
[email protected]e38f40152008-09-12 23:08:301143 Send(new ViewHostMsg_UpdateEncoding(routing_id_, last_encoding_name_));
initial.commit09911bf2008-07-26 23:55:291144 }
1145}
1146
[email protected]f4d34b52008-11-24 23:05:011147// Sends the previous session history state to the browser so it will be saved
1148// before we navigate to a new page. This must be called *before* the page ID
1149// has been updated so we know what it was.
initial.commit09911bf2008-07-26 23:55:291150void RenderView::UpdateSessionHistory(WebFrame* frame) {
1151 // If we have a valid page ID at this point, then it corresponds to the page
1152 // we are navigating away from. Otherwise, this is the first navigation, so
1153 // there is no past session history to record.
1154 if (page_id_ == -1)
1155 return;
1156
[email protected]ca948a22009-06-25 19:36:171157 const WebHistoryItem& item =
[email protected]26aa0482009-09-30 16:55:271158 webview()->mainFrame()->previousHistoryItem();
[email protected]ca948a22009-06-25 19:36:171159 if (item.isNull())
initial.commit09911bf2008-07-26 23:55:291160 return;
[email protected]ca948a22009-06-25 19:36:171161
1162 Send(new ViewHostMsg_UpdateState(
1163 routing_id_, page_id_, webkit_glue::HistoryItemToString(item)));
initial.commit09911bf2008-07-26 23:55:291164}
1165
[email protected]3d9689372009-09-10 04:29:171166void RenderView::OpenURL(
1167 const GURL& url, const GURL& referrer, WebNavigationPolicy policy) {
1168 Send(new ViewHostMsg_OpenURL(
1169 routing_id_, url, referrer, NavigationPolicyToDisposition(policy)));
1170}
1171
[email protected]79dbc662009-09-04 05:42:511172// WebViewDelegate ------------------------------------------------------------
initial.commit09911bf2008-07-26 23:55:291173
[email protected]a2f6bc112009-06-27 16:27:251174void RenderView::DidPaint() {
[email protected]26aa0482009-09-30 16:55:271175 WebFrame* main_frame = webview()->mainFrame();
[email protected]a2f6bc112009-06-27 16:27:251176
[email protected]dd7daa82009-08-10 05:46:451177 if (main_frame->provisionalDataSource()) {
[email protected]a2f6bc112009-06-27 16:27:251178 // If we have a provisional frame we are between the start
1179 // and commit stages of loading...ignore this paint.
1180 return;
1181 }
1182
[email protected]dd7daa82009-08-10 05:46:451183 WebDataSource* ds = main_frame->dataSource();
[email protected]a2f6bc112009-06-27 16:27:251184 NavigationState* navigation_state = NavigationState::FromDataSource(ds);
[email protected]78a3a6f2009-07-02 16:15:011185 DCHECK(navigation_state);
1186
1187 Time now = Time::Now();
1188 if (navigation_state->first_paint_time().is_null()) {
1189 navigation_state->set_first_paint_time(now);
1190 }
1191 if (navigation_state->first_paint_after_load_time().is_null() &&
1192 !navigation_state->finish_load_time().is_null()) {
1193 navigation_state->set_first_paint_after_load_time(now);
[email protected]a2f6bc112009-06-27 16:27:251194 }
1195}
1196
initial.commit09911bf2008-07-26 23:55:291197void RenderView::LoadNavigationErrorPage(WebFrame* frame,
[email protected]726985e22009-06-18 21:09:281198 const WebURLRequest& failed_request,
1199 const WebURLError& error,
initial.commit09911bf2008-07-26 23:55:291200 const std::string& html,
1201 bool replace) {
[email protected]726985e22009-06-18 21:09:281202 GURL failed_url = error.unreachableURL;
initial.commit09911bf2008-07-26 23:55:291203
1204 std::string alt_html;
1205 if (html.empty()) {
1206 // Use a local error page.
1207 int resource_id;
1208 DictionaryValue error_strings;
[email protected]726985e22009-06-18 21:09:281209 if (error.reason == net::ERR_CACHE_MISS &&
1210 EqualsASCII(failed_request.httpMethod(), "POST")) {
initial.commit09911bf2008-07-26 23:55:291211 GetFormRepostErrorValues(failed_url, &error_strings);
1212 resource_id = IDR_ERROR_NO_DETAILS_HTML;
1213 } else {
1214 GetLocalizedErrorValues(error, &error_strings);
1215 resource_id = IDR_NET_ERROR_HTML;
1216 }
[email protected]8e50b602009-03-03 22:59:431217 error_strings.SetString(L"textdirection",
1218 (l10n_util::GetTextDirection() == l10n_util::RIGHT_TO_LEFT) ?
1219 L"rtl" : L"ltr");
initial.commit09911bf2008-07-26 23:55:291220
1221 alt_html = GetAltHTMLForTemplate(error_strings, resource_id);
1222 } else {
1223 alt_html = html;
1224 }
1225
[email protected]dd7daa82009-08-10 05:46:451226 frame->loadHTMLString(alt_html,
[email protected]e6f546c32009-07-01 17:12:551227 GURL(kUnreachableWebDataURL),
1228 failed_url,
1229 replace);
initial.commit09911bf2008-07-26 23:55:291230}
1231
[email protected]7ccddb8c2009-08-04 17:36:551232void RenderView::BindDOMAutomationController(WebFrame* frame) {
initial.commit09911bf2008-07-26 23:55:291233 dom_automation_controller_.set_message_sender(this);
1234 dom_automation_controller_.set_routing_id(routing_id_);
[email protected]7ccddb8c2009-08-04 17:36:551235 dom_automation_controller_.BindToJavascript(frame,
initial.commit09911bf2008-07-26 23:55:291236 L"domAutomationController");
1237}
1238
initial.commit09911bf2008-07-26 23:55:291239bool RenderView::RunJavaScriptMessage(int type,
1240 const std::wstring& message,
1241 const std::wstring& default_value,
[email protected]a455d3812009-03-05 20:18:071242 const GURL& frame_url,
initial.commit09911bf2008-07-26 23:55:291243 std::wstring* result) {
1244 bool success = false;
1245 std::wstring result_temp;
1246 if (!result)
1247 result = &result_temp;
initial.commit09911bf2008-07-26 23:55:291248
[email protected]12636df2009-09-28 22:32:211249 SendAndRunNestedMessageLoop(new ViewHostMsg_RunJavaScriptMessage(
1250 routing_id_, message, default_value, frame_url, type, &success, result));
initial.commit09911bf2008-07-26 23:55:291251 return success;
1252}
1253
1254void RenderView::AddGURLSearchProvider(const GURL& osd_url, bool autodetected) {
1255 if (!osd_url.is_empty())
1256 Send(new ViewHostMsg_PageHasOSDD(routing_id_, page_id_, osd_url,
1257 autodetected));
1258}
1259
[email protected]842936a2009-10-14 06:00:361260void RenderView::OnQueryFormFieldAutofillAck(
[email protected]acca2a1f2009-10-16 03:53:391261 int query_id,
1262 const std::vector<string16>& suggestions,
[email protected]0ebf3872008-11-07 21:35:031263 int default_suggestion_index) {
[email protected]7e089f272009-11-03 17:07:181264 if (webview() && query_id == autofill_query_id_) {
[email protected]acca2a1f2009-10-16 03:53:391265 webview()->applyAutofillSuggestions(
1266 autofill_query_node_, suggestions, default_suggestion_index);
1267 }
1268 autofill_query_node_.reset();
[email protected]0ebf3872008-11-07 21:35:031269}
1270
[email protected]2c4410d2009-05-06 23:46:221271void RenderView::OnPopupNotificationVisibilityChanged(bool visible) {
[email protected]634a6f92008-12-01 21:39:311272 popup_notification_visible_ = visible;
1273}
1274
initial.commit09911bf2008-07-26 23:55:291275uint32 RenderView::GetCPBrowsingContext() {
1276 uint32 context = 0;
1277 Send(new ViewHostMsg_GetCPBrowsingContext(&context));
1278 return context;
1279}
1280
initial.commit09911bf2008-07-26 23:55:291281void RenderView::AddSearchProvider(const std::string& url) {
1282 AddGURLSearchProvider(GURL(url),
1283 false); // not autodetected
1284}
1285
[email protected]f103ab72009-09-02 17:10:591286void RenderView::OnMissingPluginStatus(
1287 WebPluginDelegateProxy* delegate,
1288 int status) {
[email protected]6c8afae52009-01-22 02:24:571289#if defined(OS_WIN)
[email protected]f103ab72009-09-02 17:10:591290 if (!first_default_plugin_) {
initial.commit09911bf2008-07-26 23:55:291291 // Show the InfoBar for the first available plugin.
1292 if (status == default_plugin::MISSING_PLUGIN_AVAILABLE) {
[email protected]f103ab72009-09-02 17:10:591293 first_default_plugin_ = delegate->AsWeakPtr();
initial.commit09911bf2008-07-26 23:55:291294 Send(new ViewHostMsg_MissingPluginStatus(routing_id_, status));
1295 }
1296 } else {
1297 // Closes the InfoBar if user clicks on the plugin (instead of the InfoBar)
1298 // to start the download/install.
1299 if (status == default_plugin::MISSING_PLUGIN_USER_STARTED_DOWNLOAD) {
1300 Send(new ViewHostMsg_MissingPluginStatus(routing_id_, status));
1301 }
1302 }
[email protected]6c8afae52009-01-22 02:24:571303#else
1304 // TODO(port): plugins current not supported
1305 NOTIMPLEMENTED();
1306#endif
initial.commit09911bf2008-07-26 23:55:291307}
1308
[email protected]48c9cf2d2009-09-16 16:47:521309// WebKit::WebViewClient ------------------------------------------------------
1310
1311WebView* RenderView::createView(WebFrame* creator) {
1312 // Check to make sure we aren't overloading on popups.
1313 if (shared_popup_counter_->data > kMaximumNumberOfUnacknowledgedPopups)
1314 return NULL;
1315
1316 // This window can't be closed from a window.close() call until we receive a
1317 // message from the Browser process explicitly allowing it.
1318 popup_notification_visible_ = true;
1319
1320 int32 routing_id = MSG_ROUTING_NONE;
1321 bool user_gesture = creator->isProcessingUserGesture();
[email protected]007a848b2009-10-26 15:55:461322 bool opener_suppressed = creator->willSuppressOpenerInNewFrame();
[email protected]48c9cf2d2009-09-16 16:47:521323
[email protected]48c9cf2d2009-09-16 16:47:521324 render_thread_->Send(
[email protected]12636df2009-09-28 22:32:211325 new ViewHostMsg_CreateWindow(routing_id_, user_gesture, &routing_id));
1326 if (routing_id == MSG_ROUTING_NONE)
[email protected]48c9cf2d2009-09-16 16:47:521327 return NULL;
[email protected]48c9cf2d2009-09-16 16:47:521328
[email protected]48c9cf2d2009-09-16 16:47:521329 RenderView* view = RenderView::Create(render_thread_,
[email protected]659f73fa2009-10-13 13:43:421330 0,
[email protected]12636df2009-09-28 22:32:211331 routing_id_,
[email protected]48c9cf2d2009-09-16 16:47:521332 renderer_preferences_,
1333 webkit_preferences_,
[email protected]12636df2009-09-28 22:32:211334 shared_popup_counter_,
1335 routing_id);
[email protected]48c9cf2d2009-09-16 16:47:521336 view->opened_by_user_gesture_ = user_gesture;
1337
[email protected]007a848b2009-10-26 15:55:461338 // Record whether the creator frame is trying to suppress the opener field.
1339 view->opener_suppressed_ = opener_suppressed;
1340
[email protected]48c9cf2d2009-09-16 16:47:521341 // Record the security origin of the creator.
[email protected]91733b62009-09-18 06:21:091342 GURL creator_url(creator->securityOrigin().toString().utf8());
[email protected]48c9cf2d2009-09-16 16:47:521343 if (!creator_url.is_valid() || !creator_url.IsStandard())
1344 creator_url = GURL();
1345 view->creator_url_ = creator_url;
1346
1347 // Copy over the alternate error page URL so we can have alt error pages in
1348 // the new render view (we don't need the browser to send the URL back down).
1349 view->alternate_error_page_url_ = alternate_error_page_url_;
1350
1351 return view->webview();
1352}
1353
1354WebWidget* RenderView::createPopupMenu(bool activatable) {
1355 RenderWidget* widget = RenderWidget::Create(routing_id_,
1356 render_thread_,
1357 activatable);
1358 return widget->webwidget();
1359}
1360
1361WebWidget* RenderView::createPopupMenu(const WebPopupMenuInfo& info) {
1362 RenderWidget* widget = RenderWidget::Create(routing_id_,
1363 render_thread_,
1364 true);
1365 widget->ConfigureAsExternalPopupMenu(info);
1366 return widget->webwidget();
1367}
1368
1369void RenderView::didAddMessageToConsole(
1370 const WebConsoleMessage& message, const WebString& source_name,
1371 unsigned source_line) {
1372 Send(new ViewHostMsg_AddMessageToConsole(routing_id_,
1373 UTF16ToWideHack(message.text),
1374 static_cast<int32>(source_line),
1375 UTF16ToWideHack(source_name)));
1376}
1377
1378void RenderView::printPage(WebFrame* frame) {
[email protected]71a14262009-09-22 20:02:581379 DCHECK(frame);
1380 Print(frame, true);
[email protected]48c9cf2d2009-09-16 16:47:521381}
1382
1383void RenderView::didStartLoading() {
1384 if (is_loading_) {
1385 DLOG(WARNING) << "didStartLoading called while loading";
1386 return;
1387 }
1388
1389 is_loading_ = true;
1390 // Clear the pointer so that we can assign it only when there is an unknown
1391 // plugin on a page.
1392 first_default_plugin_.reset();
1393
1394 Send(new ViewHostMsg_DidStartLoading(routing_id_));
1395}
1396
1397void RenderView::didStopLoading() {
1398 if (!is_loading_) {
1399 DLOG(WARNING) << "DidStopLoading called while not loading";
1400 return;
1401 }
1402
1403 is_loading_ = false;
1404
1405 // NOTE: For now we're doing the safest thing, and sending out notification
1406 // when done loading. This currently isn't an issue as the favicon is only
1407 // displayed when done loading. Ideally we would send notification when
1408 // finished parsing the head, but webkit doesn't support that yet.
1409 // The feed discovery code would also benefit from access to the head.
[email protected]26aa0482009-09-30 16:55:271410 GURL favicon_url(webview()->mainFrame()->favIconURL());
[email protected]48c9cf2d2009-09-16 16:47:521411 if (!favicon_url.is_empty())
1412 Send(new ViewHostMsg_UpdateFavIconURL(routing_id_, page_id_, favicon_url));
1413
[email protected]26aa0482009-09-30 16:55:271414 AddGURLSearchProvider(webview()->mainFrame()->openSearchDescriptionURL(),
[email protected]48c9cf2d2009-09-16 16:47:521415 true); // autodetected
1416
1417 Send(new ViewHostMsg_DidStopLoading(routing_id_));
1418
1419 MessageLoop::current()->PostDelayedTask(FROM_HERE,
1420 method_factory_.NewRunnableMethod(&RenderView::CapturePageInfo, page_id_,
1421 false),
1422 kDelayForCaptureMs);
[email protected]48c9cf2d2009-09-16 16:47:521423}
1424
[email protected]04fc9482009-09-18 22:13:031425bool RenderView::isSelectTrailingWhitespaceEnabled() {
1426#if defined(OS_WIN)
1427 return true;
1428#else
1429 return false;
1430#endif
1431}
1432
1433void RenderView::setInputMethodEnabled(bool enabled) {
1434 // Save the updated IME status and mark the input focus has been updated.
1435 // The IME status is to be sent to a browser process next time when
1436 // the input caret is rendered.
1437 if (!ime_control_busy_) {
1438 ime_control_updated_ = true;
1439 ime_control_new_state_ = enabled;
1440 }
1441}
1442
1443void RenderView::didChangeSelection(bool is_empty_selection) {
1444#if defined(OS_LINUX)
1445 if (!handling_input_event_)
1446 return;
1447 // TODO(estade): investigate incremental updates to the selection so that we
1448 // don't send the entire selection over IPC every time.
1449 if (!is_empty_selection) {
1450 // Sometimes we get repeated didChangeSelection calls from webkit when
1451 // the selection hasn't actually changed. We don't want to report these
1452 // because it will cause us to continually claim the X clipboard.
1453 const std::string& this_selection =
[email protected]26aa0482009-09-30 16:55:271454 webview()->focusedFrame()->selectionAsText().utf8();
[email protected]04fc9482009-09-18 22:13:031455 if (this_selection == last_selection_)
1456 return;
1457
1458 Send(new ViewHostMsg_SelectionChanged(routing_id_,
1459 this_selection));
1460 last_selection_ = this_selection;
1461 } else {
1462 last_selection_.clear();
1463 }
1464#endif
1465}
1466
1467void RenderView::didExecuteCommand(const WebString& command_name) {
[email protected]afe3a1672009-11-17 19:04:121468 const std::string& name = UTF16ToUTF8(command_name);
1469 if (StartsWithASCII(name, "Move", true) ||
1470 StartsWithASCII(name, "Insert", true) ||
1471 StartsWithASCII(name, "Delete", true))
[email protected]04fc9482009-09-18 22:13:031472 return;
1473 UserMetricsRecordAction(name);
1474}
1475
[email protected]b2528b72009-09-24 06:57:101476bool RenderView::handleCurrentKeyboardEvent() {
1477 if (edit_commands_.empty())
1478 return false;
1479
[email protected]26aa0482009-09-30 16:55:271480 WebFrame* frame = webview()->focusedFrame();
[email protected]b2528b72009-09-24 06:57:101481 if (!frame)
1482 return false;
1483
1484 EditCommands::iterator it = edit_commands_.begin();
1485 EditCommands::iterator end = edit_commands_.end();
1486
[email protected]507b33ea2009-09-29 03:56:511487 bool did_execute_command = false;
[email protected]b2528b72009-09-24 06:57:101488 for (; it != end; ++it) {
[email protected]e6e15012009-09-30 14:59:331489 // In gtk and cocoa, it's possible to bind multiple edit commands to one
1490 // key (but it's the exception). Once one edit command is not executed, it
1491 // seems safest to not execute the rest.
[email protected]b2528b72009-09-24 06:57:101492 if (!frame->executeCommand(WebString::fromUTF8(it->name),
1493 WebString::fromUTF8(it->value)))
1494 break;
[email protected]507b33ea2009-09-29 03:56:511495 did_execute_command = true;
[email protected]b2528b72009-09-24 06:57:101496 }
1497
[email protected]507b33ea2009-09-29 03:56:511498 return did_execute_command;
[email protected]b2528b72009-09-24 06:57:101499}
1500
[email protected]2a3a7762009-10-19 19:17:321501void RenderView::spellCheck(const WebString& text,
1502 int& misspelled_offset,
1503 int& misspelled_length) {
[email protected]1dbafaf72009-09-23 19:43:561504 EnsureDocumentTag();
[email protected]85c55dc2009-11-06 03:05:461505
1506#if defined(SPELLCHECKER_IN_RENDERER)
1507 string16 word(text);
[email protected]cb6037d2009-11-16 22:55:171508 RenderThread* thread = RenderThread::current();
1509 // Will be NULL during unit tests.
1510 if (thread) {
1511 RenderThread::current()->spellchecker()->SpellCheckWord(
1512 word.c_str(), word.size(), document_tag_,
1513 &misspelled_offset, &misspelled_length, NULL);
1514 }
[email protected]85c55dc2009-11-06 03:05:461515#else
[email protected]2a3a7762009-10-19 19:17:321516 Send(new ViewHostMsg_SpellCheck(routing_id_, text, document_tag_,
1517 &misspelled_offset, &misspelled_length));
[email protected]85c55dc2009-11-06 03:05:461518#endif
[email protected]1dbafaf72009-09-23 19:43:561519}
1520
1521WebString RenderView::autoCorrectWord(const WebKit::WebString& word) {
[email protected]2a3a7762009-10-19 19:17:321522 string16 autocorrect_word;
[email protected]1dbafaf72009-09-23 19:43:561523 const CommandLine& command_line = *CommandLine::ForCurrentProcess();
[email protected]b86c8c12009-10-05 22:01:261524 if (command_line.HasSwitch(switches::kExperimentalSpellcheckerFeatures)) {
[email protected]1dbafaf72009-09-23 19:43:561525 EnsureDocumentTag();
[email protected]85c55dc2009-11-06 03:05:461526#if defined(SPELLCHECKER_IN_RENDERER)
[email protected]cb6037d2009-11-16 22:55:171527 RenderThread* thread = RenderThread::current();
1528 // Will be NULL during unit tests.
1529 if (thread) {
1530 autocorrect_word =
1531 RenderThread::current()->spellchecker()->GetAutoCorrectionWord(
1532 word, document_tag_);
1533 }
[email protected]85c55dc2009-11-06 03:05:461534#else
[email protected]1dbafaf72009-09-23 19:43:561535 Send(new ViewHostMsg_GetAutoCorrectWord(
[email protected]2a3a7762009-10-19 19:17:321536 routing_id_, word, document_tag_, &autocorrect_word));
[email protected]85c55dc2009-11-06 03:05:461537#endif
[email protected]1dbafaf72009-09-23 19:43:561538 }
[email protected]2a3a7762009-10-19 19:17:321539 return autocorrect_word;
[email protected]1dbafaf72009-09-23 19:43:561540}
1541
[email protected]c49085c72009-10-02 16:28:561542void RenderView::showSpellingUI(bool show) {
1543 Send(new ViewHostMsg_ShowSpellingPanel(routing_id_, show));
1544}
1545
[email protected]8922e1f2009-10-03 05:01:261546bool RenderView::isShowingSpellingUI() {
1547 return spelling_panel_visible_;
1548}
1549
[email protected]1dbafaf72009-09-23 19:43:561550void RenderView::updateSpellingUIWithMisspelledWord(const WebString& word) {
[email protected]2a3a7762009-10-19 19:17:321551 Send(new ViewHostMsg_UpdateSpellingPanelWithMisspelledWord(routing_id_,
1552 word));
[email protected]1dbafaf72009-09-23 19:43:561553}
1554
[email protected]a1128322009-10-06 18:38:461555bool RenderView::runFileChooser(
1556 bool multi_select,
1557 const WebKit::WebString& title,
1558 const WebKit::WebString& initial_value,
1559 WebKit::WebFileChooserCompletion* chooser_completion) {
1560 if (file_chooser_completion_) {
1561 // TODO(brettw): bug 1235154: This should be a synchronous message to deal
1562 // with the fact that web pages can programatically trigger this. With the
1563 // asnychronous messages, we can get an additional call when one is pending,
1564 // which this test is for. For now, we just ignore the additional file
1565 // chooser request. WebKit doesn't do anything to expect the callback, so
1566 // we can just ignore calling it.
1567 return false;
1568 }
1569 file_chooser_completion_ = chooser_completion;
1570 Send(new ViewHostMsg_RunFileChooser(
1571 routing_id_, multi_select, title,
1572 webkit_glue::WebStringToFilePath(initial_value)));
1573 return true;
1574}
1575
[email protected]48c9cf2d2009-09-16 16:47:521576void RenderView::runModalAlertDialog(
1577 WebFrame* frame, const WebString& message) {
1578 RunJavaScriptMessage(MessageBoxFlags::kIsJavascriptAlert,
1579 UTF16ToWideHack(message),
1580 std::wstring(),
1581 frame->url(),
1582 NULL);
1583}
1584
1585bool RenderView::runModalConfirmDialog(
1586 WebFrame* frame, const WebString& message) {
1587 return RunJavaScriptMessage(MessageBoxFlags::kIsJavascriptConfirm,
1588 UTF16ToWideHack(message),
1589 std::wstring(),
1590 frame->url(),
1591 NULL);
1592}
1593
1594bool RenderView::runModalPromptDialog(
1595 WebFrame* frame, const WebString& message, const WebString& default_value,
1596 WebString* actual_value) {
1597 std::wstring result;
1598 bool ok = RunJavaScriptMessage(MessageBoxFlags::kIsJavascriptPrompt,
1599 UTF16ToWideHack(message),
1600 UTF16ToWideHack(default_value),
1601 frame->url(),
1602 &result);
1603 if (ok)
1604 actual_value->assign(WideToUTF16Hack(result));
1605 return ok;
1606}
1607
1608bool RenderView::runModalBeforeUnloadDialog(
1609 WebFrame* frame, const WebString& message) {
1610 bool success = false;
1611 // This is an ignored return value, but is included so we can accept the same
1612 // response as RunJavaScriptMessage.
1613 std::wstring ignored_result;
[email protected]12636df2009-09-28 22:32:211614 SendAndRunNestedMessageLoop(new ViewHostMsg_RunBeforeUnloadConfirm(
[email protected]48c9cf2d2009-09-16 16:47:521615 routing_id_, frame->url(), UTF16ToWideHack(message), &success,
[email protected]12636df2009-09-28 22:32:211616 &ignored_result));
[email protected]48c9cf2d2009-09-16 16:47:521617 return success;
1618}
1619
[email protected]79e37442009-10-09 18:17:441620void RenderView::showContextMenu(
1621 WebFrame* frame, const WebContextMenuData& data) {
1622 Send(new ViewHostMsg_ContextMenu(routing_id_, ContextMenuParams(data)));
1623}
1624
[email protected]48c9cf2d2009-09-16 16:47:521625void RenderView::setStatusText(const WebString& text) {
1626}
1627
[email protected]163f8242009-10-30 20:19:551628void RenderView::UpdateTargetURL(const GURL& url, const GURL& fallback_url) {
1629 GURL latest_url = url.spec().empty() ? fallback_url : url;
[email protected]48c9cf2d2009-09-16 16:47:521630 if (latest_url == target_url_)
1631 return;
[email protected]163f8242009-10-30 20:19:551632
[email protected]48c9cf2d2009-09-16 16:47:521633 // Tell the browser to display a destination link.
1634 if (target_url_status_ == TARGET_INFLIGHT ||
1635 target_url_status_ == TARGET_PENDING) {
1636 // If we have a request in-flight, save the URL to be sent when we
1637 // receive an ACK to the in-flight request. We can happily overwrite
1638 // any existing pending sends.
1639 pending_target_url_ = latest_url;
1640 target_url_status_ = TARGET_PENDING;
1641 } else {
1642 Send(new ViewHostMsg_UpdateTargetURL(routing_id_, page_id_, latest_url));
1643 target_url_ = latest_url;
1644 target_url_status_ = TARGET_INFLIGHT;
1645 }
1646}
1647
[email protected]882daa92009-11-05 16:31:311648void RenderView::StartNavStateSyncTimerIfNecessary() {
1649 int delay;
1650 if (send_content_state_immediately_)
1651 delay = 0;
1652 else if (is_hidden())
1653 delay = kDelaySecondsForContentStateSyncHidden;
1654 else
1655 delay = kDelaySecondsForContentStateSync;
1656
1657 if (nav_state_sync_timer_.IsRunning()) {
1658 // The timer is already running. If the delay of the timer maches the amount
1659 // we want to delay by, then return. Otherwise stop the timer so that it
1660 // gets started with the right delay.
1661 if (nav_state_sync_timer_.GetCurrentDelay().InSeconds() == delay)
1662 return;
1663 nav_state_sync_timer_.Stop();
1664 }
1665
1666 nav_state_sync_timer_.Start(
1667 TimeDelta::FromSeconds(delay), this, &RenderView::SyncNavigationState);
1668}
1669
[email protected]163f8242009-10-30 20:19:551670void RenderView::setMouseOverURL(const WebURL& url) {
1671 mouse_over_url_ = GURL(url);
1672 UpdateTargetURL(mouse_over_url_, focus_url_);
1673}
1674
1675void RenderView::setKeyboardFocusURL(const WebURL& url) {
1676 focus_url_ = GURL(url);
1677 UpdateTargetURL(focus_url_, mouse_over_url_);
1678}
1679
[email protected]48c9cf2d2009-09-16 16:47:521680void RenderView::setToolTipText(const WebString& text, WebTextDirection hint) {
1681 Send(new ViewHostMsg_SetTooltipText(routing_id_, UTF16ToWideHack(text),
1682 hint));
1683}
1684
1685void RenderView::startDragging(const WebPoint& from, const WebDragData& data,
1686 WebDragOperationsMask allowed_ops) {
1687 Send(new ViewHostMsg_StartDragging(routing_id_,
1688 WebDropData(data),
1689 allowed_ops));
1690}
1691
[email protected]28b92df2009-09-25 17:35:451692bool RenderView::acceptsLoadDrops() {
1693 return renderer_preferences_.can_accept_load_drops;
1694}
1695
[email protected]48c9cf2d2009-09-16 16:47:521696void RenderView::focusNext() {
1697 Send(new ViewHostMsg_TakeFocus(routing_id_, false));
1698}
1699
1700void RenderView::focusPrevious() {
1701 Send(new ViewHostMsg_TakeFocus(routing_id_, true));
1702}
1703
1704void RenderView::navigateBackForwardSoon(int offset) {
1705 history_back_list_count_ += offset;
1706 history_forward_list_count_ -= offset;
1707
1708 Send(new ViewHostMsg_GoToEntryAtOffset(routing_id_, offset));
1709}
1710
1711int RenderView::historyBackListCount() {
1712 return history_back_list_count_;
1713}
1714
1715int RenderView::historyForwardListCount() {
1716 return history_forward_list_count_;
1717}
1718
1719void RenderView::didAddHistoryItem() {
1720 // We don't want to update the history length for the start page
1721 // navigation.
[email protected]26aa0482009-09-30 16:55:271722 WebFrame* main_frame = webview()->mainFrame();
[email protected]48c9cf2d2009-09-16 16:47:521723 DCHECK(main_frame != NULL);
1724
1725 WebDataSource* ds = main_frame->dataSource();
1726 DCHECK(ds != NULL);
1727
1728 NavigationState* navigation_state = NavigationState::FromDataSource(ds);
1729 DCHECK(navigation_state);
1730 if (navigation_state->transition_type() == PageTransition::START_PAGE)
1731 return;
1732
1733 history_back_list_count_++;
1734 history_forward_list_count_ = 0;
1735}
1736
[email protected]8922e1f2009-10-03 05:01:261737void RenderView::didUpdateInspectorSettings() {
1738 Send(new ViewHostMsg_UpdateInspectorSettings(
1739 routing_id_, webview()->inspectorSettings().utf8()));
1740}
1741
[email protected]acca2a1f2009-10-16 03:53:391742void RenderView::queryAutofillSuggestions(const WebNode& node,
1743 const WebString& name,
1744 const WebString& value) {
1745 static int query_counter = 0;
1746 autofill_query_id_ = query_counter++;
1747 autofill_query_node_ = node;
1748 Send(new ViewHostMsg_QueryFormFieldAutofill(
1749 routing_id_, autofill_query_id_, name, value));
1750}
1751
1752void RenderView::removeAutofillSuggestions(const WebString& name,
1753 const WebString& value) {
1754 Send(new ViewHostMsg_RemoveAutofillEntry(routing_id_, name, value));
1755}
1756
[email protected]79dbc662009-09-04 05:42:511757// WebKit::WebWidgetClient ----------------------------------------------------
1758
initial.commit09911bf2008-07-26 23:55:291759// We are supposed to get a single call to Show for a newly created RenderView
1760// that was created via RenderView::CreateWebView. So, we wait until this
1761// point to dispatch the ShowView message.
1762//
1763// This method provides us with the information about how to display the newly
1764// created RenderView (i.e., as a constrained popup or as a new tab).
1765//
[email protected]4873c7d2009-07-16 06:36:281766void RenderView::show(WebNavigationPolicy policy) {
initial.commit09911bf2008-07-26 23:55:291767 DCHECK(!did_show_) << "received extraneous Show call";
1768 DCHECK(opener_id_ != MSG_ROUTING_NONE);
1769
1770 if (did_show_)
1771 return;
1772 did_show_ = true;
1773
[email protected]28295ec2009-10-16 05:34:331774 // Force new windows to a popup if they were not opened with a user gesture.
1775 if (!opened_by_user_gesture_) {
1776 // We exempt background tabs for compat with older versions of Chrome.
1777 // TODO(darin): This seems bogus. These should have a user gesture, so
1778 // we probably don't need this check.
1779 if (policy != WebKit::WebNavigationPolicyNewBackgroundTab)
1780 policy = WebKit::WebNavigationPolicyNewPopup;
1781 }
1782
initial.commit09911bf2008-07-26 23:55:291783 // NOTE: initial_pos_ may still have its default values at this point, but
1784 // that's okay. It'll be ignored if disposition is not NEW_POPUP, or the
1785 // browser process will impose a default position otherwise.
[email protected]4873c7d2009-07-16 06:36:281786 Send(new ViewHostMsg_ShowView(opener_id_, routing_id_,
1787 NavigationPolicyToDisposition(policy), initial_pos_,
1788 opened_by_user_gesture_, creator_url_));
[email protected]2533ce12009-05-09 00:02:241789 SetPendingWindowRect(initial_pos_);
initial.commit09911bf2008-07-26 23:55:291790}
1791
[email protected]4873c7d2009-07-16 06:36:281792void RenderView::closeWidgetSoon() {
[email protected]2c4410d2009-05-06 23:46:221793 if (!popup_notification_visible_)
[email protected]4873c7d2009-07-16 06:36:281794 RenderWidget::closeWidgetSoon();
[email protected]634a6f92008-12-01 21:39:311795}
1796
[email protected]4873c7d2009-07-16 06:36:281797void RenderView::runModal() {
initial.commit09911bf2008-07-26 23:55:291798 DCHECK(did_show_) << "should already have shown the view";
1799
[email protected]12636df2009-09-28 22:32:211800 SendAndRunNestedMessageLoop(new ViewHostMsg_RunModal(routing_id_));
initial.commit09911bf2008-07-26 23:55:291801}
1802
[email protected]3d9689372009-09-10 04:29:171803// WebKit::WebFrameClient -----------------------------------------------------
1804
1805WebPlugin* RenderView::createPlugin(
1806 WebFrame* frame, const WebPluginParams& params) {
1807 return new webkit_glue::WebPluginImpl(frame, params, AsWeakPtr());
1808}
1809
1810WebWorker* RenderView::createWorker(WebFrame* frame, WebWorkerClient* client) {
1811 return new WebWorkerProxy(client, RenderThread::current(), routing_id_);
1812}
1813
[email protected]9c00f002009-11-05 22:37:421814WebSharedWorker* RenderView::createSharedWorker(
1815 WebFrame* frame, const WebURL& url, const WebString& name,
[email protected]30447b62009-11-13 01:13:371816 unsigned long long document_id) {
[email protected]9c00f002009-11-05 22:37:421817
[email protected]30447b62009-11-13 01:13:371818 int route_id = MSG_ROUTING_NONE;
1819 bool url_mismatch = false;
1820 Send(new ViewHostMsg_LookupSharedWorker(
1821 url, name, document_id, &route_id, &url_mismatch));
1822 if (url_mismatch) {
1823 return NULL;
1824 } else {
1825 return new WebSharedWorkerProxy(RenderThread::current(),
1826 route_id,
1827 routing_id_);
1828 }
[email protected]9c00f002009-11-05 22:37:421829}
1830
[email protected]3d9689372009-09-10 04:29:171831WebMediaPlayer* RenderView::createMediaPlayer(
1832 WebFrame* frame, WebMediaPlayerClient* client) {
1833 scoped_refptr<media::FilterFactoryCollection> factory =
1834 new media::FilterFactoryCollection();
1835 // Add in any custom filter factories first.
1836 const CommandLine* cmd_line = CommandLine::ForCurrentProcess();
1837 if (!cmd_line->HasSwitch(switches::kDisableAudio)) {
1838 // Add the chrome specific audio renderer.
1839 factory->AddFactory(
1840 AudioRendererImpl::CreateFactory(audio_message_filter()));
1841 }
1842
1843 // TODO(hclam): obtain the following parameters from |client|.
1844 webkit_glue::MediaResourceLoaderBridgeFactory* bridge_factory =
1845 new webkit_glue::MediaResourceLoaderBridgeFactory(
1846 GURL::EmptyGURL(), // referrer
1847 "null", // frame origin
1848 "null", // main_frame_origin
1849 base::GetCurrentProcId(),
1850 appcache::kNoHostId,
1851 routing_id());
1852
[email protected]0436b9a2009-10-23 00:23:051853 // A simple data source that keeps all data in memory.
1854 media::FilterFactory* simple_data_source_factory =
1855 webkit_glue::SimpleDataSource::CreateFactory(MessageLoop::current(),
1856 bridge_factory);
1857 // A sophisticated data source that does memory caching.
1858 media::FilterFactory* buffered_data_source_factory =
1859 webkit_glue::BufferedDataSource::CreateFactory(MessageLoop::current(),
1860 bridge_factory);
1861 if (cmd_line->HasSwitch(switches::kSimpleDataSource)) {
1862 factory->AddFactory(simple_data_source_factory);
1863 factory->AddFactory(buffered_data_source_factory);
[email protected]3d9689372009-09-10 04:29:171864 } else {
[email protected]0436b9a2009-10-23 00:23:051865 factory->AddFactory(buffered_data_source_factory);
1866 factory->AddFactory(simple_data_source_factory);
[email protected]3d9689372009-09-10 04:29:171867 }
1868 return new webkit_glue::WebMediaPlayerImpl(client, factory);
1869}
1870
1871void RenderView::willClose(WebFrame* frame) {
1872 if (!frame->parent()) {
1873 const GURL& url = frame->url();
1874 if (url.SchemeIs("http") || url.SchemeIs("https"))
1875 DumpLoadHistograms();
1876 }
[email protected]fa7b6b542009-11-03 05:02:301877
1878 WebDataSource* ds = frame->dataSource();
1879 NavigationState* navigation_state = NavigationState::FromDataSource(ds);
1880 navigation_state->user_script_idle_scheduler()->Cancel();
[email protected]3d9689372009-09-10 04:29:171881}
1882
1883void RenderView::loadURLExternally(
1884 WebFrame* frame, const WebURLRequest& request,
1885 WebNavigationPolicy policy) {
[email protected]efce17b2009-09-11 18:04:591886 GURL referrer(request.httpHeaderField(WebString::fromUTF8("Referer")));
1887 if (policy == WebKit::WebNavigationPolicyDownload) {
1888 Send(new ViewHostMsg_DownloadUrl(routing_id_, request.url(), referrer));
1889 } else {
1890 OpenURL(request.url(), referrer, policy);
1891 }
[email protected]3d9689372009-09-10 04:29:171892}
1893
1894WebNavigationPolicy RenderView::decidePolicyForNavigation(
1895 WebFrame* frame, const WebURLRequest& request, WebNavigationType type,
[email protected]65b95cd2009-10-09 05:10:221896 const WebNode&, WebNavigationPolicy default_policy, bool is_redirect) {
[email protected]3d9689372009-09-10 04:29:171897 // Webkit is asking whether to navigate to a new URL.
1898 // This is fine normally, except if we're showing UI from one security
1899 // context and they're trying to navigate to a different context.
1900 const GURL& url = request.url();
1901
1902 // If the browser is interested, then give it a chance to look at top level
1903 // navigations
1904 if (renderer_preferences_.browser_handles_top_level_requests &&
1905 // Only send once.
1906 last_top_level_navigation_page_id_ != page_id_ &&
1907 // Not interested in reloads.
1908 type != WebKit::WebNavigationTypeReload &&
1909 type != WebKit::WebNavigationTypeFormSubmitted &&
1910 // Must be a top level frame.
1911 frame->parent() == NULL) {
1912 // Skip if navigation is on the same page (using '#').
1913 GURL frame_origin = GURL(frame->url()).GetOrigin();
1914 if (url.GetOrigin() != frame_origin || url.ref().empty()) {
1915 last_top_level_navigation_page_id_ = page_id_;
[email protected]b36a9f92009-10-19 17:34:571916 GURL referrer(request.httpHeaderField(WebString::fromUTF8("Referer")));
1917 OpenURL(url, referrer, default_policy);
[email protected]3d9689372009-09-10 04:29:171918 return WebKit::WebNavigationPolicyIgnore; // Suppress the load here.
1919 }
1920 }
1921
1922 // A content initiated navigation may have originated from a link-click,
1923 // script, drag-n-drop operation, etc.
1924 bool is_content_initiated =
1925 NavigationState::FromDataSource(frame->provisionalDataSource())->
1926 is_content_initiated();
1927
1928 // We only care about navigations that are within the current tab (as opposed
1929 // to, for example, opening a new window).
1930 // But we sometimes navigate to about:blank to clear a tab, and we want to
1931 // still allow that.
1932 if (default_policy == WebKit::WebNavigationPolicyCurrentTab &&
1933 is_content_initiated && frame->parent() == NULL &&
1934 !url.SchemeIs(chrome::kAboutScheme)) {
1935 // When we received such unsolicited navigations, we sometimes want to
1936 // punt them up to the browser to handle.
1937 if (BindingsPolicy::is_dom_ui_enabled(enabled_bindings_) ||
1938 BindingsPolicy::is_extension_enabled(enabled_bindings_) ||
1939 frame->isViewSourceModeEnabled() ||
1940 url.SchemeIs(chrome::kViewSourceScheme) ||
1941 url.SchemeIs(chrome::kPrintScheme)) {
1942 OpenURL(url, GURL(), default_policy);
1943 return WebKit::WebNavigationPolicyIgnore; // Suppress the load here.
1944 }
1945 }
1946
1947 // Detect when a page is "forking" a new tab that can be safely rendered in
1948 // its own process. This is done by sites like Gmail that try to open links
1949 // in new windows without script connections back to the original page. We
1950 // treat such cases as browser navigations (in which we will create a new
1951 // renderer for a cross-site navigation), rather than WebKit navigations.
1952 //
1953 // We use the following heuristic to decide whether to fork a new page in its
1954 // own process:
1955 // The parent page must open a new tab to about:blank, set the new tab's
1956 // window.opener to null, and then redirect the tab to a cross-site URL using
1957 // JavaScript.
[email protected]007a848b2009-10-26 15:55:461958 //
1959 // TODO(creis): Deprecate this logic once we can rely on rel=noreferrer
1960 // (see below).
[email protected]3d9689372009-09-10 04:29:171961 bool is_fork =
1962 // Must start from a tab showing about:blank, which is later redirected.
[email protected]e0d481582009-09-15 21:06:251963 GURL(frame->url()) == GURL(chrome::kAboutBlankURL) &&
[email protected]3d9689372009-09-10 04:29:171964 // Must be the first real navigation of the tab.
[email protected]48c9cf2d2009-09-16 16:47:521965 historyBackListCount() < 1 &&
1966 historyForwardListCount() < 1 &&
[email protected]3d9689372009-09-10 04:29:171967 // The parent page must have set the child's window.opener to null before
1968 // redirecting to the desired URL.
1969 frame->opener() == NULL &&
1970 // Must be a top-level frame.
1971 frame->parent() == NULL &&
1972 // Must not have issued the request from this page.
1973 is_content_initiated &&
1974 // Must be targeted at the current tab.
1975 default_policy == WebKit::WebNavigationPolicyCurrentTab &&
1976 // Must be a JavaScript navigation, which appears as "other".
1977 type == WebKit::WebNavigationTypeOther;
[email protected]007a848b2009-10-26 15:55:461978
1979 // Recognize if this navigation is from a link with rel=noreferrer and
1980 // target=_blank attributes, in which case the opener will be suppressed. If
1981 // so, it is safe to load cross-site pages in a separate process, so we
1982 // should let the browser handle it.
1983 bool is_noreferrer_and_blank_target =
1984 // Frame should be top level and not yet navigated.
1985 frame->parent() == NULL &&
1986 frame->url().isEmpty() &&
1987 historyBackListCount() < 1 &&
1988 historyForwardListCount() < 1 &&
1989 // Links with rel=noreferrer will have no Referer field, and their
1990 // resulting frame will have its window.opener suppressed.
1991 // TODO(creis): should add a request.httpReferrer() method to help avoid
1992 // typos on the unusual spelling of Referer.
1993 request.httpHeaderField(WebString::fromUTF8("Referer")).isNull() &&
1994 opener_suppressed_ &&
1995 frame->opener() == NULL &&
1996 // Links with target=_blank will have no name.
1997 frame->name().isNull() &&
1998 // Another frame (with a non-empty creator) should have initiated the
1999 // request, targeted at this frame.
2000 !creator_url_.is_empty() &&
2001 is_content_initiated &&
2002 default_policy == WebKit::WebNavigationPolicyCurrentTab &&
2003 type == WebKit::WebNavigationTypeOther;
2004
2005 if (is_fork || is_noreferrer_and_blank_target) {
[email protected]3d9689372009-09-10 04:29:172006 // Open the URL via the browser, not via WebKit.
2007 OpenURL(url, GURL(), default_policy);
2008 return WebKit::WebNavigationPolicyIgnore;
2009 }
2010
2011 return default_policy;
2012}
2013
[email protected]6069da8c2009-10-20 20:33:492014bool RenderView::canHandleRequest(
2015 WebFrame* frame, const WebURLRequest& request) {
2016 // We allow WebKit to think that everything can be handled even though
2017 // browser-side we limit what we load.
[email protected]7b7a7dc2009-10-19 02:23:342018 return true;
2019}
2020
[email protected]6069da8c2009-10-20 20:33:492021WebURLError RenderView::cannotHandleRequestError(
2022 WebFrame* frame, const WebURLRequest& request) {
2023 NOTREACHED(); // Since we said we can handle all requests.
2024 return WebURLError();
2025}
2026
2027WebURLError RenderView::cancelledError(
2028 WebFrame* frame, const WebURLRequest& request) {
2029 WebURLError error;
2030 error.domain = WebString::fromUTF8(net::kErrorDomain);
2031 error.reason = net::ERR_ABORTED;
2032 error.unreachableURL = request.url();
2033 return error;
[email protected]7b7a7dc2009-10-19 02:23:342034}
2035
2036void RenderView::unableToImplementPolicyWithError(
[email protected]6069da8c2009-10-20 20:33:492037 WebFrame*, const WebURLError&) {
2038 NOTREACHED(); // Since we said we can handle all requests.
[email protected]7b7a7dc2009-10-19 02:23:342039}
2040
[email protected]979c28b2009-11-07 01:30:482041void RenderView::willSubmitForm(WebFrame* frame, const WebFormElement& form) {
[email protected]3d9689372009-09-10 04:29:172042 NavigationState* navigation_state =
2043 NavigationState::FromDataSource(frame->provisionalDataSource());
2044
2045 if (navigation_state->transition_type() == PageTransition::LINK)
2046 navigation_state->set_transition_type(PageTransition::FORM_SUBMIT);
2047
2048 // Save these to be processed when the ensuing navigation is committed.
[email protected]ce0e250d2009-10-23 21:00:352049 WebSearchableFormData web_searchable_form_data(form);
2050 navigation_state->set_searchable_form_url(web_searchable_form_data.url());
2051 navigation_state->set_searchable_form_encoding(
2052 webkit_glue::WebStringToStdString(web_searchable_form_data.encoding()));
[email protected]3d9689372009-09-10 04:29:172053 navigation_state->set_password_form_data(
2054 PasswordFormDomManager::CreatePasswordForm(form));
2055
[email protected]979c28b2009-11-07 01:30:482056 if (form.autoComplete()) {
[email protected]c54d269e2009-10-21 18:07:382057 scoped_ptr<FormFieldValues> form_values(FormFieldValues::Create(form));
2058 if (form_values.get())
[email protected]51bd36612009-10-20 22:49:472059 Send(new ViewHostMsg_FormFieldValuesSubmitted(routing_id_,
[email protected]c54d269e2009-10-21 18:07:382060 *form_values));
[email protected]3d9689372009-09-10 04:29:172061 }
2062}
2063
2064void RenderView::willPerformClientRedirect(
2065 WebFrame* frame, const WebURL& from, const WebURL& to, double interval,
2066 double fire_time) {
2067 // Ignore
2068}
2069
2070void RenderView::didCancelClientRedirect(WebFrame* frame) {
2071 // Ignore
2072}
2073
2074void RenderView::didCompleteClientRedirect(
2075 WebFrame* frame, const WebURL& from) {
2076 if (!frame->parent())
2077 completed_client_redirect_src_ = from;
2078}
2079
2080void RenderView::didCreateDataSource(WebFrame* frame, WebDataSource* ds) {
2081 // The rest of RenderView assumes that a WebDataSource will always have a
2082 // non-null NavigationState.
[email protected]fa7b6b542009-11-03 05:02:302083 NavigationState* state = pending_navigation_state_.get() ?
[email protected]7ea093ba2009-11-03 05:54:592084 pending_navigation_state_.release() :
[email protected]fa7b6b542009-11-03 05:02:302085 NavigationState::CreateContentInitiated();
2086
2087 state->set_user_script_idle_scheduler(
2088 new UserScriptIdleScheduler(this, frame));
2089 ds->setExtraData(state);
[email protected]3d9689372009-09-10 04:29:172090}
2091
2092void RenderView::didStartProvisionalLoad(WebFrame* frame) {
2093 WebDataSource* ds = frame->provisionalDataSource();
2094 NavigationState* navigation_state = NavigationState::FromDataSource(ds);
2095
2096 navigation_state->set_start_load_time(Time::Now());
2097
2098 // Update the request time if WebKit has better knowledge of it.
2099 if (navigation_state->request_time().is_null()) {
2100 double event_time = ds->triggeringEventTime();
2101 if (event_time != 0.0)
2102 navigation_state->set_request_time(Time::FromDoubleT(event_time));
2103 }
2104
2105 bool is_top_most = !frame->parent();
2106 if (is_top_most) {
2107 navigation_gesture_ = frame->isProcessingUserGesture() ?
2108 NavigationGestureUnknown : NavigationGestureAuto;
2109
2110 // Make sure redirect tracking state is clear for the new load.
2111 completed_client_redirect_src_ = GURL();
2112 } else if (frame->parent()->isLoading()) {
2113 // Take note of AUTO_SUBFRAME loads here, so that we can know how to
2114 // load an error page. See DidFailProvisionalLoadWithError.
2115 navigation_state->set_transition_type(PageTransition::AUTO_SUBFRAME);
2116 }
2117
2118 Send(new ViewHostMsg_DidStartProvisionalLoadForFrame(
2119 routing_id_, is_top_most, ds->request().url()));
2120}
2121
2122void RenderView::didReceiveServerRedirectForProvisionalLoad(WebFrame* frame) {
2123 if (frame->parent())
2124 return;
2125 // Received a redirect on the main frame.
2126 WebDataSource* data_source = frame->provisionalDataSource();
2127 if (!data_source) {
2128 // Should only be invoked when we have a data source.
2129 NOTREACHED();
2130 return;
2131 }
2132 std::vector<GURL> redirects;
2133 GetRedirectChain(data_source, &redirects);
2134 if (redirects.size() >= 2) {
2135 Send(new ViewHostMsg_DidRedirectProvisionalLoad(
2136 routing_id_, page_id_, redirects[redirects.size() - 2],
2137 redirects[redirects.size() - 1]));
2138 }
2139}
2140
2141void RenderView::didFailProvisionalLoad(
2142 WebFrame* frame, const WebURLError& error) {
2143 // Notify the browser that we failed a provisional load with an error.
2144 //
2145 // Note: It is important this notification occur before DidStopLoading so the
2146 // SSL manager can react to the provisional load failure before being
2147 // notified the load stopped.
2148 //
2149 WebDataSource* ds = frame->provisionalDataSource();
2150 DCHECK(ds);
2151
2152 const WebURLRequest& failed_request = ds->request();
2153
2154 bool show_repost_interstitial =
2155 (error.reason == net::ERR_CACHE_MISS &&
2156 EqualsASCII(failed_request.httpMethod(), "POST"));
2157 Send(new ViewHostMsg_DidFailProvisionalLoadWithError(
2158 routing_id_, !frame->parent(), error.reason, error.unreachableURL,
2159 show_repost_interstitial));
2160
2161 // Don't display an error page if this is simply a cancelled load. Aside
2162 // from being dumb, WebCore doesn't expect it and it will cause a crash.
2163 if (error.reason == net::ERR_ABORTED)
2164 return;
2165
2166 // Make sure we never show errors in view source mode.
2167 frame->enableViewSourceMode(false);
2168
2169 NavigationState* navigation_state = NavigationState::FromDataSource(ds);
2170
2171 // If this is a failed back/forward/reload navigation, then we need to do a
2172 // 'replace' load. This is necessary to avoid messing up session history.
2173 // Otherwise, we do a normal load, which simulates a 'go' navigation as far
2174 // as session history is concerned.
2175 //
2176 // AUTO_SUBFRAME loads should always be treated as loads that do not advance
2177 // the page id.
2178 //
2179 bool replace =
2180 navigation_state->pending_page_id() != -1 ||
2181 navigation_state->transition_type() == PageTransition::AUTO_SUBFRAME;
2182
2183 // If we failed on a browser initiated request, then make sure that our error
2184 // page load is regarded as the same browser initiated request.
2185 if (!navigation_state->is_content_initiated()) {
2186 pending_navigation_state_.reset(NavigationState::CreateBrowserInitiated(
2187 navigation_state->pending_page_id(),
2188 navigation_state->transition_type(),
2189 navigation_state->request_time()));
2190 }
2191
2192 // Provide the user with a more helpful error page?
2193 if (MaybeLoadAlternateErrorPage(frame, error, replace))
2194 return;
2195
2196 // Fallback to a local error page.
2197 LoadNavigationErrorPage(frame, failed_request, error, std::string(),
2198 replace);
2199}
2200
2201void RenderView::didReceiveDocumentData(
2202 WebFrame* frame, const char* data, size_t data_len,
2203 bool& prevent_default) {
2204 NavigationState* navigation_state =
2205 NavigationState::FromDataSource(frame->dataSource());
2206 if (!navigation_state->postpone_loading_data())
2207 return;
2208
2209 // We're going to call commitDocumentData ourselves...
2210 prevent_default = true;
2211
2212 // Continue buffering the response data for the original 404 page. If it
2213 // grows too large, then we'll just let it through.
2214 navigation_state->append_postponed_data(data, data_len);
2215 if (navigation_state->postponed_data().size() >= 512) {
2216 navigation_state->set_postpone_loading_data(false);
2217 frame->commitDocumentData(navigation_state->postponed_data().data(),
2218 navigation_state->postponed_data().size());
2219 navigation_state->clear_postponed_data();
2220 }
2221}
2222
2223void RenderView::didCommitProvisionalLoad(
2224 WebFrame* frame, bool is_new_navigation) {
2225 NavigationState* navigation_state =
2226 NavigationState::FromDataSource(frame->dataSource());
2227
2228 navigation_state->set_commit_load_time(Time::Now());
2229 if (is_new_navigation) {
2230 // When we perform a new navigation, we need to update the previous session
2231 // history entry with state for the page we are leaving.
2232 UpdateSessionHistory(frame);
2233
2234 // We bump our Page ID to correspond with the new session history entry.
2235 page_id_ = next_page_id_++;
2236
2237 MessageLoop::current()->PostDelayedTask(FROM_HERE,
2238 method_factory_.NewRunnableMethod(&RenderView::CapturePageInfo,
2239 page_id_, true),
2240 kDelayForForcedCaptureMs);
2241 } else {
2242 // Inspect the navigation_state on this frame to see if the navigation
2243 // corresponds to a session history navigation... Note: |frame| may or
2244 // may not be the toplevel frame, but for the case of capturing session
2245 // history, the first committed frame suffices. We keep track of whether
2246 // we've seen this commit before so that only capture session history once
2247 // per navigation.
2248 //
2249 // Note that we need to check if the page ID changed. In the case of a
2250 // reload, the page ID doesn't change, and UpdateSessionHistory gets the
2251 // previous URL and the current page ID, which would be wrong.
2252 if (navigation_state->pending_page_id() != -1 &&
2253 navigation_state->pending_page_id() != page_id_ &&
2254 !navigation_state->request_committed()) {
2255 // This is a successful session history navigation!
2256 UpdateSessionHistory(frame);
2257 page_id_ = navigation_state->pending_page_id();
2258 }
2259 }
2260
2261 // Remember that we've already processed this request, so we don't update
2262 // the session history again. We do this regardless of whether this is
2263 // a session history navigation, because if we attempted a session history
2264 // navigation without valid HistoryItem state, WebCore will think it is a
2265 // new navigation.
2266 navigation_state->set_request_committed(true);
2267
2268 UpdateURL(frame);
2269
2270 // If this committed load was initiated by a client redirect, we're
2271 // at the last stop now, so clear it.
2272 completed_client_redirect_src_ = GURL();
2273
2274 // Check whether we have new encoding name.
[email protected]26aa0482009-09-30 16:55:272275 UpdateEncoding(frame, frame->view()->pageEncoding().utf8());
[email protected]3d9689372009-09-10 04:29:172276}
2277
2278void RenderView::didClearWindowObject(WebFrame* frame) {
2279 if (BindingsPolicy::is_dom_automation_enabled(enabled_bindings_))
2280 BindDOMAutomationController(frame);
2281 if (BindingsPolicy::is_dom_ui_enabled(enabled_bindings_)) {
2282 dom_ui_bindings_.set_message_sender(this);
2283 dom_ui_bindings_.set_routing_id(routing_id_);
2284 dom_ui_bindings_.BindToJavascript(frame, L"chrome");
2285 }
2286 if (BindingsPolicy::is_external_host_enabled(enabled_bindings_)) {
2287 external_host_bindings_.set_message_sender(this);
2288 external_host_bindings_.set_routing_id(routing_id_);
2289 external_host_bindings_.BindToJavascript(frame, L"externalHost");
2290 }
2291}
2292
2293void RenderView::didCreateDocumentElement(WebFrame* frame) {
2294 if (RenderThread::current()) { // Will be NULL during unit tests.
2295 RenderThread::current()->user_script_slave()->InjectScripts(
2296 frame, UserScript::DOCUMENT_START);
2297 }
[email protected]078b34612009-09-19 19:31:512298 if (view_type_ == ViewType::EXTENSION_TOOLSTRIP ||
2299 view_type_ == ViewType::EXTENSION_MOLE) {
2300 InjectToolstripCSS();
2301 ExtensionProcessBindings::SetViewType(webview(), view_type_);
2302 }
[email protected]3d9689372009-09-10 04:29:172303
2304 // Notify the browser about non-blank documents loading in the top frame.
2305 GURL url = frame->url();
[email protected]e0d481582009-09-15 21:06:252306 if (url.is_valid() && url.spec() != chrome::kAboutBlankURL) {
[email protected]26aa0482009-09-30 16:55:272307 if (frame == webview()->mainFrame())
[email protected]3d9689372009-09-10 04:29:172308 Send(new ViewHostMsg_DocumentAvailableInMainFrame(routing_id_));
2309 }
2310}
2311
2312void RenderView::didReceiveTitle(WebFrame* frame, const WebString& title) {
2313 UpdateTitle(frame, title);
2314
2315 // Also check whether we have new encoding name.
[email protected]26aa0482009-09-30 16:55:272316 UpdateEncoding(frame, frame->view()->pageEncoding().utf8());
[email protected]3d9689372009-09-10 04:29:172317}
2318
2319void RenderView::didFinishDocumentLoad(WebFrame* frame) {
2320 WebDataSource* ds = frame->dataSource();
2321 NavigationState* navigation_state = NavigationState::FromDataSource(ds);
2322 DCHECK(navigation_state);
2323 navigation_state->set_finish_document_load_time(Time::Now());
2324
2325 Send(new ViewHostMsg_DocumentLoadedInFrame(routing_id_));
2326
2327 // The document has now been fully loaded. Scan for password forms to be
2328 // sent up to the browser.
2329 SendPasswordForms(frame);
2330
2331 // Check whether we have new encoding name.
[email protected]26aa0482009-09-30 16:55:272332 UpdateEncoding(frame, frame->view()->pageEncoding().utf8());
[email protected]3d9689372009-09-10 04:29:172333
2334 if (RenderThread::current()) { // Will be NULL during unit tests.
2335 RenderThread::current()->user_script_slave()->InjectScripts(
2336 frame, UserScript::DOCUMENT_END);
2337 }
[email protected]fa7b6b542009-11-03 05:02:302338
2339 navigation_state->user_script_idle_scheduler()->DidFinishDocumentLoad();
2340}
2341
2342void RenderView::OnUserScriptIdleTriggered(WebFrame* frame) {
2343 if (RenderThread::current()) { // Will be NULL during unit tests.
2344 RenderThread::current()->user_script_slave()->InjectScripts(
2345 frame, UserScript::DOCUMENT_IDLE);
2346 }
2347
2348 WebFrame* main_frame = webview()->mainFrame();
2349 if (frame == main_frame) {
2350 while (!pending_code_execution_queue_.empty()) {
2351 scoped_refptr<CodeExecutionInfo> info =
2352 pending_code_execution_queue_.front();
2353 ExecuteCodeImpl(main_frame, info->request_id, info->extension_id,
2354 info->is_js_code, info->code_string);
2355 pending_code_execution_queue_.pop();
2356 }
2357 }
[email protected]3d9689372009-09-10 04:29:172358}
2359
2360void RenderView::didHandleOnloadEvents(WebFrame* frame) {
2361 // Ignore
2362}
2363
2364void RenderView::didFailLoad(WebFrame* frame, const WebURLError& error) {
2365 // Ignore
2366}
2367
2368void RenderView::didFinishLoad(WebFrame* frame) {
2369 WebDataSource* ds = frame->dataSource();
2370 NavigationState* navigation_state = NavigationState::FromDataSource(ds);
2371 DCHECK(navigation_state);
2372 navigation_state->set_finish_load_time(Time::Now());
[email protected]fa7b6b542009-11-03 05:02:302373 navigation_state->user_script_idle_scheduler()->DidFinishLoad();
[email protected]3d9689372009-09-10 04:29:172374}
2375
2376void RenderView::didChangeLocationWithinPage(
2377 WebFrame* frame, bool is_new_navigation) {
2378 // If this was a reference fragment navigation that we initiated, then we
2379 // could end up having a non-null pending navigation state. We just need to
2380 // update the ExtraData on the datasource so that others who read the
2381 // ExtraData will get the new NavigationState. Similarly, if we did not
2382 // initiate this navigation, then we need to take care to reset any pre-
2383 // existing navigation state to a content-initiated navigation state.
2384 // DidCreateDataSource conveniently takes care of this for us.
2385 didCreateDataSource(frame, frame->dataSource());
2386
2387 didCommitProvisionalLoad(frame, is_new_navigation);
2388
[email protected]26aa0482009-09-30 16:55:272389 UpdateTitle(frame, frame->view()->mainFrame()->dataSource()->pageTitle());
[email protected]3d9689372009-09-10 04:29:172390}
2391
[email protected]476b6f82009-09-10 21:00:592392void RenderView::didUpdateCurrentHistoryItem(WebFrame* frame) {
[email protected]882daa92009-11-05 16:31:312393 StartNavStateSyncTimerIfNecessary();
[email protected]476b6f82009-09-10 21:00:592394}
2395
[email protected]3d9689372009-09-10 04:29:172396void RenderView::assignIdentifierToRequest(
2397 WebFrame* frame, unsigned identifier, const WebURLRequest& request) {
2398 // Ignore
2399}
2400
2401void RenderView::willSendRequest(
2402 WebFrame* frame, unsigned identifier, WebURLRequest& request,
2403 const WebURLResponse& redirect_response) {
[email protected]5e369672009-11-03 23:48:302404 WebFrame* top_frame = frame->top();
2405 if (!top_frame)
2406 top_frame = frame;
2407 WebDataSource* data_source = top_frame->provisionalDataSource();
2408 if (!data_source)
2409 data_source = top_frame->dataSource();
2410 if (data_source) {
2411 NavigationState* state = NavigationState::FromDataSource(data_source);
2412 if (state && state->is_cache_policy_override_set())
2413 request.setCachePolicy(state->cache_policy_override());
2414 }
[email protected]3d9689372009-09-10 04:29:172415 request.setRequestorID(routing_id_);
2416}
2417
2418void RenderView::didReceiveResponse(
2419 WebFrame* frame, unsigned identifier, const WebURLResponse& response) {
2420 // Consider loading an alternate error page for 404 responses.
2421 if (response.httpStatusCode() != 404)
2422 return;
2423
2424 // Only do this for responses that correspond to a provisional data source
2425 // of the top-most frame. If we have a provisional data source, then we
2426 // can't have any sub-resources yet, so we know that this response must
2427 // correspond to a frame load.
2428 if (!frame->provisionalDataSource() || frame->parent())
2429 return;
2430
2431 // If we are in view source mode, then just let the user see the source of
2432 // the server's 404 error page.
2433 if (frame->isViewSourceModeEnabled())
2434 return;
2435
2436 // Can we even load an alternate error page for this URL?
2437 if (!GetAlternateErrorPageURL(response.url(), HTTP_404).is_valid())
2438 return;
2439
2440 NavigationState* navigation_state =
2441 NavigationState::FromDataSource(frame->provisionalDataSource());
2442 navigation_state->set_postpone_loading_data(true);
2443 navigation_state->clear_postponed_data();
2444}
2445
2446void RenderView::didFinishResourceLoad(
2447 WebFrame* frame, unsigned identifier) {
2448 NavigationState* navigation_state =
2449 NavigationState::FromDataSource(frame->dataSource());
2450 if (!navigation_state->postpone_loading_data())
2451 return;
2452
2453 // The server returned a 404 and the content was < 512 bytes (which we
2454 // suppressed). Go ahead and fetch the alternate page content.
2455
2456 const GURL& frame_url = frame->url();
2457
2458 const GURL& error_page_url = GetAlternateErrorPageURL(frame_url, HTTP_404);
2459 DCHECK(error_page_url.is_valid());
2460
2461 WebURLError original_error;
2462 original_error.unreachableURL = frame_url;
2463
2464 navigation_state->set_alt_error_page_fetcher(
2465 new AltErrorPageResourceFetcher(
2466 error_page_url, frame, original_error,
2467 NewCallback(this, &RenderView::AltErrorPageFinished)));
2468}
2469
2470void RenderView::didFailResourceLoad(
2471 WebFrame* frame, unsigned identifier, const WebURLError& error) {
2472 // Ignore
2473}
2474
2475void RenderView::didLoadResourceFromMemoryCache(
2476 WebFrame* frame, const WebURLRequest& request,
2477 const WebURLResponse& response) {
2478 // Let the browser know we loaded a resource from the memory cache. This
2479 // message is needed to display the correct SSL indicators.
2480 Send(new ViewHostMsg_DidLoadResourceFromMemoryCache(
2481 routing_id_,
2482 request.url(),
[email protected]91733b62009-09-18 06:21:092483 frame->securityOrigin().toString().utf8(),
2484 frame->top()->securityOrigin().toString().utf8(),
[email protected]3d9689372009-09-10 04:29:172485 response.securityInfo()));
2486}
2487
[email protected]6069da8c2009-10-20 20:33:492488void RenderView::didDisplayInsecureContent(WebFrame* frame) {
[email protected]e3d60e5d2009-09-25 21:08:292489 Send(new ViewHostMsg_DidDisplayInsecureContent(routing_id_));
2490}
2491
2492void RenderView::didRunInsecureContent(
2493 WebFrame* frame, const WebSecurityOrigin& origin) {
2494 Send(new ViewHostMsg_DidRunInsecureContent(
2495 routing_id_,
2496 origin.toString().utf8()));
2497}
2498
[email protected]7ea093ba2009-11-03 05:54:592499bool RenderView::allowScript(WebFrame* frame, bool enabled_per_settings) {
2500 if (enabled_per_settings)
2501 return true;
2502
2503 WebSecurityOrigin origin = frame->securityOrigin();
2504 if (origin.isEmpty())
2505 return false; // Uninitialized document?
2506
2507 if (EqualsASCII(origin.protocol(), chrome::kChromeUIScheme))
2508 return true; // Browser UI elements should still work.
2509
2510 // If the scheme is ftp: or file:, an empty file name indicates a directory
2511 // listing, which requires JavaScript to function properly.
2512 GURL frame_url = frame->url();
2513 const char* kDirProtocols[] = { "ftp", "file" };
2514 for (size_t i = 0; i < arraysize(kDirProtocols); ++i) {
2515 if (EqualsASCII(origin.protocol(), kDirProtocols[i])) {
2516 return frame_url.SchemeIs(kDirProtocols[i]) &&
2517 frame_url.ExtractFileName().empty();
2518 }
2519 }
2520
2521 return false; // Other protocols fall through here.
2522}
2523
[email protected]3d9689372009-09-10 04:29:172524void RenderView::didExhaustMemoryAvailableForScript(WebFrame* frame) {
2525 Send(new ViewHostMsg_JSOutOfMemory(routing_id_));
2526}
2527
[email protected]0c882b282009-10-07 17:01:282528void RenderView::didCreateScriptContext(WebFrame* frame) {
2529 EventBindings::HandleContextCreated(frame, false);
2530}
2531
2532void RenderView::didDestroyScriptContext(WebFrame* frame) {
2533 EventBindings::HandleContextDestroyed(frame);
2534}
2535
2536void RenderView::didCreateIsolatedScriptContext(WebFrame* frame) {
2537 EventBindings::HandleContextCreated(frame, true);
2538}
2539
[email protected]3d9689372009-09-10 04:29:172540void RenderView::didChangeContentsSize(WebFrame* frame, const WebSize& size) {
2541 // We don't always want to send the change messages over IPC, only if we've
[email protected]ab32b16c2009-10-16 14:57:252542 // be put in that mode by getting a |ViewMsg_EnablePreferredSizeChangedMode|
[email protected]3d9689372009-09-10 04:29:172543 // message.
[email protected]ab32b16c2009-10-16 14:57:252544 if (send_preferred_size_changes_) {
[email protected]3d9689372009-09-10 04:29:172545 // WebCore likes to tell us things have changed even when they haven't, so
[email protected]ab32b16c2009-10-16 14:57:252546 // cache the width and height and only send the IPC message when we're sure
2547 // they're different.
[email protected]26aa0482009-09-30 16:55:272548 int width = webview()->mainFrame()->contentsPreferredWidth();
[email protected]ab32b16c2009-10-16 14:57:252549 if (width != preferred_size_.width() ||
2550 size.height != preferred_size_.height()) {
2551 preferred_size_.set_width(width);
2552
2553 // TODO(erikkay) the contents size is not really the same as the
2554 // preferred size. It's just the current size. This means that for
2555 // height, it will only ever grow, it will never shrink.
2556 preferred_size_.set_height(size.height);
2557 Send(new ViewHostMsg_DidContentsPreferredSizeChange(routing_id_,
2558 preferred_size_));
[email protected]3d9689372009-09-10 04:29:172559 }
2560 }
2561}
2562
[email protected]143dcd592009-11-06 21:33:492563void RenderView::didChangeScrollOffset(WebFrame* frame) {
2564 StartNavStateSyncTimerIfNecessary();
2565}
2566
[email protected]8922e1f2009-10-03 05:01:262567void RenderView::reportFindInPageMatchCount(int request_id, int count,
2568 bool final_update) {
2569 // If we have a message that has been queued up, then we should just replace
2570 // it. The ACK from the browser will make sure it gets sent when the browser
2571 // wants it.
2572 if (queued_find_reply_message_.get()) {
2573 IPC::Message* msg = new ViewHostMsg_Find_Reply(
2574 routing_id_,
2575 request_id,
2576 count,
2577 gfx::Rect(),
2578 -1, // Don't update active match ordinal.
2579 final_update);
2580 queued_find_reply_message_.reset(msg);
2581 } else {
2582 // Send the search result over to the browser process.
2583 Send(new ViewHostMsg_Find_Reply(
2584 routing_id_,
2585 request_id,
2586 count,
2587 gfx::Rect(),
2588 -1, // // Don't update active match ordinal.
2589 final_update));
2590 }
2591}
2592
2593void RenderView::reportFindInPageSelection(int request_id,
2594 int active_match_ordinal,
2595 const WebRect& selection_rect) {
2596 // Send the search result over to the browser process.
2597 Send(new ViewHostMsg_Find_Reply(routing_id_,
2598 request_id,
2599 -1,
2600 selection_rect,
2601 active_match_ordinal,
2602 false));
2603}
2604
[email protected]79dbc662009-09-04 05:42:512605// webkit_glue::WebPluginPageDelegate -----------------------------------------
2606
[email protected]f103ab72009-09-02 17:10:592607webkit_glue::WebPluginDelegate* RenderView::CreatePluginDelegate(
2608 const GURL& url,
2609 const std::string& mime_type,
[email protected]f103ab72009-09-02 17:10:592610 std::string* actual_mime_type) {
2611 if (!PluginChannelHost::IsListening())
2612 return NULL;
2613
2614 GURL policy_url;
[email protected]26aa0482009-09-30 16:55:272615 WebFrame* main_frame = webview()->mainFrame();
[email protected]f103ab72009-09-02 17:10:592616 if (main_frame)
2617 policy_url = main_frame->url();
2618
2619 FilePath path;
[email protected]610c0892009-09-08 19:46:182620 render_thread_->Send(new ViewHostMsg_GetPluginPath(
2621 url, policy_url, mime_type, &path, actual_mime_type));
[email protected]f103ab72009-09-02 17:10:592622 if (path.value().empty())
2623 return NULL;
2624
2625 const std::string* mime_type_to_use;
2626 if (!actual_mime_type->empty())
2627 mime_type_to_use = actual_mime_type;
2628 else
2629 mime_type_to_use = &mime_type;
2630
[email protected]26e8d5e2009-10-13 02:47:162631#if defined(PEPPER_APIS_ENABLED)
2632 const char kPepperPrefix[] = "pepper-";
2633 if (StartsWithASCII(*mime_type_to_use, kPepperPrefix, true)) {
[email protected]d439ba072009-10-17 22:32:292634 return WebPluginDelegatePepper::Create(
[email protected]26e8d5e2009-10-13 02:47:162635 path, *mime_type_to_use, gfx::NativeViewFromId(host_window_));
2636 }
2637#endif
2638
[email protected]d032f492009-09-29 00:33:462639 bool in_process_plugin = RenderProcess::current()->in_process_plugins();
2640 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kInternalNaCl)) {
2641 if (mime_type == "application/x-nacl-srpc") {
2642 in_process_plugin = true;
2643 }
2644 }
2645 if (in_process_plugin) {
[email protected]f103ab72009-09-02 17:10:592646#if defined(OS_WIN) // In-proc plugins aren't supported on Linux or Mac.
[email protected]8a3b7962009-09-04 05:53:232647 return WebPluginDelegateImpl::Create(
[email protected]f103ab72009-09-02 17:10:592648 path, *mime_type_to_use, gfx::NativeViewFromId(host_window_));
2649#else
2650 NOTIMPLEMENTED();
2651 return NULL;
2652#endif
2653 }
2654
[email protected]610c0892009-09-08 19:46:182655 return new WebPluginDelegateProxy(*mime_type_to_use, AsWeakPtr());
[email protected]f103ab72009-09-02 17:10:592656}
2657
2658void RenderView::CreatedPluginWindow(gfx::PluginWindowHandle window) {
2659#if defined(OS_LINUX)
2660 RenderThread::current()->Send(new ViewHostMsg_CreatePluginContainer(
2661 routing_id(), window));
2662#endif
2663}
2664
2665void RenderView::WillDestroyPluginWindow(gfx::PluginWindowHandle window) {
2666#if defined(OS_LINUX)
2667 RenderThread::current()->Send(new ViewHostMsg_DestroyPluginContainer(
2668 routing_id(), window));
2669#endif
2670 CleanupWindowInPluginMoves(window);
2671}
2672
2673void RenderView::DidMovePlugin(const webkit_glue::WebPluginGeometry& move) {
2674 SchedulePluginMove(move);
2675}
2676
2677void RenderView::DidStartLoadingForPlugin() {
2678 // TODO(darin): Make is_loading_ be a counter!
[email protected]48c9cf2d2009-09-16 16:47:522679 didStartLoading();
[email protected]f103ab72009-09-02 17:10:592680}
2681
2682void RenderView::DidStopLoadingForPlugin() {
2683 // TODO(darin): Make is_loading_ be a counter!
[email protected]48c9cf2d2009-09-16 16:47:522684 didStopLoading();
[email protected]f103ab72009-09-02 17:10:592685}
2686
2687void RenderView::ShowModalHTMLDialogForPlugin(
2688 const GURL& url,
2689 const gfx::Size& size,
2690 const std::string& json_arguments,
2691 std::string* json_retval) {
[email protected]12636df2009-09-28 22:32:212692 SendAndRunNestedMessageLoop(new ViewHostMsg_ShowModalHTMLDialog(
[email protected]f103ab72009-09-02 17:10:592693 routing_id_, url, size.width(), size.height(), json_arguments,
[email protected]12636df2009-09-28 22:32:212694 json_retval));
[email protected]f103ab72009-09-02 17:10:592695}
2696
initial.commit09911bf2008-07-26 23:55:292697void RenderView::SyncNavigationState() {
2698 if (!webview())
2699 return;
2700
[email protected]26aa0482009-09-30 16:55:272701 const WebHistoryItem& item = webview()->mainFrame()->currentHistoryItem();
[email protected]ca948a22009-06-25 19:36:172702 if (item.isNull())
initial.commit09911bf2008-07-26 23:55:292703 return;
[email protected]ca948a22009-06-25 19:36:172704
2705 Send(new ViewHostMsg_UpdateState(
2706 routing_id_, page_id_, webkit_glue::HistoryItemToString(item)));
initial.commit09911bf2008-07-26 23:55:292707}
2708
[email protected]b0950a72009-09-29 23:16:172709bool RenderView::DownloadImage(int id, const GURL& image_url, int image_size) {
2710 // Make sure webview was not shut down.
2711 if (!webview())
2712 return false;
2713 // Create an image resource fetcher and assign it with a call back object.
2714 image_fetchers_.insert(new ImageResourceFetcher(
[email protected]26aa0482009-09-30 16:55:272715 image_url, webview()->mainFrame(), id, image_size,
[email protected]b0950a72009-09-29 23:16:172716 NewCallback(this, &RenderView::DidDownloadImage)));
2717 return true;
2718}
2719
2720void RenderView::DidDownloadImage(ImageResourceFetcher* fetcher,
initial.commit09911bf2008-07-26 23:55:292721 const SkBitmap& image) {
[email protected]b0950a72009-09-29 23:16:172722 // Notify requester of image download status.
[email protected]51bd36612009-10-20 22:49:472723 Send(new ViewHostMsg_DidDownloadFavIcon(routing_id_,
2724 fetcher->id(),
2725 fetcher->image_url(),
2726 image.isNull(),
2727 image));
[email protected]b0950a72009-09-29 23:16:172728 // Dispose of the image fetcher.
2729 DCHECK(image_fetchers_.find(fetcher) != image_fetchers_.end());
2730 image_fetchers_.erase(fetcher);
2731 // We're in the callback from the ImageResourceFetcher, best to delay
2732 // deletion.
2733 MessageLoop::current()->DeleteSoon(FROM_HERE, fetcher);
initial.commit09911bf2008-07-26 23:55:292734}
2735
[email protected]bf5c2ff392009-07-08 16:24:332736void RenderView::OnDownloadFavIcon(int id,
2737 const GURL& image_url,
2738 int image_size) {
[email protected]f11ca0732009-04-11 00:09:342739 bool data_image_failed = false;
2740 if (image_url.SchemeIs("data")) {
2741 SkBitmap data_image = ImageFromDataUrl(image_url);
2742 data_image_failed = data_image.empty();
2743 if (!data_image_failed) {
[email protected]bf5c2ff392009-07-08 16:24:332744 Send(new ViewHostMsg_DidDownloadFavIcon(routing_id_, id, image_url, false,
2745 data_image));
[email protected]f11ca0732009-04-11 00:09:342746 }
2747 }
2748
[email protected]bf5c2ff392009-07-08 16:24:332749 if (data_image_failed ||
[email protected]b0950a72009-09-29 23:16:172750 !DownloadImage(id, image_url, image_size)) {
[email protected]bf5c2ff392009-07-08 16:24:332751 Send(new ViewHostMsg_DidDownloadFavIcon(routing_id_, id, image_url, true,
2752 SkBitmap()));
2753 }
initial.commit09911bf2008-07-26 23:55:292754}
2755
[email protected]f11ca0732009-04-11 00:09:342756SkBitmap RenderView::ImageFromDataUrl(const GURL& url) const {
2757 std::string mime_type, char_set, data;
2758 if (net::DataURL::Parse(url, &mime_type, &char_set, &data) && !data.empty()) {
2759 // Decode the favicon using WebKit's image decoder.
2760 webkit_glue::ImageDecoder decoder(gfx::Size(kFavIconSize, kFavIconSize));
2761 const unsigned char* src_data =
2762 reinterpret_cast<const unsigned char*>(&data[0]);
2763
2764 return decoder.Decode(src_data, data.size());
2765 }
2766 return SkBitmap();
2767}
2768
initial.commit09911bf2008-07-26 23:55:292769void RenderView::OnGetApplicationInfo(int page_id) {
2770 webkit_glue::WebApplicationInfo app_info;
2771 if (page_id == page_id_)
2772 webkit_glue::GetApplicationInfo(webview(), &app_info);
2773
2774 // Prune out any data URLs in the set of icons. The browser process expects
2775 // any icon with a data URL to have originated from a favicon. We don't want
2776 // to decode arbitrary data URLs in the browser process. See
2777 // http://b/issue?id=1162972
2778 for (size_t i = 0; i < app_info.icons.size(); ++i) {
[email protected]6de74452009-02-25 18:04:592779 if (app_info.icons[i].url.SchemeIs(chrome::kDataScheme)) {
initial.commit09911bf2008-07-26 23:55:292780 app_info.icons.erase(app_info.icons.begin() + i);
2781 --i;
2782 }
2783 }
2784
2785 Send(new ViewHostMsg_DidGetApplicationInfo(routing_id_, page_id, app_info));
2786}
2787
[email protected]7ccddb8c2009-08-04 17:36:552788GURL RenderView::GetAlternateErrorPageURL(const GURL& failed_url,
initial.commit09911bf2008-07-26 23:55:292789 ErrorPageType error_type) {
[email protected]7ccddb8c2009-08-04 17:36:552790 if (failed_url.SchemeIsSecure()) {
initial.commit09911bf2008-07-26 23:55:292791 // If the URL that failed was secure, then the embedding web page was not
2792 // expecting a network attacker to be able to manipulate its contents. As
2793 // we fetch alternate error pages over HTTP, we would be allowing a network
2794 // attacker to manipulate the contents of the response if we tried to use
2795 // the link doctor here.
2796 return GURL::EmptyGURL();
2797 }
2798
2799 // Grab the base URL from the browser process.
2800 if (!alternate_error_page_url_.is_valid())
2801 return GURL::EmptyGURL();
2802
2803 // Strip query params from the failed URL.
2804 GURL::Replacements remove_params;
2805 remove_params.ClearUsername();
2806 remove_params.ClearPassword();
2807 remove_params.ClearQuery();
2808 remove_params.ClearRef();
[email protected]7ccddb8c2009-08-04 17:36:552809 const GURL url_to_send = failed_url.ReplaceComponents(remove_params);
initial.commit09911bf2008-07-26 23:55:292810
2811 // Construct the query params to send to link doctor.
2812 std::string params(alternate_error_page_url_.query());
2813 params.append("&url=");
2814 params.append(EscapeQueryParamValue(url_to_send.spec()));
2815 params.append("&sourceid=chrome");
2816 params.append("&error=");
2817 switch (error_type) {
2818 case DNS_ERROR:
2819 params.append("dnserror");
2820 break;
2821
2822 case HTTP_404:
2823 params.append("http404");
2824 break;
2825
[email protected]5df266ac2008-10-15 19:50:132826 case CONNECTION_ERROR:
[email protected]e1f934b2009-01-26 20:41:332827 params.append("connectionfailure");
[email protected]5df266ac2008-10-15 19:50:132828 break;
2829
initial.commit09911bf2008-07-26 23:55:292830 default:
2831 NOTREACHED() << "unknown ErrorPageType";
2832 }
2833
2834 // OK, build the final url to return.
2835 GURL::Replacements link_doctor_params;
2836 link_doctor_params.SetQueryStr(params);
2837 GURL url = alternate_error_page_url_.ReplaceComponents(link_doctor_params);
2838 return url;
2839}
2840
[email protected]6069da8c2009-10-20 20:33:492841void RenderView::OnFind(int request_id, const string16& search_text,
2842 const WebFindOptions& options) {
[email protected]26aa0482009-09-30 16:55:272843 WebFrame* main_frame = webview()->mainFrame();
[email protected]b4bb2502009-10-01 22:35:272844 WebFrame* frame_after_main = main_frame->traverseNext(true);
[email protected]26aa0482009-09-30 16:55:272845 WebFrame* focused_frame = webview()->focusedFrame();
initial.commit09911bf2008-07-26 23:55:292846 WebFrame* search_frame = focused_frame; // start searching focused frame.
2847
2848 bool multi_frame = (frame_after_main != main_frame);
2849
2850 // If we have multiple frames, we don't want to wrap the search within the
2851 // frame, so we check here if we only have main_frame in the chain.
2852 bool wrap_within_frame = !multi_frame;
2853
[email protected]b3f2b912009-04-09 16:18:522854 WebRect selection_rect;
initial.commit09911bf2008-07-26 23:55:292855 bool result = false;
2856
[email protected]7830da3e2009-11-06 16:27:262857 // If something is selected when we start searching it means we cannot just
2858 // increment the current match ordinal; we need to re-generate it.
2859 WebRange current_selection = focused_frame->selectionRange();
2860
initial.commit09911bf2008-07-26 23:55:292861 do {
[email protected]dd7daa82009-08-10 05:46:452862 result = search_frame->find(
[email protected]7ea066a2009-04-06 20:21:592863 request_id, search_text, options, wrap_within_frame, &selection_rect);
initial.commit09911bf2008-07-26 23:55:292864
2865 if (!result) {
2866 // don't leave text selected as you move to the next frame.
[email protected]a100d76bb2009-08-14 17:50:222867 search_frame->executeCommand(WebString::fromUTF8("Unselect"));
initial.commit09911bf2008-07-26 23:55:292868
2869 // Find the next frame, but skip the invisible ones.
2870 do {
2871 // What is the next frame to search? (we might be going backwards). Note
2872 // that we specify wrap=true so that search_frame never becomes NULL.
[email protected]7ea066a2009-04-06 20:21:592873 search_frame = options.forward ?
[email protected]b4bb2502009-10-01 22:35:272874 search_frame->traverseNext(true) :
2875 search_frame->traversePrevious(true);
[email protected]dd7daa82009-08-10 05:46:452876 } while (!search_frame->hasVisibleContent() &&
2877 search_frame != focused_frame);
initial.commit09911bf2008-07-26 23:55:292878
[email protected]884db412008-11-24 23:46:502879 // Make sure selection doesn't affect the search operation in new frame.
[email protected]a100d76bb2009-08-14 17:50:222880 search_frame->executeCommand(WebString::fromUTF8("Unselect"));
initial.commit09911bf2008-07-26 23:55:292881
2882 // If we have multiple frames and we have wrapped back around to the
2883 // focused frame, we need to search it once more allowing wrap within
2884 // the frame, otherwise it will report 'no match' if the focused frame has
2885 // reported matches, but no frames after the focused_frame contain a
2886 // match for the search word(s).
2887 if (multi_frame && search_frame == focused_frame) {
[email protected]dd7daa82009-08-10 05:46:452888 result = search_frame->find(
[email protected]7ea066a2009-04-06 20:21:592889 request_id, search_text, options, true, // Force wrapping.
2890 &selection_rect);
initial.commit09911bf2008-07-26 23:55:292891 }
2892 }
2893
[email protected]26aa0482009-09-30 16:55:272894 webview()->setFocusedFrame(search_frame);
initial.commit09911bf2008-07-26 23:55:292895 } while (!result && search_frame != focused_frame);
2896
[email protected]7830da3e2009-11-06 16:27:262897 if (options.findNext && current_selection.isNull()) {
[email protected]4f3dc372009-02-24 00:10:292898 // Force the main_frame to report the actual count.
[email protected]dd7daa82009-08-10 05:46:452899 main_frame->increaseMatchCount(0, request_id);
[email protected]4f3dc372009-02-24 00:10:292900 } else {
2901 // If nothing is found, set result to "0 of 0", otherwise, set it to
2902 // "-1 of 1" to indicate that we found at least one item, but we don't know
2903 // yet what is active.
2904 int ordinal = result ? -1 : 0; // -1 here means, we might know more later.
2905 int match_count = result ? 1 : 0; // 1 here means possibly more coming.
initial.commit09911bf2008-07-26 23:55:292906
[email protected]4f3dc372009-02-24 00:10:292907 // If we find no matches then this will be our last status update.
2908 // Otherwise the scoping effort will send more results.
2909 bool final_status_update = !result;
initial.commit09911bf2008-07-26 23:55:292910
[email protected]4f3dc372009-02-24 00:10:292911 // Send the search result over to the browser process.
[email protected]4f999132009-03-31 18:08:402912 Send(new ViewHostMsg_Find_Reply(routing_id_,
[email protected]7ea066a2009-04-06 20:21:592913 request_id,
[email protected]4f3dc372009-02-24 00:10:292914 match_count,
2915 selection_rect,
2916 ordinal,
2917 final_status_update));
initial.commit09911bf2008-07-26 23:55:292918
initial.commit09911bf2008-07-26 23:55:292919 // Scoping effort begins, starting with the mainframe.
2920 search_frame = main_frame;
2921
[email protected]dd7daa82009-08-10 05:46:452922 main_frame->resetMatchCount();
initial.commit09911bf2008-07-26 23:55:292923
2924 do {
2925 // Cancel all old scoping requests before starting a new one.
[email protected]dd7daa82009-08-10 05:46:452926 search_frame->cancelPendingScopingEffort();
initial.commit09911bf2008-07-26 23:55:292927
2928 // We don't start another scoping effort unless at least one match has
2929 // been found.
2930 if (result) {
2931 // Start new scoping request. If the scoping function determines that it
2932 // needs to scope, it will defer until later.
[email protected]dd7daa82009-08-10 05:46:452933 search_frame->scopeStringMatches(request_id,
[email protected]7ea066a2009-04-06 20:21:592934 search_text,
2935 options,
initial.commit09911bf2008-07-26 23:55:292936 true); // reset the tickmarks
2937 }
2938
2939 // Iterate to the next frame. The frame will not necessarily scope, for
2940 // example if it is not visible.
[email protected]b4bb2502009-10-01 22:35:272941 search_frame = search_frame->traverseNext(true);
initial.commit09911bf2008-07-26 23:55:292942 } while (search_frame != main_frame);
2943 }
2944}
2945
[email protected]5c4266922009-07-10 16:41:272946void RenderView::OnDeterminePageText() {
2947 if (!is_loading_) {
2948 if (!webview())
2949 return;
[email protected]26aa0482009-09-30 16:55:272950 WebFrame* main_frame = webview()->mainFrame();
[email protected]5c4266922009-07-10 16:41:272951 std::wstring contents;
2952 CaptureText(main_frame, &contents);
2953 Send(new ViewMsg_DeterminePageText_Reply(routing_id_, contents));
2954 determine_page_text_after_loading_stops_ = false;
2955 return;
2956 }
2957
2958 // We set |determine_page_text_after_loading_stops_| true here so that,
2959 // after page has been loaded completely, the text in the page is captured.
2960 determine_page_text_after_loading_stops_ = true;
2961}
2962
initial.commit09911bf2008-07-26 23:55:292963void RenderView::DnsPrefetch(const std::vector<std::string>& host_names) {
2964 Send(new ViewHostMsg_DnsPrefetch(host_names));
2965}
2966
[email protected]630e26b2008-10-14 22:55:172967void RenderView::OnZoom(int function) {
2968 static const bool kZoomIsTextOnly = false;
2969 switch (function) {
2970 case PageZoom::SMALLER:
[email protected]26aa0482009-09-30 16:55:272971 webview()->zoomOut(kZoomIsTextOnly);
initial.commit09911bf2008-07-26 23:55:292972 break;
[email protected]630e26b2008-10-14 22:55:172973 case PageZoom::STANDARD:
[email protected]26aa0482009-09-30 16:55:272974 webview()->zoomDefault();
initial.commit09911bf2008-07-26 23:55:292975 break;
[email protected]630e26b2008-10-14 22:55:172976 case PageZoom::LARGER:
[email protected]26aa0482009-09-30 16:55:272977 webview()->zoomIn(kZoomIsTextOnly);
initial.commit09911bf2008-07-26 23:55:292978 break;
2979 default:
2980 NOTREACHED();
2981 }
2982}
2983
[email protected]41fc0322009-09-04 22:23:402984void RenderView::OnSetPageEncoding(const std::string& encoding_name) {
[email protected]26aa0482009-09-30 16:55:272985 webview()->setPageEncoding(WebString::fromUTF8(encoding_name));
initial.commit09911bf2008-07-26 23:55:292986}
2987
[email protected]a697f4c2009-09-14 22:30:182988void RenderView::OnResetPageEncodingToDefault() {
[email protected]26aa0482009-09-30 16:55:272989 WebString no_encoding;
2990 webview()->setPageEncoding(no_encoding);
[email protected]a697f4c2009-09-14 22:30:182991}
2992
[email protected]dd7daa82009-08-10 05:46:452993WebFrame* RenderView::GetChildFrame(const std::wstring& xpath) const {
2994 if (xpath.empty())
[email protected]26aa0482009-09-30 16:55:272995 return webview()->mainFrame();
[email protected]dd7daa82009-08-10 05:46:452996
2997 // xpath string can represent a frame deep down the tree (across multiple
2998 // frame DOMs).
2999 // Example, /html/body/table/tbody/tr/td/iframe\n/frameset/frame[0]
3000 // should break into 2 xpaths
3001 // /html/body/table/tbody/tr/td/iframe & /frameset/frame[0]
3002
[email protected]26aa0482009-09-30 16:55:273003 WebFrame* frame = webview()->mainFrame();
[email protected]dd7daa82009-08-10 05:46:453004
3005 std::wstring xpath_remaining = xpath;
3006 while (!xpath_remaining.empty()) {
3007 std::wstring::size_type delim_pos = xpath_remaining.find_first_of(L'\n');
3008 std::wstring xpath_child;
3009 if (delim_pos != std::wstring::npos) {
3010 xpath_child = xpath_remaining.substr(0, delim_pos);
3011 xpath_remaining.erase(0, delim_pos + 1);
3012 } else {
3013 xpath_remaining.swap(xpath_child);
3014 }
3015 frame = frame->findChildByExpression(WideToUTF16Hack(xpath_child));
initial.commit09911bf2008-07-26 23:55:293016 }
3017
[email protected]dd7daa82009-08-10 05:46:453018 return frame;
initial.commit09911bf2008-07-26 23:55:293019}
3020
[email protected]f29acf52008-11-03 20:08:333021void RenderView::EvaluateScript(const std::wstring& frame_xpath,
3022 const std::wstring& script) {
initial.commit09911bf2008-07-26 23:55:293023 WebFrame* web_frame = GetChildFrame(frame_xpath);
3024 if (!web_frame)
3025 return;
3026
[email protected]dd7daa82009-08-10 05:46:453027 web_frame->executeScript(WebScriptSource(WideToUTF16Hack(script)));
initial.commit09911bf2008-07-26 23:55:293028}
3029
[email protected]1810e132009-03-24 23:35:483030void RenderView::InsertCSS(const std::wstring& frame_xpath,
[email protected]ffaef0c2009-09-15 17:08:083031 const std::string& css,
3032 const std::string& id) {
[email protected]1810e132009-03-24 23:35:483033 WebFrame* web_frame = GetChildFrame(frame_xpath);
3034 if (!web_frame)
3035 return;
3036
[email protected]ffaef0c2009-09-15 17:08:083037 web_frame->insertStyleText(WebString::fromUTF8(css), WebString::fromUTF8(id));
[email protected]1810e132009-03-24 23:35:483038}
3039
initial.commit09911bf2008-07-26 23:55:293040void RenderView::OnScriptEvalRequest(const std::wstring& frame_xpath,
3041 const std::wstring& jscript) {
[email protected]f29acf52008-11-03 20:08:333042 EvaluateScript(frame_xpath, jscript);
initial.commit09911bf2008-07-26 23:55:293043}
3044
[email protected]1810e132009-03-24 23:35:483045void RenderView::OnCSSInsertRequest(const std::wstring& frame_xpath,
[email protected]ffaef0c2009-09-15 17:08:083046 const std::string& css,
3047 const std::string& id) {
3048 InsertCSS(frame_xpath, css, id);
[email protected]ae461542009-06-19 19:03:413049
3050 // Notify RenderViewHost that css has been inserted into the frame.
3051 Send(new ViewHostMsg_OnCSSInserted(routing_id_));
[email protected]1810e132009-03-24 23:35:483052}
3053
[email protected]7ea066a2009-04-06 20:21:593054void RenderView::OnAddMessageToConsole(
3055 const string16& frame_xpath,
3056 const string16& message,
3057 const WebConsoleMessage::Level& level) {
3058 WebFrame* web_frame = GetChildFrame(UTF16ToWideHack(frame_xpath));
[email protected]0dea3ea2009-03-31 23:30:593059 if (web_frame)
[email protected]dd7daa82009-08-10 05:46:453060 web_frame->addMessageToConsole(WebConsoleMessage(level, message));
initial.commit09911bf2008-07-26 23:55:293061}
3062
[email protected]81e63782009-02-27 19:35:093063void RenderView::OnAllowBindings(int enabled_bindings_flags) {
3064 enabled_bindings_ |= enabled_bindings_flags;
initial.commit09911bf2008-07-26 23:55:293065}
3066
3067void RenderView::OnSetDOMUIProperty(const std::string& name,
3068 const std::string& value) {
[email protected]81e63782009-02-27 19:35:093069 DCHECK(BindingsPolicy::is_dom_ui_enabled(enabled_bindings_));
initial.commit09911bf2008-07-26 23:55:293070 dom_ui_bindings_.SetProperty(name, value);
3071}
3072
3073void RenderView::OnReservePageIDRange(int size_of_range) {
3074 next_page_id_ += size_of_range + 1;
3075}
3076
[email protected]e80c73b2009-04-07 23:24:583077void RenderView::OnDragSourceEndedOrMoved(const gfx::Point& client_point,
3078 const gfx::Point& screen_point,
[email protected]1d9f4132009-09-08 17:29:253079 bool ended,
3080 WebDragOperation op) {
[email protected]5f9ae6c2009-07-08 02:38:033081 if (ended) {
[email protected]26aa0482009-09-30 16:55:273082 webview()->dragSourceEndedAt(client_point, screen_point, op);
[email protected]5f9ae6c2009-07-08 02:38:033083 }
initial.commit09911bf2008-07-26 23:55:293084}
3085
3086void RenderView::OnDragSourceSystemDragEnded() {
[email protected]26aa0482009-09-30 16:55:273087 webview()->dragSourceSystemDragEnded();
initial.commit09911bf2008-07-26 23:55:293088}
3089
initial.commit09911bf2008-07-26 23:55:293090void RenderView::OnFormFill(const FormData& form) {
3091 webkit_glue::FillForm(this->webview(), form);
3092}
3093
3094void RenderView::OnFillPasswordForm(
[email protected]daa8c58e2009-06-15 17:21:103095 const webkit_glue::PasswordFormDomManager::FillData& form_data) {
initial.commit09911bf2008-07-26 23:55:293096 webkit_glue::FillPasswordForm(this->webview(), form_data);
3097}
3098
3099void RenderView::OnDragTargetDragEnter(const WebDropData& drop_data,
[email protected]e80c73b2009-04-07 23:24:583100 const gfx::Point& client_point,
[email protected]1d9f4132009-09-08 17:29:253101 const gfx::Point& screen_point,
3102 WebDragOperationsMask ops) {
[email protected]26aa0482009-09-30 16:55:273103 WebDragOperation operation = webview()->dragTargetDragEnter(
[email protected]e80c73b2009-04-07 23:24:583104 drop_data.ToDragData(),
3105 drop_data.identity,
3106 client_point,
[email protected]1d9f4132009-09-08 17:29:253107 screen_point,
3108 ops);
initial.commit09911bf2008-07-26 23:55:293109
[email protected]1d9f4132009-09-08 17:29:253110 Send(new ViewHostMsg_UpdateDragCursor(routing_id_, operation));
initial.commit09911bf2008-07-26 23:55:293111}
3112
[email protected]e80c73b2009-04-07 23:24:583113void RenderView::OnDragTargetDragOver(const gfx::Point& client_point,
[email protected]1d9f4132009-09-08 17:29:253114 const gfx::Point& screen_point,
3115 WebDragOperationsMask ops) {
[email protected]26aa0482009-09-30 16:55:273116 WebDragOperation operation = webview()->dragTargetDragOver(
[email protected]1d9f4132009-09-08 17:29:253117 client_point,
3118 screen_point,
3119 ops);
initial.commit09911bf2008-07-26 23:55:293120
[email protected]1d9f4132009-09-08 17:29:253121 Send(new ViewHostMsg_UpdateDragCursor(routing_id_, operation));
initial.commit09911bf2008-07-26 23:55:293122}
3123
3124void RenderView::OnDragTargetDragLeave() {
[email protected]26aa0482009-09-30 16:55:273125 webview()->dragTargetDragLeave();
initial.commit09911bf2008-07-26 23:55:293126}
3127
[email protected]e80c73b2009-04-07 23:24:583128void RenderView::OnDragTargetDrop(const gfx::Point& client_point,
3129 const gfx::Point& screen_point) {
[email protected]26aa0482009-09-30 16:55:273130 webview()->dragTargetDrop(client_point, screen_point);
initial.commit09911bf2008-07-26 23:55:293131}
3132
3133void RenderView::OnUpdateWebPreferences(const WebPreferences& prefs) {
[email protected]2fab253a2009-08-17 23:00:593134 webkit_preferences_ = prefs;
3135 webkit_preferences_.Apply(webview());
initial.commit09911bf2008-07-26 23:55:293136}
3137
3138void RenderView::OnSetAltErrorPageURL(const GURL& url) {
3139 alternate_error_page_url_ = url;
3140}
3141
initial.commit09911bf2008-07-26 23:55:293142void RenderView::OnInstallMissingPlugin() {
3143 // This could happen when the first default plugin is deleted.
[email protected]f103ab72009-09-02 17:10:593144 if (first_default_plugin_)
3145 first_default_plugin_->InstallMissingPlugin();
initial.commit09911bf2008-07-26 23:55:293146}
3147
[email protected]b62d1a8c2009-01-13 23:54:573148void RenderView::OnFileChooserResponse(
[email protected]561abe62009-04-06 18:08:343149 const std::vector<FilePath>& file_names) {
[email protected]8029f5672009-03-20 22:33:363150 // This could happen if we navigated to a different page before the user
3151 // closed the chooser.
[email protected]a1128322009-10-06 18:38:463152 if (!file_chooser_completion_)
[email protected]8029f5672009-03-20 22:33:363153 return;
3154
[email protected]6069da8c2009-10-20 20:33:493155 WebVector<WebString> ws_file_names(file_names.size());
[email protected]a1128322009-10-06 18:38:463156 for (size_t i = 0; i < file_names.size(); ++i) {
3157 ws_file_names[i] = webkit_glue::FilePathToWebString(file_names[i]);
3158 }
3159
3160 file_chooser_completion_->didChooseFile(ws_file_names);
3161 // Reset the chooser pointer
3162 file_chooser_completion_ = NULL;
initial.commit09911bf2008-07-26 23:55:293163}
3164
3165void RenderView::OnEnableViewSourceMode() {
3166 if (!webview())
3167 return;
[email protected]26aa0482009-09-30 16:55:273168 WebFrame* main_frame = webview()->mainFrame();
initial.commit09911bf2008-07-26 23:55:293169 if (!main_frame)
3170 return;
3171
[email protected]dd7daa82009-08-10 05:46:453172 main_frame->enableViewSourceMode(true);
initial.commit09911bf2008-07-26 23:55:293173}
3174
[email protected]ab32b16c2009-10-16 14:57:253175void RenderView::OnEnablePreferredSizeChangedMode() {
3176 send_preferred_size_changes_ = true;
[email protected]0666aef2009-05-13 19:48:083177}
3178
[email protected]80d96fa2009-06-10 22:34:513179void RenderView::OnSetRendererPrefs(const RendererPreferences& renderer_prefs) {
3180 renderer_preferences_ = renderer_prefs;
[email protected]6e282c92009-07-24 01:19:373181 UpdateFontRenderingFromRendererPrefs();
[email protected]033970a2009-10-14 16:45:053182#if defined(OS_LINUX) && !defined(TOOLKIT_VIEWS)
[email protected]1c83eb42009-09-11 21:08:413183 WebColorName name = WebKit::WebColorWebkitFocusRingColor;
3184 WebKit::setNamedColors(&name, &renderer_prefs.focus_ring_color, 1);
[email protected]7a74e102009-09-03 00:16:563185#endif
[email protected]80d96fa2009-06-10 22:34:513186}
3187
[email protected]952cb702009-10-07 05:50:283188void RenderView::OnMediaPlayerActionAt(const gfx::Point& location,
3189 const WebMediaPlayerAction& action) {
3190 if (webview())
3191 webview()->performMediaPlayerAction(action, location);
[email protected]581b87eb2009-07-23 23:06:563192}
3193
[email protected]7b291f92009-08-14 05:43:533194void RenderView::OnNotifyRendererViewType(ViewType::Type type) {
[email protected]078b34612009-09-19 19:31:513195 // When this is first set, the bindings aren't fully loaded. We only need
3196 // to call through this API after the page has already been loaded. It's
3197 // also called in didCreateDocumentElement to bootstrap.
3198 if (view_type_ != ViewType::INVALID) {
3199 if (type == ViewType::EXTENSION_MOLE ||
3200 type == ViewType::EXTENSION_TOOLSTRIP) {
3201 ExtensionProcessBindings::SetViewType(webview(), type);
3202 }
3203 }
[email protected]7b291f92009-08-14 05:43:533204 view_type_ = type;
3205}
3206
3207void RenderView::OnUpdateBrowserWindowId(int window_id) {
3208 browser_window_id_ = window_id;
3209}
3210
initial.commit09911bf2008-07-26 23:55:293211void RenderView::OnUpdateBackForwardListCount(int back_list_count,
3212 int forward_list_count) {
3213 history_back_list_count_ = back_list_count;
3214 history_forward_list_count_ = forward_list_count;
3215}
3216
[email protected]266eb6f2008-09-30 23:56:503217void RenderView::OnGetAccessibilityInfo(
[email protected]6a983b42009-03-20 20:12:253218 const webkit_glue::WebAccessibility::InParams& in_params,
3219 webkit_glue::WebAccessibility::OutParams* out_params) {
[email protected]6c8afae52009-01-22 02:24:573220#if defined(OS_WIN)
[email protected]c7287a92009-11-04 20:06:153221 if (!accessibility_.get()) {
3222 // TODO(dglazkov): Once implemented for all ports, remove lazy
3223 // instantiation of accessibility_.
3224 accessibility_.reset(WebAccessibilityCache::create());
3225 accessibility_->initialize(webview());
[email protected]6a983b42009-03-20 20:12:253226 }
[email protected]266eb6f2008-09-30 23:56:503227
[email protected]c7287a92009-11-04 20:06:153228 webkit_glue::WebAccessibility::GetAccObjInfo(accessibility_.get(),
3229 in_params,
3230 out_params);
3231
[email protected]6c8afae52009-01-22 02:24:573232#else // defined(OS_WIN)
3233 // TODO(port): accessibility not yet implemented
3234 NOTIMPLEMENTED();
3235#endif
[email protected]266eb6f2008-09-30 23:56:503236}
3237
[email protected]6a983b42009-03-20 20:12:253238void RenderView::OnClearAccessibilityInfo(int acc_obj_id, bool clear_all) {
[email protected]6c8afae52009-01-22 02:24:573239#if defined(OS_WIN)
[email protected]c7287a92009-11-04 20:06:153240 if (!accessibility_.get()) {
[email protected]266eb6f2008-09-30 23:56:503241 // If accessibility is not activated, ignore clearing message.
3242 return;
3243 }
[email protected]e846d0d2009-05-20 00:53:063244
[email protected]c7287a92009-11-04 20:06:153245 if (clear_all) {
3246 accessibility_->clear();
[email protected]266eb6f2008-09-30 23:56:503247 return;
[email protected]c7287a92009-11-04 20:06:153248 }
3249
3250 accessibility_->remove(acc_obj_id);
[email protected]e846d0d2009-05-20 00:53:063251
[email protected]6c8afae52009-01-22 02:24:573252#else // defined(OS_WIN)
3253 // TODO(port): accessibility not yet implemented
3254 NOTIMPLEMENTED();
3255#endif
[email protected]266eb6f2008-09-30 23:56:503256}
3257
initial.commit09911bf2008-07-26 23:55:293258void RenderView::OnGetAllSavableResourceLinksForCurrentPage(
3259 const GURL& page_url) {
3260 // Prepare list to storage all savable resource links.
3261 std::vector<GURL> resources_list;
3262 std::vector<GURL> referrers_list;
3263 std::vector<GURL> frames_list;
3264 webkit_glue::SavableResourcesResult result(&resources_list,
3265 &referrers_list,
3266 &frames_list);
3267
[email protected]dbeb3952009-10-13 18:01:183268 if (!webkit_glue::GetAllSavableResourceLinksForCurrentPage(
3269 webview(),
3270 page_url,
3271 &result,
3272 chrome::kSavableSchemes)) {
initial.commit09911bf2008-07-26 23:55:293273 // If something is wrong when collecting all savable resource links,
3274 // send empty list to embedder(browser) to tell it failed.
3275 referrers_list.clear();
3276 resources_list.clear();
3277 frames_list.clear();
3278 }
3279
3280 // Send result of all savable resource links to embedder.
3281 Send(new ViewHostMsg_SendCurrentPageAllSavableResourceLinks(routing_id_,
3282 resources_list,
3283 referrers_list,
3284 frames_list));
3285}
3286
3287void RenderView::OnGetSerializedHtmlDataForCurrentPageWithLocalLinks(
[email protected]f6b48532009-02-12 01:56:323288 const std::vector<GURL>& links,
[email protected]fde6714d12009-02-18 22:39:313289 const std::vector<FilePath>& local_paths,
3290 const FilePath& local_directory_name) {
[email protected]26aa0482009-09-30 16:55:273291 webkit_glue::DomSerializer dom_serializer(webview()->mainFrame(),
initial.commit09911bf2008-07-26 23:55:293292 true,
3293 this,
3294 links,
3295 local_paths,
3296 local_directory_name);
3297 dom_serializer.SerializeDom();
3298}
3299
3300void RenderView::DidSerializeDataForFrame(const GURL& frame_url,
3301 const std::string& data, PageSavingSerializationStatus status) {
3302 Send(new ViewHostMsg_SendSerializedHtmlData(routing_id_,
3303 frame_url, data, static_cast<int32>(status)));
3304}
3305
[email protected]04b4a6c2008-08-02 00:44:473306void RenderView::OnMsgShouldClose() {
[email protected]26aa0482009-09-30 16:55:273307 bool should_close = webview()->dispatchBeforeUnloadEvent();
[email protected]04b4a6c2008-08-02 00:44:473308 Send(new ViewHostMsg_ShouldClose_ACK(routing_id_, should_close));
initial.commit09911bf2008-07-26 23:55:293309}
3310
[email protected]eb6b87a2009-07-24 15:57:393311void RenderView::OnClosePage(const ViewMsg_ClosePage_Params& params) {
initial.commit09911bf2008-07-26 23:55:293312 // TODO(creis): We'd rather use webview()->Close() here, but that currently
3313 // sets the WebView's delegate_ to NULL, preventing any JavaScript dialogs
3314 // in the onunload handler from appearing. For now, we're bypassing that and
3315 // calling the FrameLoader's CloseURL method directly. This should be
3316 // revisited to avoid having two ways to close a page. Having a single way
3317 // to close that can run onunload is also useful for fixing
3318 // http://b/issue?id=753080.
[email protected]26aa0482009-09-30 16:55:273319 WebFrame* main_frame = webview()->mainFrame();
[email protected]7a9b51f2009-06-29 21:28:293320 if (main_frame) {
[email protected]dd7daa82009-08-10 05:46:453321 const GURL& url = main_frame->url();
[email protected]3d9689372009-09-10 04:29:173322 // TODO(davemoore) this code should be removed once willClose() gets
[email protected]7a9b51f2009-06-29 21:28:293323 // called when a page is destroyed. DumpLoadHistograms() is safe to call
3324 // multiple times for the same frame, but it will simplify things.
[email protected]dd7daa82009-08-10 05:46:453325 if (url.SchemeIs(chrome::kHttpScheme) ||
3326 url.SchemeIs(chrome::kHttpsScheme))
[email protected]7a9b51f2009-06-29 21:28:293327 DumpLoadHistograms();
[email protected]7a9b51f2009-06-29 21:28:293328 }
[email protected]26aa0482009-09-30 16:55:273329 webview()->dispatchUnloadEvent();
initial.commit09911bf2008-07-26 23:55:293330
[email protected]eb6b87a2009-07-24 15:57:393331 // Just echo back the params in the ACK.
3332 Send(new ViewHostMsg_ClosePage_ACK(routing_id_, params));
initial.commit09911bf2008-07-26 23:55:293333}
3334
3335void RenderView::OnThemeChanged() {
[email protected]6c8afae52009-01-22 02:24:573336#if defined(OS_WIN)
initial.commit09911bf2008-07-26 23:55:293337 gfx::NativeTheme::instance()->CloseHandles();
3338 gfx::Rect view_rect(0, 0, size_.width(), size_.height());
[email protected]4873c7d2009-07-16 06:36:283339 didInvalidateRect(view_rect);
[email protected]6c8afae52009-01-22 02:24:573340#else // defined(OS_WIN)
3341 // TODO(port): we don't support theming on non-Windows platforms yet
3342 NOTIMPLEMENTED();
3343#endif
initial.commit09911bf2008-07-26 23:55:293344}
3345
[email protected]28790922009-03-09 19:48:373346void RenderView::OnMessageFromExternalHost(const std::string& message,
3347 const std::string& origin,
3348 const std::string& target) {
[email protected]3ac14a052008-08-15 21:22:153349 if (message.empty())
3350 return;
3351
[email protected]28790922009-03-09 19:48:373352 external_host_bindings_.ForwardMessageFromExternalHost(message, origin,
3353 target);
[email protected]3ac14a052008-08-15 21:22:153354}
3355
[email protected]0aa55312008-10-17 21:53:083356void RenderView::OnDisassociateFromPopupCount() {
3357 if (decrement_shared_popup_at_destruction_)
3358 shared_popup_counter_->data--;
3359 shared_popup_counter_ = new SharedRenderViewCounter(0);
3360 decrement_shared_popup_at_destruction_ = false;
3361}
3362
[email protected]15d79e12009-08-02 19:23:453363bool RenderView::MaybeLoadAlternateErrorPage(WebFrame* frame,
3364 const WebURLError& error,
3365 bool replace) {
3366 // We only show alternate error pages in the main frame. They are
3367 // intended to assist the user when navigating, so there is not much
3368 // value in showing them for failed subframes. Ideally, we would be
3369 // able to use the TYPED transition type for this, but that flag is
3370 // not preserved across page reloads.
[email protected]dd7daa82009-08-10 05:46:453371 if (frame->parent())
[email protected]15d79e12009-08-02 19:23:453372 return false;
3373
3374 // Use the alternate error page service if this is a DNS failure or
[email protected]c53976d52009-08-07 18:58:373375 // connection failure.
[email protected]15d79e12009-08-02 19:23:453376 int ec = error.reason;
3377 if (ec != net::ERR_NAME_NOT_RESOLVED &&
3378 ec != net::ERR_CONNECTION_FAILED &&
3379 ec != net::ERR_CONNECTION_REFUSED &&
3380 ec != net::ERR_ADDRESS_UNREACHABLE &&
[email protected]c53976d52009-08-07 18:58:373381 ec != net::ERR_CONNECTION_TIMED_OUT)
[email protected]15d79e12009-08-02 19:23:453382 return false;
3383
3384 const GURL& error_page_url = GetAlternateErrorPageURL(error.unreachableURL,
[email protected]7ccddb8c2009-08-04 17:36:553385 ec == net::ERR_NAME_NOT_RESOLVED ? DNS_ERROR : CONNECTION_ERROR);
[email protected]15d79e12009-08-02 19:23:453386 if (!error_page_url.is_valid())
3387 return false;
3388
3389 // Load an empty page first so there is an immediate response to the error,
3390 // and then kick off a request for the alternate error page.
[email protected]dd7daa82009-08-10 05:46:453391 frame->loadHTMLString(std::string(),
[email protected]15d79e12009-08-02 19:23:453392 GURL(kUnreachableWebDataURL),
3393 error.unreachableURL,
3394 replace);
3395
3396 // Now, create a fetcher for the error page and associate it with the data
3397 // source we just created via the LoadHTMLString call. That way if another
3398 // navigation occurs, the fetcher will get destroyed.
3399 NavigationState* navigation_state =
[email protected]dd7daa82009-08-10 05:46:453400 NavigationState::FromDataSource(frame->provisionalDataSource());
[email protected]15d79e12009-08-02 19:23:453401 navigation_state->set_alt_error_page_fetcher(
3402 new AltErrorPageResourceFetcher(
3403 error_page_url, frame, error,
3404 NewCallback(this, &RenderView::AltErrorPageFinished)));
3405 return true;
3406}
3407
initial.commit09911bf2008-07-26 23:55:293408std::string RenderView::GetAltHTMLForTemplate(
3409 const DictionaryValue& error_strings, int template_resource_id) const {
[email protected]8a16266e2009-09-10 21:08:393410 const base::StringPiece template_html(
initial.commit09911bf2008-07-26 23:55:293411 ResourceBundle::GetSharedInstance().GetRawDataResource(
3412 template_resource_id));
3413
3414 if (template_html.empty()) {
3415 NOTREACHED() << "unable to load template. ID: " << template_resource_id;
3416 return "";
3417 }
[email protected]7cd22a52009-07-14 00:40:253418
initial.commit09911bf2008-07-26 23:55:293419 // "t" is the id of the templates root node.
[email protected]7cd22a52009-07-14 00:40:253420 return jstemplate_builder::GetTemplatesHtml(
initial.commit09911bf2008-07-26 23:55:293421 template_html, &error_strings, "t");
3422}
[email protected]0e79b9e2009-02-13 04:20:483423
[email protected]15d79e12009-08-02 19:23:453424void RenderView::AltErrorPageFinished(WebFrame* frame,
3425 const WebURLError& original_error,
3426 const std::string& html) {
3427 // Here, we replace the blank page we loaded previously.
[email protected]7ccddb8c2009-08-04 17:36:553428
3429 // If we failed to download the alternate error page, fall back to the
3430 // original error page if present. Otherwise, LoadNavigationErrorPage
3431 // will simply display a default error page.
3432 const std::string* html_to_load = &html;
3433 if (html.empty()) {
3434 NavigationState* navigation_state =
[email protected]dd7daa82009-08-10 05:46:453435 NavigationState::FromDataSource(frame->dataSource());
[email protected]7ccddb8c2009-08-04 17:36:553436 html_to_load = &navigation_state->postponed_data();
3437 }
3438 LoadNavigationErrorPage(
3439 frame, WebURLRequest(), original_error, *html_to_load, true);
[email protected]15d79e12009-08-02 19:23:453440}
3441
[email protected]30f75e62009-02-25 22:01:003442void RenderView::OnMoveOrResizeStarted() {
3443 if (webview())
[email protected]acca2a1f2009-10-16 03:53:393444 webview()->hideAutofillPopup();
[email protected]30f75e62009-02-25 22:01:003445}
3446
[email protected]30f75e62009-02-25 22:01:003447void RenderView::OnResize(const gfx::Size& new_size,
3448 const gfx::Rect& resizer_rect) {
3449 if (webview())
[email protected]acca2a1f2009-10-16 03:53:393450 webview()->hideAutofillPopup();
[email protected]30f75e62009-02-25 22:01:003451 RenderWidget::OnResize(new_size, resizer_rect);
3452}
[email protected]0aa477bd2009-03-23 22:21:433453
[email protected]05d478752009-04-08 23:38:163454void RenderView::OnClearFocusedNode() {
3455 if (webview())
[email protected]26aa0482009-09-30 16:55:273456 webview()->clearFocusedNode();
[email protected]05d478752009-04-08 23:38:163457}
3458
[email protected]699ab0d2009-04-23 23:19:143459void RenderView::OnSetBackground(const SkBitmap& background) {
3460 if (webview())
[email protected]b4bb2502009-10-01 22:35:273461 webview()->setIsTransparent(!background.empty());
[email protected]699ab0d2009-04-23 23:19:143462
3463 SetBackground(background);
3464}
3465
[email protected]8c66c5a2009-07-22 17:26:343466void RenderView::OnSetActive(bool active) {
3467 if (webview())
[email protected]b4bb2502009-10-01 22:35:273468 webview()->setIsActive(active);
[email protected]8c66c5a2009-07-22 17:26:343469}
3470
[email protected]309d7a282009-03-24 09:18:273471void RenderView::SendExtensionRequest(const std::string& name,
[email protected]e4dad9fb2009-10-06 18:15:583472 const ListValue& args,
[email protected]c6619182009-05-12 14:59:323473 int request_id,
[email protected]2f25d7b92009-06-10 00:06:473474 bool has_callback) {
[email protected]c6619182009-05-12 14:59:323475 Send(new ViewHostMsg_ExtensionRequest(routing_id_, name, args, request_id,
[email protected]2f25d7b92009-06-10 00:06:473476 has_callback));
[email protected]309d7a282009-03-24 09:18:273477}
3478
[email protected]c6619182009-05-12 14:59:323479void RenderView::OnExtensionResponse(int request_id,
3480 bool success,
3481 const std::string& response,
3482 const std::string& error) {
[email protected]0f6053962009-07-09 19:26:353483 ExtensionProcessBindings::HandleResponse(
3484 request_id, success, response, error);
[email protected]309d7a282009-03-24 09:18:273485}
[email protected]c20210e62009-04-03 21:39:263486
[email protected]078b34612009-09-19 19:31:513487void RenderView::InjectToolstripCSS() {
3488 if (view_type_ != ViewType::EXTENSION_TOOLSTRIP)
3489 return;
3490
3491 static const base::StringPiece toolstrip_css(
3492 ResourceBundle::GetSharedInstance().GetRawDataResource(
3493 IDR_EXTENSION_TOOLSTRIP_CSS));
3494 std::string css = toolstrip_css.as_string();
3495 InsertCSS(L"", css, "ToolstripDefaultCSS");
3496}
3497
[email protected]7120f132009-07-20 21:05:373498void RenderView::OnExtensionMessageInvoke(const std::string& function_name,
3499 const ListValue& args) {
3500 RendererExtensionBindings::Invoke(function_name, args, this);
3501}
3502
[email protected]e7e4f3c2009-04-21 15:24:083503// Dump all load time histograms.
[email protected]c20210e62009-04-03 21:39:263504//
[email protected]7a9b51f2009-06-29 21:28:293505// There are 13 histograms measuring various times.
[email protected]c20210e62009-04-03 21:39:263506// The time points we keep are
3507// request: time document was requested by user
3508// start: time load of document started
[email protected]a2f6bc112009-06-27 16:27:253509// commit: time load of document started
[email protected]7a9b51f2009-06-29 21:28:293510// finish_document: main document loaded, before onload()
[email protected]c20210e62009-04-03 21:39:263511// finish: after onload() and all resources are loaded
[email protected]7a9b51f2009-06-29 21:28:293512// first_paint: first paint performed
3513// first_paint_after_load: first paint performed after load is finished
3514// begin: request if it was user requested, start otherwise
3515//
[email protected]c20210e62009-04-03 21:39:263516// The times that we histogram are
[email protected]a2f6bc112009-06-27 16:27:253517// request->start,
[email protected]7a9b51f2009-06-29 21:28:293518// start->commit,
3519// commit->finish_document,
3520// finish_document->finish,
3521// begin->commit,
3522// begin->finishDoc,
3523// begin->finish,
3524// begin->first_paint,
3525// begin->first_paint_after_load
3526// commit->finishDoc,
3527// commit->first_paint,
3528// commit->first_paint_after_load,
3529// finish->first_paint_after_load,
[email protected]c20210e62009-04-03 21:39:263530//
[email protected]e7e4f3c2009-04-21 15:24:083531// It's possible for the request time not to be set, if a client
3532// redirect had been done (the user never requested the page)
3533// Also, it's possible to load a page without ever laying it out
[email protected]7a9b51f2009-06-29 21:28:293534// so first_paint and first_paint_after_load can be 0.
[email protected]c20210e62009-04-03 21:39:263535void RenderView::DumpLoadHistograms() const {
[email protected]26aa0482009-09-30 16:55:273536 WebFrame* main_frame = webview()->mainFrame();
[email protected]ed3fb032009-06-16 19:50:563537 NavigationState* navigation_state =
[email protected]dd7daa82009-08-10 05:46:453538 NavigationState::FromDataSource(main_frame->dataSource());
[email protected]7a9b51f2009-06-29 21:28:293539 Time finish = navigation_state->finish_load_time();
[email protected]ed3fb032009-06-16 19:50:563540
[email protected]7a9b51f2009-06-29 21:28:293541 // If we've already dumped or we haven't finished loading, do nothing.
3542 if (navigation_state->load_histograms_recorded() || finish.is_null())
3543 return;
[email protected]ed3fb032009-06-16 19:50:563544
[email protected]f8999642009-10-27 21:39:423545 LogNavigationState(navigation_state, main_frame->dataSource());
3546
[email protected]7a9b51f2009-06-29 21:28:293547 Time request = navigation_state->request_time();
3548 Time start = navigation_state->start_load_time();
3549 Time commit = navigation_state->commit_load_time();
3550 Time finish_doc = navigation_state->finish_document_load_time();
3551 Time first_paint = navigation_state->first_paint_time();
3552 Time first_paint_after_load =
3553 navigation_state->first_paint_after_load_time();
[email protected]c20210e62009-04-03 21:39:263554
[email protected]7a9b51f2009-06-29 21:28:293555 Time begin;
3556 // Client side redirects will have no request time.
3557 if (request.is_null()) {
3558 begin = start;
3559 } else {
3560 begin = request;
3561 UMA_HISTOGRAM_MEDIUM_TIMES("Renderer4.RequestToStart", start - request);
[email protected]e7e4f3c2009-04-21 15:24:083562 }
[email protected]7a9b51f2009-06-29 21:28:293563 UMA_HISTOGRAM_MEDIUM_TIMES("Renderer4.StartToCommit", commit - start);
3564 UMA_HISTOGRAM_MEDIUM_TIMES(
3565 "Renderer4.CommitToFinishDoc", finish_doc - commit);
3566 UMA_HISTOGRAM_MEDIUM_TIMES(
3567 "Renderer4.FinishDocToFinish", finish - finish_doc);
3568
3569 UMA_HISTOGRAM_MEDIUM_TIMES("Renderer4.BeginToCommit", commit - begin);
3570 UMA_HISTOGRAM_MEDIUM_TIMES("Renderer4.BeginToFinishDoc", finish_doc - begin);
[email protected]e695fbd62009-06-30 16:31:543571
3572 static const TimeDelta kBeginToFinishMin(TimeDelta::FromMilliseconds(10));
3573 static const TimeDelta kBeginToFinishMax(TimeDelta::FromMinutes(10));
3574 static const size_t kBeginToFinishBucketCount(100);
3575
3576 UMA_HISTOGRAM_CUSTOM_TIMES("Renderer4.BeginToFinish",
3577 finish - begin, kBeginToFinishMin,
3578 kBeginToFinishMax, kBeginToFinishBucketCount);
[email protected]0a32257a2009-07-09 18:10:413579 UMA_HISTOGRAM_CUSTOM_TIMES("Renderer4.StartToFinish",
3580 finish - start, kBeginToFinishMin,
3581 kBeginToFinishMax, kBeginToFinishBucketCount);
3582 if (!request.is_null())
3583 UMA_HISTOGRAM_CUSTOM_TIMES("Renderer4.RequestToFinish",
3584 finish - request, kBeginToFinishMin,
3585 kBeginToFinishMax, kBeginToFinishBucketCount);
[email protected]e695fbd62009-06-30 16:31:543586
[email protected]36285b52009-06-30 19:10:003587 static bool use_dns_histogram(FieldTrialList::Find("DnsImpact") &&
3588 !FieldTrialList::Find("DnsImpact")->group_name().empty());
[email protected]0a32257a2009-07-09 18:10:413589 if (use_dns_histogram) {
[email protected]36285b52009-06-30 19:10:003590 UMA_HISTOGRAM_CUSTOM_TIMES(
3591 FieldTrial::MakeName("Renderer4.BeginToFinish", "DnsImpact").data(),
3592 finish - begin, kBeginToFinishMin,
3593 kBeginToFinishMax, kBeginToFinishBucketCount);
[email protected]0a32257a2009-07-09 18:10:413594 UMA_HISTOGRAM_CUSTOM_TIMES(
3595 FieldTrial::MakeName("Renderer4.StartToFinish", "DnsImpact").data(),
3596 finish - start, kBeginToFinishMin,
3597 kBeginToFinishMax, kBeginToFinishBucketCount);
3598 if (!request.is_null())
3599 UMA_HISTOGRAM_CUSTOM_TIMES(
3600 FieldTrial::MakeName("Renderer4.RequestToFinish", "DnsImpact").data(),
3601 finish - request, kBeginToFinishMin,
3602 kBeginToFinishMax, kBeginToFinishBucketCount);
3603 }
[email protected]e695fbd62009-06-30 16:31:543604
[email protected]36285b52009-06-30 19:10:003605 static bool use_sdch_histogram(FieldTrialList::Find("GlobalSdch") &&
3606 !FieldTrialList::Find("GlobalSdch")->group_name().empty());
[email protected]0a32257a2009-07-09 18:10:413607 if (use_sdch_histogram) {
[email protected]36285b52009-06-30 19:10:003608 UMA_HISTOGRAM_CUSTOM_TIMES(
3609 FieldTrial::MakeName("Renderer4.BeginToFinish", "GlobalSdch").data(),
3610 finish - begin, kBeginToFinishMin,
3611 kBeginToFinishMax, kBeginToFinishBucketCount);
[email protected]0a32257a2009-07-09 18:10:413612 UMA_HISTOGRAM_CUSTOM_TIMES(
3613 FieldTrial::MakeName("Renderer4.StartToFinish", "GlobalSdch").data(),
3614 finish - start, kBeginToFinishMin,
3615 kBeginToFinishMax, kBeginToFinishBucketCount);
3616 if (!request.is_null())
3617 UMA_HISTOGRAM_CUSTOM_TIMES(
3618 FieldTrial::MakeName("Renderer4.RequestToFinish",
3619 "GlobalSdch").data(),
3620 finish - request, kBeginToFinishMin,
3621 kBeginToFinishMax, kBeginToFinishBucketCount);
3622 }
[email protected]7a9b51f2009-06-29 21:28:293623
[email protected]5fff93f2009-08-02 04:27:343624 static bool use_socket_late_binding_histogram =
3625 FieldTrialList::Find("SocketLateBinding") &&
3626 !FieldTrialList::Find("SocketLateBinding")->group_name().empty();
3627 if (use_socket_late_binding_histogram) {
3628 UMA_HISTOGRAM_CUSTOM_TIMES(
3629 FieldTrial::MakeName("Renderer4.BeginToFinish",
3630 "SocketLateBinding").data(),
3631 finish - begin, kBeginToFinishMin,
3632 kBeginToFinishMax, kBeginToFinishBucketCount);
3633 UMA_HISTOGRAM_CUSTOM_TIMES(
3634 FieldTrial::MakeName("Renderer4.StartToFinish",
3635 "SocketLateBinding").data(),
3636 finish - start, kBeginToFinishMin,
3637 kBeginToFinishMax, kBeginToFinishBucketCount);
3638 if (!request.is_null())
3639 UMA_HISTOGRAM_CUSTOM_TIMES(
3640 FieldTrial::MakeName("Renderer4.RequestToFinish",
3641 "SocketLateBinding").data(),
3642 finish - request, kBeginToFinishMin,
3643 kBeginToFinishMax, kBeginToFinishBucketCount);
3644 }
3645
[email protected]7e05f6c42009-07-11 01:50:483646 static bool use_cache_histogram1(FieldTrialList::Find("CacheSize") &&
3647 !FieldTrialList::Find("CacheSize")->group_name().empty());
3648 if (use_cache_histogram1)
3649 UMA_HISTOGRAM_CUSTOM_TIMES(
3650 FieldTrial::MakeName("Renderer4.StartToFinish", "CacheSize").data(),
3651 finish - start, kBeginToFinishMin,
3652 kBeginToFinishMax, kBeginToFinishBucketCount);
3653
3654 static bool use_cache_histogram2(FieldTrialList::Find("NewEviction") &&
3655 !FieldTrialList::Find("NewEviction")->group_name().empty());
3656 if (use_cache_histogram2)
3657 UMA_HISTOGRAM_CUSTOM_TIMES(
3658 FieldTrial::MakeName("Renderer4.StartToFinish", "NewEviction").data(),
3659 finish - start, kBeginToFinishMin,
3660 kBeginToFinishMax, kBeginToFinishBucketCount);
3661
[email protected]ab0729e2009-09-30 04:42:463662 static bool use_async_tcp(FieldTrialList::Find("AsyncSlowStart") &&
3663 !FieldTrialList::Find("AsyncSlowStart")->group_name().empty());
3664 if (use_async_tcp) {
3665 UMA_HISTOGRAM_CUSTOM_TIMES(
3666 FieldTrial::MakeName("Renderer4.StartToFinish",
3667 "AsyncSlowStart").data(),
3668 finish - start, kBeginToFinishMin,
3669 kBeginToFinishMax, kBeginToFinishBucketCount);
3670 }
3671
[email protected]7a9b51f2009-06-29 21:28:293672 UMA_HISTOGRAM_MEDIUM_TIMES("Renderer4.CommitToFinish", finish - commit);
3673
3674 if (!first_paint.is_null()) {
3675 UMA_HISTOGRAM_MEDIUM_TIMES(
3676 "Renderer4.BeginToFirstPaint", first_paint - begin);
3677 UMA_HISTOGRAM_MEDIUM_TIMES(
3678 "Renderer4.CommitToFirstPaint", first_paint - commit);
[email protected]c20210e62009-04-03 21:39:263679 }
[email protected]7a9b51f2009-06-29 21:28:293680
3681 if (!first_paint_after_load.is_null()) {
3682 UMA_HISTOGRAM_MEDIUM_TIMES(
3683 "Renderer4.BeginToFirstPaintAfterLoad", first_paint_after_load - begin);
3684 UMA_HISTOGRAM_MEDIUM_TIMES(
3685 "Renderer4.CommitToFirstPaintAfterLoad",
3686 first_paint_after_load - commit);
3687 UMA_HISTOGRAM_MEDIUM_TIMES(
3688 "Renderer4.FinishToFirstPaintAfterLoad",
3689 first_paint_after_load - finish);
3690 }
3691
3692 navigation_state->set_load_histograms_recorded(true);
[email protected]c20210e62009-04-03 21:39:263693}
[email protected]e846d0d2009-05-20 00:53:063694
[email protected]f8999642009-10-27 21:39:423695void RenderView::LogNavigationState(const NavigationState* state,
3696 const WebDataSource* ds) const {
3697 // Because this function gets called on every page load,
3698 // take extra care to optimize it away if logging is turned off.
3699 if (logging::LOG_INFO < logging::GetMinLogLevel())
3700 return;
3701
3702 DCHECK(state);
3703 DCHECK(ds);
3704 GURL url(ds->request().url());
3705 Time start = state->start_load_time();
3706 Time finish = state->finish_load_time();
3707 // TODO(mbelshe): should we log more stats?
3708 LOG(INFO) << "PLT: "
3709 << (finish - start).InMilliseconds()
3710 << "ms "
3711 << url.spec();
3712}
3713
[email protected]cc0445f2009-10-13 16:09:083714void RenderView::focusAccessibilityObject(
3715 const WebAccessibilityObject& acc_obj) {
[email protected]e846d0d2009-05-20 00:53:063716#if defined(OS_WIN)
[email protected]c7287a92009-11-04 20:06:153717 // TODO(dglazkov): Current logic implies that focus change can only be made
3718 // after at least one call to RenderView::OnGetAccessibilityInfo, which is
3719 // where accessibility is initialized. We should determine whether that's
3720 // right.
3721 if (!accessibility_.get())
3722 return;
[email protected]e846d0d2009-05-20 00:53:063723
3724 // Retrieve the accessibility object id of the AccessibilityObject.
[email protected]c7287a92009-11-04 20:06:153725 int acc_obj_id = accessibility_->addOrGetId(acc_obj);
[email protected]e846d0d2009-05-20 00:53:063726
3727 // If id is valid, alert the browser side that an accessibility focus change
3728 // occurred.
3729 if (acc_obj_id >= 0)
3730 Send(new ViewHostMsg_AccessibilityFocusChange(routing_id_, acc_obj_id));
3731
3732#else // defined(OS_WIN)
3733 // TODO(port): accessibility not yet implemented
3734 NOTIMPLEMENTED();
3735#endif
3736}
[email protected]daa8c58e2009-06-15 17:21:103737
3738void RenderView::SendPasswordForms(WebFrame* frame) {
[email protected]979c28b2009-11-07 01:30:483739 WebVector<WebFormElement> forms;
[email protected]dd7daa82009-08-10 05:46:453740 frame->forms(forms);
[email protected]daa8c58e2009-06-15 17:21:103741
3742 std::vector<PasswordForm> password_forms;
3743 for (size_t i = 0; i < forms.size(); ++i) {
[email protected]979c28b2009-11-07 01:30:483744 const WebFormElement& form = forms[i];
[email protected]daa8c58e2009-06-15 17:21:103745
3746 // Respect autocomplete=off.
[email protected]979c28b2009-11-07 01:30:483747 if (form.autoComplete()) {
[email protected]daa8c58e2009-06-15 17:21:103748 scoped_ptr<PasswordForm> password_form(
3749 PasswordFormDomManager::CreatePasswordForm(form));
3750 if (password_form.get())
3751 password_forms.push_back(*password_form);
3752 }
3753 }
3754
3755 if (!password_forms.empty())
3756 Send(new ViewHostMsg_PasswordFormsSeen(routing_id_, password_forms));
3757}
[email protected]0fda7272009-06-26 15:49:333758
3759void RenderView::Print(WebFrame* frame, bool script_initiated) {
3760 DCHECK(frame);
3761 if (print_helper_.get() == NULL) {
3762 print_helper_.reset(new PrintWebViewHelper(this));
3763 }
3764 print_helper_->Print(frame, script_initiated);
3765}
[email protected]446705872009-09-10 07:22:483766
3767void RenderView::OnSetEditCommandsForNextKeyEvent(
3768 const EditCommands& edit_commands) {
3769 edit_commands_ = edit_commands;
3770}
3771
[email protected]912256b32009-09-18 09:47:353772void RenderView::OnExecuteCode(int request_id, const std::string& extension_id,
3773 bool is_js_code,
3774 const std::string& code_string) {
[email protected]26aa0482009-09-30 16:55:273775 WebFrame* main_frame = webview() ? webview()->mainFrame() : NULL;
[email protected]912256b32009-09-18 09:47:353776 if (!main_frame) {
3777 Send(new ViewMsg_ExecuteCodeFinished(routing_id_, request_id, false));
3778 return;
3779 }
3780
[email protected]fa7b6b542009-11-03 05:02:303781 WebDataSource* ds = main_frame->dataSource();
3782 NavigationState* navigation_state = NavigationState::FromDataSource(ds);
3783 if (!navigation_state->user_script_idle_scheduler()->has_run()) {
3784 scoped_refptr<CodeExecutionInfo> info = new CodeExecutionInfo(
3785 request_id, extension_id, is_js_code, code_string);
3786 pending_code_execution_queue_.push(info);
3787 return;
3788 }
3789
3790 ExecuteCodeImpl(main_frame, request_id, extension_id, is_js_code,
3791 code_string);
3792}
3793
3794void RenderView::ExecuteCodeImpl(WebFrame* frame,
3795 int request_id,
3796 const std::string& extension_id,
3797 bool is_js_code,
3798 const std::string& code_string) {
[email protected]912256b32009-09-18 09:47:353799 if (is_js_code) {
3800 std::vector<WebScriptSource> sources;
3801 sources.push_back(
3802 WebScriptSource(WebString::fromUTF8(code_string)));
3803 UserScriptSlave::InsertInitExtensionCode(&sources, extension_id);
[email protected]fa7b6b542009-11-03 05:02:303804 frame->executeScriptInIsolatedWorld(
[email protected]146486ff2009-10-08 01:52:563805 UserScriptSlave::GetIsolatedWorldId(extension_id),
3806 &sources.front(), sources.size(), EXTENSION_GROUP_CONTENT_SCRIPTS);
[email protected]912256b32009-09-18 09:47:353807 } else {
[email protected]fa7b6b542009-11-03 05:02:303808 frame->insertStyleText(WebString::fromUTF8(code_string), WebString());
[email protected]912256b32009-09-18 09:47:353809 }
3810
3811 Send(new ViewMsg_ExecuteCodeFinished(routing_id_, request_id, true));
3812}
3813
[email protected]60c42a8c72009-10-09 04:08:593814void RenderView::Close() {
3815 // We need to grab a pointer to the doomed WebView before we destroy it.
3816 WebView* doomed = webview();
3817 RenderWidget::Close();
3818 Singleton<ViewMap>::get()->erase(doomed);
3819}
3820
[email protected]446705872009-09-10 07:22:483821void RenderView::DidHandleKeyEvent() {
3822 edit_commands_.clear();
3823}
3824
[email protected]83dde542009-09-11 20:59:553825void RenderView::EnsureDocumentTag() {
3826 // TODO(darin): There's actually no reason for this to be here. We should
3827 // have the browser side manage the document tag.
3828#if defined(OS_MACOSX)
3829 if (!has_document_tag_) {
3830 // Make the call to get the tag.
3831 Send(new ViewHostMsg_GetDocumentTag(routing_id_, &document_tag_));
3832 has_document_tag_ = true;
3833 }
3834#endif
3835}
[email protected]12636df2009-09-28 22:32:213836
3837bool RenderView::SendAndRunNestedMessageLoop(IPC::SyncMessage* message) {
[email protected]8beff0762009-09-29 02:18:303838 PluginChannelHost::Broadcast(
3839 new PluginMsg_SignalModalDialogEvent(host_window_));
[email protected]12636df2009-09-28 22:32:213840
3841 message->EnableMessagePumping(); // Runs a nested message loop.
3842 bool rv = Send(message);
3843
[email protected]8beff0762009-09-29 02:18:303844 PluginChannelHost::Broadcast(
3845 new PluginMsg_ResetModalDialogEvent(host_window_));
[email protected]12636df2009-09-28 22:32:213846
3847 return rv;
3848}