blob: e325e345d11d1c621dcaee13c5fa2492e46403f9 [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]c7287a92009-11-04 20:06:1571#include "webkit/api/public/WebAccessibilityCache.h"
[email protected]cc0445f2009-10-13 16:09:0872#include "webkit/api/public/WebAccessibilityObject.h"
[email protected]726985e22009-06-18 21:09:2873#include "webkit/api/public/WebDataSource.h"
[email protected]2661b332009-11-03 18:42:2974#include "webkit/api/public/WebDevToolsAgent.h"
[email protected]afdcf5c2009-05-10 20:30:4175#include "webkit/api/public/WebDragData.h"
[email protected]979c28b2009-11-07 01:30:4876#include "webkit/api/public/WebFormElement.h"
[email protected]dd7daa82009-08-10 05:46:4577#include "webkit/api/public/WebFrame.h"
[email protected]ca948a22009-06-25 19:36:1778#include "webkit/api/public/WebHistoryItem.h"
[email protected]581b87eb2009-07-23 23:06:5679#include "webkit/api/public/WebNode.h"
[email protected]afdcf5c2009-05-10 20:30:4180#include "webkit/api/public/WebPoint.h"
[email protected]7830da3e2009-11-06 16:27:2681#include "webkit/api/public/WebRange.h"
[email protected]afdcf5c2009-05-10 20:30:4182#include "webkit/api/public/WebRect.h"
83#include "webkit/api/public/WebScriptSource.h"
[email protected]ce0e250d2009-10-23 21:00:3584#include "webkit/api/public/WebSearchableFormData.h"
[email protected]91733b62009-09-18 06:21:0985#include "webkit/api/public/WebSecurityOrigin.h"
[email protected]afdcf5c2009-05-10 20:30:4186#include "webkit/api/public/WebSize.h"
[email protected]a1128322009-10-06 18:38:4687#include "webkit/api/public/WebString.h"
[email protected]726985e22009-06-18 21:09:2888#include "webkit/api/public/WebURL.h"
89#include "webkit/api/public/WebURLError.h"
90#include "webkit/api/public/WebURLRequest.h"
91#include "webkit/api/public/WebURLResponse.h"
92#include "webkit/api/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]acca2a12009-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]1dbafaf72009-09-23 19:43:56339void RenderView::UserMetricsRecordAction(const std::wstring& action) {
340 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]dd7daa82009-08-10 05:46:45884 UserMetricsRecordAction(L"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]dd7daa82009-08-10 05:46:45892 UserMetricsRecordAction(L"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]dd7daa82009-08-10 05:46:45900 UserMetricsRecordAction(L"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]dd7daa82009-08-10 05:46:45908 UserMetricsRecordAction(L"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
925 UserMetricsRecordAction(L"CopyToFindPboard");
926}
[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]dd7daa82009-08-10 05:46:45934 UserMetricsRecordAction(L"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]dd7daa82009-08-10 05:46:45975 UserMetricsRecordAction(L"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"));
984 UserMetricsRecordAction(L"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]acca2a12009-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]acca2a12009-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]659f73f2009-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) {
1468 const std::wstring& name = UTF16ToWideHack(command_name);
1469 if (StartsWith(name, L"Move", true) ||
1470 StartsWith(name, L"Insert", true) ||
1471 StartsWith(name, L"Delete", true))
1472 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);
1508 RenderThread::current()->spellchecker()->SpellCheckWord(
1509 word.c_str(), word.size(), document_tag_,
1510 &misspelled_offset, &misspelled_length, NULL);
1511#else
[email protected]2a3a7762009-10-19 19:17:321512 Send(new ViewHostMsg_SpellCheck(routing_id_, text, document_tag_,
1513 &misspelled_offset, &misspelled_length));
[email protected]85c55dc2009-11-06 03:05:461514#endif
[email protected]1dbafaf72009-09-23 19:43:561515}
1516
1517WebString RenderView::autoCorrectWord(const WebKit::WebString& word) {
[email protected]2a3a7762009-10-19 19:17:321518 string16 autocorrect_word;
[email protected]1dbafaf72009-09-23 19:43:561519 const CommandLine& command_line = *CommandLine::ForCurrentProcess();
[email protected]b86c8c12009-10-05 22:01:261520 if (command_line.HasSwitch(switches::kExperimentalSpellcheckerFeatures)) {
[email protected]1dbafaf72009-09-23 19:43:561521 EnsureDocumentTag();
[email protected]85c55dc2009-11-06 03:05:461522#if defined(SPELLCHECKER_IN_RENDERER)
1523 autocorrect_word =
1524 RenderThread::current()->spellchecker()->GetAutoCorrectionWord(
1525 word, document_tag_);
1526#else
[email protected]1dbafaf72009-09-23 19:43:561527 Send(new ViewHostMsg_GetAutoCorrectWord(
[email protected]2a3a7762009-10-19 19:17:321528 routing_id_, word, document_tag_, &autocorrect_word));
[email protected]85c55dc2009-11-06 03:05:461529#endif
[email protected]1dbafaf72009-09-23 19:43:561530 }
[email protected]2a3a7762009-10-19 19:17:321531 return autocorrect_word;
[email protected]1dbafaf72009-09-23 19:43:561532}
1533
[email protected]c49085c72009-10-02 16:28:561534void RenderView::showSpellingUI(bool show) {
1535 Send(new ViewHostMsg_ShowSpellingPanel(routing_id_, show));
1536}
1537
[email protected]8922e1f2009-10-03 05:01:261538bool RenderView::isShowingSpellingUI() {
1539 return spelling_panel_visible_;
1540}
1541
[email protected]1dbafaf72009-09-23 19:43:561542void RenderView::updateSpellingUIWithMisspelledWord(const WebString& word) {
[email protected]2a3a7762009-10-19 19:17:321543 Send(new ViewHostMsg_UpdateSpellingPanelWithMisspelledWord(routing_id_,
1544 word));
[email protected]1dbafaf72009-09-23 19:43:561545}
1546
[email protected]a1128322009-10-06 18:38:461547bool RenderView::runFileChooser(
1548 bool multi_select,
1549 const WebKit::WebString& title,
1550 const WebKit::WebString& initial_value,
1551 WebKit::WebFileChooserCompletion* chooser_completion) {
1552 if (file_chooser_completion_) {
1553 // TODO(brettw): bug 1235154: This should be a synchronous message to deal
1554 // with the fact that web pages can programatically trigger this. With the
1555 // asnychronous messages, we can get an additional call when one is pending,
1556 // which this test is for. For now, we just ignore the additional file
1557 // chooser request. WebKit doesn't do anything to expect the callback, so
1558 // we can just ignore calling it.
1559 return false;
1560 }
1561 file_chooser_completion_ = chooser_completion;
1562 Send(new ViewHostMsg_RunFileChooser(
1563 routing_id_, multi_select, title,
1564 webkit_glue::WebStringToFilePath(initial_value)));
1565 return true;
1566}
1567
[email protected]48c9cf2d2009-09-16 16:47:521568void RenderView::runModalAlertDialog(
1569 WebFrame* frame, const WebString& message) {
1570 RunJavaScriptMessage(MessageBoxFlags::kIsJavascriptAlert,
1571 UTF16ToWideHack(message),
1572 std::wstring(),
1573 frame->url(),
1574 NULL);
1575}
1576
1577bool RenderView::runModalConfirmDialog(
1578 WebFrame* frame, const WebString& message) {
1579 return RunJavaScriptMessage(MessageBoxFlags::kIsJavascriptConfirm,
1580 UTF16ToWideHack(message),
1581 std::wstring(),
1582 frame->url(),
1583 NULL);
1584}
1585
1586bool RenderView::runModalPromptDialog(
1587 WebFrame* frame, const WebString& message, const WebString& default_value,
1588 WebString* actual_value) {
1589 std::wstring result;
1590 bool ok = RunJavaScriptMessage(MessageBoxFlags::kIsJavascriptPrompt,
1591 UTF16ToWideHack(message),
1592 UTF16ToWideHack(default_value),
1593 frame->url(),
1594 &result);
1595 if (ok)
1596 actual_value->assign(WideToUTF16Hack(result));
1597 return ok;
1598}
1599
1600bool RenderView::runModalBeforeUnloadDialog(
1601 WebFrame* frame, const WebString& message) {
1602 bool success = false;
1603 // This is an ignored return value, but is included so we can accept the same
1604 // response as RunJavaScriptMessage.
1605 std::wstring ignored_result;
[email protected]12636df2009-09-28 22:32:211606 SendAndRunNestedMessageLoop(new ViewHostMsg_RunBeforeUnloadConfirm(
[email protected]48c9cf2d2009-09-16 16:47:521607 routing_id_, frame->url(), UTF16ToWideHack(message), &success,
[email protected]12636df2009-09-28 22:32:211608 &ignored_result));
[email protected]48c9cf2d2009-09-16 16:47:521609 return success;
1610}
1611
[email protected]79e37442009-10-09 18:17:441612void RenderView::showContextMenu(
1613 WebFrame* frame, const WebContextMenuData& data) {
1614 Send(new ViewHostMsg_ContextMenu(routing_id_, ContextMenuParams(data)));
1615}
1616
[email protected]48c9cf2d2009-09-16 16:47:521617void RenderView::setStatusText(const WebString& text) {
1618}
1619
[email protected]163f8242009-10-30 20:19:551620void RenderView::UpdateTargetURL(const GURL& url, const GURL& fallback_url) {
1621 GURL latest_url = url.spec().empty() ? fallback_url : url;
[email protected]48c9cf2d2009-09-16 16:47:521622 if (latest_url == target_url_)
1623 return;
[email protected]163f8242009-10-30 20:19:551624
[email protected]48c9cf2d2009-09-16 16:47:521625 // Tell the browser to display a destination link.
1626 if (target_url_status_ == TARGET_INFLIGHT ||
1627 target_url_status_ == TARGET_PENDING) {
1628 // If we have a request in-flight, save the URL to be sent when we
1629 // receive an ACK to the in-flight request. We can happily overwrite
1630 // any existing pending sends.
1631 pending_target_url_ = latest_url;
1632 target_url_status_ = TARGET_PENDING;
1633 } else {
1634 Send(new ViewHostMsg_UpdateTargetURL(routing_id_, page_id_, latest_url));
1635 target_url_ = latest_url;
1636 target_url_status_ = TARGET_INFLIGHT;
1637 }
1638}
1639
[email protected]882daa92009-11-05 16:31:311640void RenderView::StartNavStateSyncTimerIfNecessary() {
1641 int delay;
1642 if (send_content_state_immediately_)
1643 delay = 0;
1644 else if (is_hidden())
1645 delay = kDelaySecondsForContentStateSyncHidden;
1646 else
1647 delay = kDelaySecondsForContentStateSync;
1648
1649 if (nav_state_sync_timer_.IsRunning()) {
1650 // The timer is already running. If the delay of the timer maches the amount
1651 // we want to delay by, then return. Otherwise stop the timer so that it
1652 // gets started with the right delay.
1653 if (nav_state_sync_timer_.GetCurrentDelay().InSeconds() == delay)
1654 return;
1655 nav_state_sync_timer_.Stop();
1656 }
1657
1658 nav_state_sync_timer_.Start(
1659 TimeDelta::FromSeconds(delay), this, &RenderView::SyncNavigationState);
1660}
1661
[email protected]163f8242009-10-30 20:19:551662void RenderView::setMouseOverURL(const WebURL& url) {
1663 mouse_over_url_ = GURL(url);
1664 UpdateTargetURL(mouse_over_url_, focus_url_);
1665}
1666
1667void RenderView::setKeyboardFocusURL(const WebURL& url) {
1668 focus_url_ = GURL(url);
1669 UpdateTargetURL(focus_url_, mouse_over_url_);
1670}
1671
[email protected]48c9cf2d2009-09-16 16:47:521672void RenderView::setToolTipText(const WebString& text, WebTextDirection hint) {
1673 Send(new ViewHostMsg_SetTooltipText(routing_id_, UTF16ToWideHack(text),
1674 hint));
1675}
1676
1677void RenderView::startDragging(const WebPoint& from, const WebDragData& data,
1678 WebDragOperationsMask allowed_ops) {
1679 Send(new ViewHostMsg_StartDragging(routing_id_,
1680 WebDropData(data),
1681 allowed_ops));
1682}
1683
[email protected]28b92df2009-09-25 17:35:451684bool RenderView::acceptsLoadDrops() {
1685 return renderer_preferences_.can_accept_load_drops;
1686}
1687
[email protected]48c9cf2d2009-09-16 16:47:521688void RenderView::focusNext() {
1689 Send(new ViewHostMsg_TakeFocus(routing_id_, false));
1690}
1691
1692void RenderView::focusPrevious() {
1693 Send(new ViewHostMsg_TakeFocus(routing_id_, true));
1694}
1695
1696void RenderView::navigateBackForwardSoon(int offset) {
1697 history_back_list_count_ += offset;
1698 history_forward_list_count_ -= offset;
1699
1700 Send(new ViewHostMsg_GoToEntryAtOffset(routing_id_, offset));
1701}
1702
1703int RenderView::historyBackListCount() {
1704 return history_back_list_count_;
1705}
1706
1707int RenderView::historyForwardListCount() {
1708 return history_forward_list_count_;
1709}
1710
1711void RenderView::didAddHistoryItem() {
1712 // We don't want to update the history length for the start page
1713 // navigation.
[email protected]26aa0482009-09-30 16:55:271714 WebFrame* main_frame = webview()->mainFrame();
[email protected]48c9cf2d2009-09-16 16:47:521715 DCHECK(main_frame != NULL);
1716
1717 WebDataSource* ds = main_frame->dataSource();
1718 DCHECK(ds != NULL);
1719
1720 NavigationState* navigation_state = NavigationState::FromDataSource(ds);
1721 DCHECK(navigation_state);
1722 if (navigation_state->transition_type() == PageTransition::START_PAGE)
1723 return;
1724
1725 history_back_list_count_++;
1726 history_forward_list_count_ = 0;
1727}
1728
[email protected]8922e1f2009-10-03 05:01:261729void RenderView::didUpdateInspectorSettings() {
1730 Send(new ViewHostMsg_UpdateInspectorSettings(
1731 routing_id_, webview()->inspectorSettings().utf8()));
1732}
1733
[email protected]acca2a12009-10-16 03:53:391734void RenderView::queryAutofillSuggestions(const WebNode& node,
1735 const WebString& name,
1736 const WebString& value) {
1737 static int query_counter = 0;
1738 autofill_query_id_ = query_counter++;
1739 autofill_query_node_ = node;
1740 Send(new ViewHostMsg_QueryFormFieldAutofill(
1741 routing_id_, autofill_query_id_, name, value));
1742}
1743
1744void RenderView::removeAutofillSuggestions(const WebString& name,
1745 const WebString& value) {
1746 Send(new ViewHostMsg_RemoveAutofillEntry(routing_id_, name, value));
1747}
1748
[email protected]79dbc662009-09-04 05:42:511749// WebKit::WebWidgetClient ----------------------------------------------------
1750
initial.commit09911bf2008-07-26 23:55:291751// We are supposed to get a single call to Show for a newly created RenderView
1752// that was created via RenderView::CreateWebView. So, we wait until this
1753// point to dispatch the ShowView message.
1754//
1755// This method provides us with the information about how to display the newly
1756// created RenderView (i.e., as a constrained popup or as a new tab).
1757//
[email protected]4873c7d2009-07-16 06:36:281758void RenderView::show(WebNavigationPolicy policy) {
initial.commit09911bf2008-07-26 23:55:291759 DCHECK(!did_show_) << "received extraneous Show call";
1760 DCHECK(opener_id_ != MSG_ROUTING_NONE);
1761
1762 if (did_show_)
1763 return;
1764 did_show_ = true;
1765
[email protected]28295ec2009-10-16 05:34:331766 // Force new windows to a popup if they were not opened with a user gesture.
1767 if (!opened_by_user_gesture_) {
1768 // We exempt background tabs for compat with older versions of Chrome.
1769 // TODO(darin): This seems bogus. These should have a user gesture, so
1770 // we probably don't need this check.
1771 if (policy != WebKit::WebNavigationPolicyNewBackgroundTab)
1772 policy = WebKit::WebNavigationPolicyNewPopup;
1773 }
1774
initial.commit09911bf2008-07-26 23:55:291775 // NOTE: initial_pos_ may still have its default values at this point, but
1776 // that's okay. It'll be ignored if disposition is not NEW_POPUP, or the
1777 // browser process will impose a default position otherwise.
[email protected]4873c7d2009-07-16 06:36:281778 Send(new ViewHostMsg_ShowView(opener_id_, routing_id_,
1779 NavigationPolicyToDisposition(policy), initial_pos_,
1780 opened_by_user_gesture_, creator_url_));
[email protected]2533ce12009-05-09 00:02:241781 SetPendingWindowRect(initial_pos_);
initial.commit09911bf2008-07-26 23:55:291782}
1783
[email protected]4873c7d2009-07-16 06:36:281784void RenderView::closeWidgetSoon() {
[email protected]2c4410d2009-05-06 23:46:221785 if (!popup_notification_visible_)
[email protected]4873c7d2009-07-16 06:36:281786 RenderWidget::closeWidgetSoon();
[email protected]634a6f92008-12-01 21:39:311787}
1788
[email protected]4873c7d2009-07-16 06:36:281789void RenderView::runModal() {
initial.commit09911bf2008-07-26 23:55:291790 DCHECK(did_show_) << "should already have shown the view";
1791
[email protected]12636df2009-09-28 22:32:211792 SendAndRunNestedMessageLoop(new ViewHostMsg_RunModal(routing_id_));
initial.commit09911bf2008-07-26 23:55:291793}
1794
[email protected]3d9689372009-09-10 04:29:171795// WebKit::WebFrameClient -----------------------------------------------------
1796
1797WebPlugin* RenderView::createPlugin(
1798 WebFrame* frame, const WebPluginParams& params) {
1799 return new webkit_glue::WebPluginImpl(frame, params, AsWeakPtr());
1800}
1801
1802WebWorker* RenderView::createWorker(WebFrame* frame, WebWorkerClient* client) {
1803 return new WebWorkerProxy(client, RenderThread::current(), routing_id_);
1804}
1805
[email protected]9c00f002009-11-05 22:37:421806WebSharedWorker* RenderView::createSharedWorker(
1807 WebFrame* frame, const WebURL& url, const WebString& name,
1808 unsigned long long documentId) {
1809
1810 // TODO(atwilson): Call to the browser process to check if there's an existing
1811 // worker (passing MSG_ROUTING_NONE for now, to indicate no existing worker).
1812 int worker_route_id = MSG_ROUTING_NONE;
1813 return new WebSharedWorkerProxy(
1814 RenderThread::current(), worker_route_id, routing_id_);
1815}
1816
[email protected]3d9689372009-09-10 04:29:171817WebMediaPlayer* RenderView::createMediaPlayer(
1818 WebFrame* frame, WebMediaPlayerClient* client) {
1819 scoped_refptr<media::FilterFactoryCollection> factory =
1820 new media::FilterFactoryCollection();
1821 // Add in any custom filter factories first.
1822 const CommandLine* cmd_line = CommandLine::ForCurrentProcess();
1823 if (!cmd_line->HasSwitch(switches::kDisableAudio)) {
1824 // Add the chrome specific audio renderer.
1825 factory->AddFactory(
1826 AudioRendererImpl::CreateFactory(audio_message_filter()));
1827 }
1828
1829 // TODO(hclam): obtain the following parameters from |client|.
1830 webkit_glue::MediaResourceLoaderBridgeFactory* bridge_factory =
1831 new webkit_glue::MediaResourceLoaderBridgeFactory(
1832 GURL::EmptyGURL(), // referrer
1833 "null", // frame origin
1834 "null", // main_frame_origin
1835 base::GetCurrentProcId(),
1836 appcache::kNoHostId,
1837 routing_id());
1838
[email protected]0436b9a2009-10-23 00:23:051839 // A simple data source that keeps all data in memory.
1840 media::FilterFactory* simple_data_source_factory =
1841 webkit_glue::SimpleDataSource::CreateFactory(MessageLoop::current(),
1842 bridge_factory);
1843 // A sophisticated data source that does memory caching.
1844 media::FilterFactory* buffered_data_source_factory =
1845 webkit_glue::BufferedDataSource::CreateFactory(MessageLoop::current(),
1846 bridge_factory);
1847 if (cmd_line->HasSwitch(switches::kSimpleDataSource)) {
1848 factory->AddFactory(simple_data_source_factory);
1849 factory->AddFactory(buffered_data_source_factory);
[email protected]3d9689372009-09-10 04:29:171850 } else {
[email protected]0436b9a2009-10-23 00:23:051851 factory->AddFactory(buffered_data_source_factory);
1852 factory->AddFactory(simple_data_source_factory);
[email protected]3d9689372009-09-10 04:29:171853 }
1854 return new webkit_glue::WebMediaPlayerImpl(client, factory);
1855}
1856
1857void RenderView::willClose(WebFrame* frame) {
1858 if (!frame->parent()) {
1859 const GURL& url = frame->url();
1860 if (url.SchemeIs("http") || url.SchemeIs("https"))
1861 DumpLoadHistograms();
1862 }
[email protected]fa7b6b542009-11-03 05:02:301863
1864 WebDataSource* ds = frame->dataSource();
1865 NavigationState* navigation_state = NavigationState::FromDataSource(ds);
1866 navigation_state->user_script_idle_scheduler()->Cancel();
[email protected]3d9689372009-09-10 04:29:171867}
1868
1869void RenderView::loadURLExternally(
1870 WebFrame* frame, const WebURLRequest& request,
1871 WebNavigationPolicy policy) {
[email protected]efce17b2009-09-11 18:04:591872 GURL referrer(request.httpHeaderField(WebString::fromUTF8("Referer")));
1873 if (policy == WebKit::WebNavigationPolicyDownload) {
1874 Send(new ViewHostMsg_DownloadUrl(routing_id_, request.url(), referrer));
1875 } else {
1876 OpenURL(request.url(), referrer, policy);
1877 }
[email protected]3d9689372009-09-10 04:29:171878}
1879
1880WebNavigationPolicy RenderView::decidePolicyForNavigation(
1881 WebFrame* frame, const WebURLRequest& request, WebNavigationType type,
[email protected]65b95cd2009-10-09 05:10:221882 const WebNode&, WebNavigationPolicy default_policy, bool is_redirect) {
[email protected]3d9689372009-09-10 04:29:171883 // Webkit is asking whether to navigate to a new URL.
1884 // This is fine normally, except if we're showing UI from one security
1885 // context and they're trying to navigate to a different context.
1886 const GURL& url = request.url();
1887
1888 // If the browser is interested, then give it a chance to look at top level
1889 // navigations
1890 if (renderer_preferences_.browser_handles_top_level_requests &&
1891 // Only send once.
1892 last_top_level_navigation_page_id_ != page_id_ &&
1893 // Not interested in reloads.
1894 type != WebKit::WebNavigationTypeReload &&
1895 type != WebKit::WebNavigationTypeFormSubmitted &&
1896 // Must be a top level frame.
1897 frame->parent() == NULL) {
1898 // Skip if navigation is on the same page (using '#').
1899 GURL frame_origin = GURL(frame->url()).GetOrigin();
1900 if (url.GetOrigin() != frame_origin || url.ref().empty()) {
1901 last_top_level_navigation_page_id_ = page_id_;
[email protected]b36a9f92009-10-19 17:34:571902 GURL referrer(request.httpHeaderField(WebString::fromUTF8("Referer")));
1903 OpenURL(url, referrer, default_policy);
[email protected]3d9689372009-09-10 04:29:171904 return WebKit::WebNavigationPolicyIgnore; // Suppress the load here.
1905 }
1906 }
1907
1908 // A content initiated navigation may have originated from a link-click,
1909 // script, drag-n-drop operation, etc.
1910 bool is_content_initiated =
1911 NavigationState::FromDataSource(frame->provisionalDataSource())->
1912 is_content_initiated();
1913
1914 // We only care about navigations that are within the current tab (as opposed
1915 // to, for example, opening a new window).
1916 // But we sometimes navigate to about:blank to clear a tab, and we want to
1917 // still allow that.
1918 if (default_policy == WebKit::WebNavigationPolicyCurrentTab &&
1919 is_content_initiated && frame->parent() == NULL &&
1920 !url.SchemeIs(chrome::kAboutScheme)) {
1921 // When we received such unsolicited navigations, we sometimes want to
1922 // punt them up to the browser to handle.
1923 if (BindingsPolicy::is_dom_ui_enabled(enabled_bindings_) ||
1924 BindingsPolicy::is_extension_enabled(enabled_bindings_) ||
1925 frame->isViewSourceModeEnabled() ||
1926 url.SchemeIs(chrome::kViewSourceScheme) ||
1927 url.SchemeIs(chrome::kPrintScheme)) {
1928 OpenURL(url, GURL(), default_policy);
1929 return WebKit::WebNavigationPolicyIgnore; // Suppress the load here.
1930 }
1931 }
1932
1933 // Detect when a page is "forking" a new tab that can be safely rendered in
1934 // its own process. This is done by sites like Gmail that try to open links
1935 // in new windows without script connections back to the original page. We
1936 // treat such cases as browser navigations (in which we will create a new
1937 // renderer for a cross-site navigation), rather than WebKit navigations.
1938 //
1939 // We use the following heuristic to decide whether to fork a new page in its
1940 // own process:
1941 // The parent page must open a new tab to about:blank, set the new tab's
1942 // window.opener to null, and then redirect the tab to a cross-site URL using
1943 // JavaScript.
[email protected]007a848b2009-10-26 15:55:461944 //
1945 // TODO(creis): Deprecate this logic once we can rely on rel=noreferrer
1946 // (see below).
[email protected]3d9689372009-09-10 04:29:171947 bool is_fork =
1948 // Must start from a tab showing about:blank, which is later redirected.
[email protected]e0d481582009-09-15 21:06:251949 GURL(frame->url()) == GURL(chrome::kAboutBlankURL) &&
[email protected]3d9689372009-09-10 04:29:171950 // Must be the first real navigation of the tab.
[email protected]48c9cf2d2009-09-16 16:47:521951 historyBackListCount() < 1 &&
1952 historyForwardListCount() < 1 &&
[email protected]3d9689372009-09-10 04:29:171953 // The parent page must have set the child's window.opener to null before
1954 // redirecting to the desired URL.
1955 frame->opener() == NULL &&
1956 // Must be a top-level frame.
1957 frame->parent() == NULL &&
1958 // Must not have issued the request from this page.
1959 is_content_initiated &&
1960 // Must be targeted at the current tab.
1961 default_policy == WebKit::WebNavigationPolicyCurrentTab &&
1962 // Must be a JavaScript navigation, which appears as "other".
1963 type == WebKit::WebNavigationTypeOther;
[email protected]007a848b2009-10-26 15:55:461964
1965 // Recognize if this navigation is from a link with rel=noreferrer and
1966 // target=_blank attributes, in which case the opener will be suppressed. If
1967 // so, it is safe to load cross-site pages in a separate process, so we
1968 // should let the browser handle it.
1969 bool is_noreferrer_and_blank_target =
1970 // Frame should be top level and not yet navigated.
1971 frame->parent() == NULL &&
1972 frame->url().isEmpty() &&
1973 historyBackListCount() < 1 &&
1974 historyForwardListCount() < 1 &&
1975 // Links with rel=noreferrer will have no Referer field, and their
1976 // resulting frame will have its window.opener suppressed.
1977 // TODO(creis): should add a request.httpReferrer() method to help avoid
1978 // typos on the unusual spelling of Referer.
1979 request.httpHeaderField(WebString::fromUTF8("Referer")).isNull() &&
1980 opener_suppressed_ &&
1981 frame->opener() == NULL &&
1982 // Links with target=_blank will have no name.
1983 frame->name().isNull() &&
1984 // Another frame (with a non-empty creator) should have initiated the
1985 // request, targeted at this frame.
1986 !creator_url_.is_empty() &&
1987 is_content_initiated &&
1988 default_policy == WebKit::WebNavigationPolicyCurrentTab &&
1989 type == WebKit::WebNavigationTypeOther;
1990
1991 if (is_fork || is_noreferrer_and_blank_target) {
[email protected]3d9689372009-09-10 04:29:171992 // Open the URL via the browser, not via WebKit.
1993 OpenURL(url, GURL(), default_policy);
1994 return WebKit::WebNavigationPolicyIgnore;
1995 }
1996
1997 return default_policy;
1998}
1999
[email protected]6069da8c2009-10-20 20:33:492000bool RenderView::canHandleRequest(
2001 WebFrame* frame, const WebURLRequest& request) {
2002 // We allow WebKit to think that everything can be handled even though
2003 // browser-side we limit what we load.
[email protected]7b7a7dc2009-10-19 02:23:342004 return true;
2005}
2006
[email protected]6069da8c2009-10-20 20:33:492007WebURLError RenderView::cannotHandleRequestError(
2008 WebFrame* frame, const WebURLRequest& request) {
2009 NOTREACHED(); // Since we said we can handle all requests.
2010 return WebURLError();
2011}
2012
2013WebURLError RenderView::cancelledError(
2014 WebFrame* frame, const WebURLRequest& request) {
2015 WebURLError error;
2016 error.domain = WebString::fromUTF8(net::kErrorDomain);
2017 error.reason = net::ERR_ABORTED;
2018 error.unreachableURL = request.url();
2019 return error;
[email protected]7b7a7dc2009-10-19 02:23:342020}
2021
2022void RenderView::unableToImplementPolicyWithError(
[email protected]6069da8c2009-10-20 20:33:492023 WebFrame*, const WebURLError&) {
2024 NOTREACHED(); // Since we said we can handle all requests.
[email protected]7b7a7dc2009-10-19 02:23:342025}
2026
[email protected]979c28b2009-11-07 01:30:482027void RenderView::willSubmitForm(WebFrame* frame, const WebFormElement& form) {
[email protected]3d9689372009-09-10 04:29:172028 NavigationState* navigation_state =
2029 NavigationState::FromDataSource(frame->provisionalDataSource());
2030
2031 if (navigation_state->transition_type() == PageTransition::LINK)
2032 navigation_state->set_transition_type(PageTransition::FORM_SUBMIT);
2033
2034 // Save these to be processed when the ensuing navigation is committed.
[email protected]ce0e250d2009-10-23 21:00:352035 WebSearchableFormData web_searchable_form_data(form);
2036 navigation_state->set_searchable_form_url(web_searchable_form_data.url());
2037 navigation_state->set_searchable_form_encoding(
2038 webkit_glue::WebStringToStdString(web_searchable_form_data.encoding()));
[email protected]3d9689372009-09-10 04:29:172039 navigation_state->set_password_form_data(
2040 PasswordFormDomManager::CreatePasswordForm(form));
2041
[email protected]979c28b2009-11-07 01:30:482042 if (form.autoComplete()) {
[email protected]c54d269e2009-10-21 18:07:382043 scoped_ptr<FormFieldValues> form_values(FormFieldValues::Create(form));
2044 if (form_values.get())
[email protected]51bd36612009-10-20 22:49:472045 Send(new ViewHostMsg_FormFieldValuesSubmitted(routing_id_,
[email protected]c54d269e2009-10-21 18:07:382046 *form_values));
[email protected]3d9689372009-09-10 04:29:172047 }
2048}
2049
2050void RenderView::willPerformClientRedirect(
2051 WebFrame* frame, const WebURL& from, const WebURL& to, double interval,
2052 double fire_time) {
2053 // Ignore
2054}
2055
2056void RenderView::didCancelClientRedirect(WebFrame* frame) {
2057 // Ignore
2058}
2059
2060void RenderView::didCompleteClientRedirect(
2061 WebFrame* frame, const WebURL& from) {
2062 if (!frame->parent())
2063 completed_client_redirect_src_ = from;
2064}
2065
2066void RenderView::didCreateDataSource(WebFrame* frame, WebDataSource* ds) {
2067 // The rest of RenderView assumes that a WebDataSource will always have a
2068 // non-null NavigationState.
[email protected]fa7b6b542009-11-03 05:02:302069 NavigationState* state = pending_navigation_state_.get() ?
[email protected]7ea093ba2009-11-03 05:54:592070 pending_navigation_state_.release() :
[email protected]fa7b6b542009-11-03 05:02:302071 NavigationState::CreateContentInitiated();
2072
2073 state->set_user_script_idle_scheduler(
2074 new UserScriptIdleScheduler(this, frame));
2075 ds->setExtraData(state);
[email protected]3d9689372009-09-10 04:29:172076}
2077
2078void RenderView::didStartProvisionalLoad(WebFrame* frame) {
2079 WebDataSource* ds = frame->provisionalDataSource();
2080 NavigationState* navigation_state = NavigationState::FromDataSource(ds);
2081
2082 navigation_state->set_start_load_time(Time::Now());
2083
2084 // Update the request time if WebKit has better knowledge of it.
2085 if (navigation_state->request_time().is_null()) {
2086 double event_time = ds->triggeringEventTime();
2087 if (event_time != 0.0)
2088 navigation_state->set_request_time(Time::FromDoubleT(event_time));
2089 }
2090
2091 bool is_top_most = !frame->parent();
2092 if (is_top_most) {
2093 navigation_gesture_ = frame->isProcessingUserGesture() ?
2094 NavigationGestureUnknown : NavigationGestureAuto;
2095
2096 // Make sure redirect tracking state is clear for the new load.
2097 completed_client_redirect_src_ = GURL();
2098 } else if (frame->parent()->isLoading()) {
2099 // Take note of AUTO_SUBFRAME loads here, so that we can know how to
2100 // load an error page. See DidFailProvisionalLoadWithError.
2101 navigation_state->set_transition_type(PageTransition::AUTO_SUBFRAME);
2102 }
2103
2104 Send(new ViewHostMsg_DidStartProvisionalLoadForFrame(
2105 routing_id_, is_top_most, ds->request().url()));
2106}
2107
2108void RenderView::didReceiveServerRedirectForProvisionalLoad(WebFrame* frame) {
2109 if (frame->parent())
2110 return;
2111 // Received a redirect on the main frame.
2112 WebDataSource* data_source = frame->provisionalDataSource();
2113 if (!data_source) {
2114 // Should only be invoked when we have a data source.
2115 NOTREACHED();
2116 return;
2117 }
2118 std::vector<GURL> redirects;
2119 GetRedirectChain(data_source, &redirects);
2120 if (redirects.size() >= 2) {
2121 Send(new ViewHostMsg_DidRedirectProvisionalLoad(
2122 routing_id_, page_id_, redirects[redirects.size() - 2],
2123 redirects[redirects.size() - 1]));
2124 }
2125}
2126
2127void RenderView::didFailProvisionalLoad(
2128 WebFrame* frame, const WebURLError& error) {
2129 // Notify the browser that we failed a provisional load with an error.
2130 //
2131 // Note: It is important this notification occur before DidStopLoading so the
2132 // SSL manager can react to the provisional load failure before being
2133 // notified the load stopped.
2134 //
2135 WebDataSource* ds = frame->provisionalDataSource();
2136 DCHECK(ds);
2137
2138 const WebURLRequest& failed_request = ds->request();
2139
2140 bool show_repost_interstitial =
2141 (error.reason == net::ERR_CACHE_MISS &&
2142 EqualsASCII(failed_request.httpMethod(), "POST"));
2143 Send(new ViewHostMsg_DidFailProvisionalLoadWithError(
2144 routing_id_, !frame->parent(), error.reason, error.unreachableURL,
2145 show_repost_interstitial));
2146
2147 // Don't display an error page if this is simply a cancelled load. Aside
2148 // from being dumb, WebCore doesn't expect it and it will cause a crash.
2149 if (error.reason == net::ERR_ABORTED)
2150 return;
2151
2152 // Make sure we never show errors in view source mode.
2153 frame->enableViewSourceMode(false);
2154
2155 NavigationState* navigation_state = NavigationState::FromDataSource(ds);
2156
2157 // If this is a failed back/forward/reload navigation, then we need to do a
2158 // 'replace' load. This is necessary to avoid messing up session history.
2159 // Otherwise, we do a normal load, which simulates a 'go' navigation as far
2160 // as session history is concerned.
2161 //
2162 // AUTO_SUBFRAME loads should always be treated as loads that do not advance
2163 // the page id.
2164 //
2165 bool replace =
2166 navigation_state->pending_page_id() != -1 ||
2167 navigation_state->transition_type() == PageTransition::AUTO_SUBFRAME;
2168
2169 // If we failed on a browser initiated request, then make sure that our error
2170 // page load is regarded as the same browser initiated request.
2171 if (!navigation_state->is_content_initiated()) {
2172 pending_navigation_state_.reset(NavigationState::CreateBrowserInitiated(
2173 navigation_state->pending_page_id(),
2174 navigation_state->transition_type(),
2175 navigation_state->request_time()));
2176 }
2177
2178 // Provide the user with a more helpful error page?
2179 if (MaybeLoadAlternateErrorPage(frame, error, replace))
2180 return;
2181
2182 // Fallback to a local error page.
2183 LoadNavigationErrorPage(frame, failed_request, error, std::string(),
2184 replace);
2185}
2186
2187void RenderView::didReceiveDocumentData(
2188 WebFrame* frame, const char* data, size_t data_len,
2189 bool& prevent_default) {
2190 NavigationState* navigation_state =
2191 NavigationState::FromDataSource(frame->dataSource());
2192 if (!navigation_state->postpone_loading_data())
2193 return;
2194
2195 // We're going to call commitDocumentData ourselves...
2196 prevent_default = true;
2197
2198 // Continue buffering the response data for the original 404 page. If it
2199 // grows too large, then we'll just let it through.
2200 navigation_state->append_postponed_data(data, data_len);
2201 if (navigation_state->postponed_data().size() >= 512) {
2202 navigation_state->set_postpone_loading_data(false);
2203 frame->commitDocumentData(navigation_state->postponed_data().data(),
2204 navigation_state->postponed_data().size());
2205 navigation_state->clear_postponed_data();
2206 }
2207}
2208
2209void RenderView::didCommitProvisionalLoad(
2210 WebFrame* frame, bool is_new_navigation) {
2211 NavigationState* navigation_state =
2212 NavigationState::FromDataSource(frame->dataSource());
2213
2214 navigation_state->set_commit_load_time(Time::Now());
2215 if (is_new_navigation) {
2216 // When we perform a new navigation, we need to update the previous session
2217 // history entry with state for the page we are leaving.
2218 UpdateSessionHistory(frame);
2219
2220 // We bump our Page ID to correspond with the new session history entry.
2221 page_id_ = next_page_id_++;
2222
2223 MessageLoop::current()->PostDelayedTask(FROM_HERE,
2224 method_factory_.NewRunnableMethod(&RenderView::CapturePageInfo,
2225 page_id_, true),
2226 kDelayForForcedCaptureMs);
2227 } else {
2228 // Inspect the navigation_state on this frame to see if the navigation
2229 // corresponds to a session history navigation... Note: |frame| may or
2230 // may not be the toplevel frame, but for the case of capturing session
2231 // history, the first committed frame suffices. We keep track of whether
2232 // we've seen this commit before so that only capture session history once
2233 // per navigation.
2234 //
2235 // Note that we need to check if the page ID changed. In the case of a
2236 // reload, the page ID doesn't change, and UpdateSessionHistory gets the
2237 // previous URL and the current page ID, which would be wrong.
2238 if (navigation_state->pending_page_id() != -1 &&
2239 navigation_state->pending_page_id() != page_id_ &&
2240 !navigation_state->request_committed()) {
2241 // This is a successful session history navigation!
2242 UpdateSessionHistory(frame);
2243 page_id_ = navigation_state->pending_page_id();
2244 }
2245 }
2246
2247 // Remember that we've already processed this request, so we don't update
2248 // the session history again. We do this regardless of whether this is
2249 // a session history navigation, because if we attempted a session history
2250 // navigation without valid HistoryItem state, WebCore will think it is a
2251 // new navigation.
2252 navigation_state->set_request_committed(true);
2253
2254 UpdateURL(frame);
2255
2256 // If this committed load was initiated by a client redirect, we're
2257 // at the last stop now, so clear it.
2258 completed_client_redirect_src_ = GURL();
2259
2260 // Check whether we have new encoding name.
[email protected]26aa0482009-09-30 16:55:272261 UpdateEncoding(frame, frame->view()->pageEncoding().utf8());
[email protected]3d9689372009-09-10 04:29:172262}
2263
2264void RenderView::didClearWindowObject(WebFrame* frame) {
2265 if (BindingsPolicy::is_dom_automation_enabled(enabled_bindings_))
2266 BindDOMAutomationController(frame);
2267 if (BindingsPolicy::is_dom_ui_enabled(enabled_bindings_)) {
2268 dom_ui_bindings_.set_message_sender(this);
2269 dom_ui_bindings_.set_routing_id(routing_id_);
2270 dom_ui_bindings_.BindToJavascript(frame, L"chrome");
2271 }
2272 if (BindingsPolicy::is_external_host_enabled(enabled_bindings_)) {
2273 external_host_bindings_.set_message_sender(this);
2274 external_host_bindings_.set_routing_id(routing_id_);
2275 external_host_bindings_.BindToJavascript(frame, L"externalHost");
2276 }
2277}
2278
2279void RenderView::didCreateDocumentElement(WebFrame* frame) {
2280 if (RenderThread::current()) { // Will be NULL during unit tests.
2281 RenderThread::current()->user_script_slave()->InjectScripts(
2282 frame, UserScript::DOCUMENT_START);
2283 }
[email protected]078b34612009-09-19 19:31:512284 if (view_type_ == ViewType::EXTENSION_TOOLSTRIP ||
2285 view_type_ == ViewType::EXTENSION_MOLE) {
2286 InjectToolstripCSS();
2287 ExtensionProcessBindings::SetViewType(webview(), view_type_);
2288 }
[email protected]3d9689372009-09-10 04:29:172289
2290 // Notify the browser about non-blank documents loading in the top frame.
2291 GURL url = frame->url();
[email protected]e0d481582009-09-15 21:06:252292 if (url.is_valid() && url.spec() != chrome::kAboutBlankURL) {
[email protected]26aa0482009-09-30 16:55:272293 if (frame == webview()->mainFrame())
[email protected]3d9689372009-09-10 04:29:172294 Send(new ViewHostMsg_DocumentAvailableInMainFrame(routing_id_));
2295 }
2296}
2297
2298void RenderView::didReceiveTitle(WebFrame* frame, const WebString& title) {
2299 UpdateTitle(frame, title);
2300
2301 // Also check whether we have new encoding name.
[email protected]26aa0482009-09-30 16:55:272302 UpdateEncoding(frame, frame->view()->pageEncoding().utf8());
[email protected]3d9689372009-09-10 04:29:172303}
2304
2305void RenderView::didFinishDocumentLoad(WebFrame* frame) {
2306 WebDataSource* ds = frame->dataSource();
2307 NavigationState* navigation_state = NavigationState::FromDataSource(ds);
2308 DCHECK(navigation_state);
2309 navigation_state->set_finish_document_load_time(Time::Now());
2310
2311 Send(new ViewHostMsg_DocumentLoadedInFrame(routing_id_));
2312
2313 // The document has now been fully loaded. Scan for password forms to be
2314 // sent up to the browser.
2315 SendPasswordForms(frame);
2316
2317 // Check whether we have new encoding name.
[email protected]26aa0482009-09-30 16:55:272318 UpdateEncoding(frame, frame->view()->pageEncoding().utf8());
[email protected]3d9689372009-09-10 04:29:172319
2320 if (RenderThread::current()) { // Will be NULL during unit tests.
2321 RenderThread::current()->user_script_slave()->InjectScripts(
2322 frame, UserScript::DOCUMENT_END);
2323 }
[email protected]fa7b6b542009-11-03 05:02:302324
2325 navigation_state->user_script_idle_scheduler()->DidFinishDocumentLoad();
2326}
2327
2328void RenderView::OnUserScriptIdleTriggered(WebFrame* frame) {
2329 if (RenderThread::current()) { // Will be NULL during unit tests.
2330 RenderThread::current()->user_script_slave()->InjectScripts(
2331 frame, UserScript::DOCUMENT_IDLE);
2332 }
2333
2334 WebFrame* main_frame = webview()->mainFrame();
2335 if (frame == main_frame) {
2336 while (!pending_code_execution_queue_.empty()) {
2337 scoped_refptr<CodeExecutionInfo> info =
2338 pending_code_execution_queue_.front();
2339 ExecuteCodeImpl(main_frame, info->request_id, info->extension_id,
2340 info->is_js_code, info->code_string);
2341 pending_code_execution_queue_.pop();
2342 }
2343 }
[email protected]3d9689372009-09-10 04:29:172344}
2345
2346void RenderView::didHandleOnloadEvents(WebFrame* frame) {
2347 // Ignore
2348}
2349
2350void RenderView::didFailLoad(WebFrame* frame, const WebURLError& error) {
2351 // Ignore
2352}
2353
2354void RenderView::didFinishLoad(WebFrame* frame) {
2355 WebDataSource* ds = frame->dataSource();
2356 NavigationState* navigation_state = NavigationState::FromDataSource(ds);
2357 DCHECK(navigation_state);
2358 navigation_state->set_finish_load_time(Time::Now());
[email protected]fa7b6b542009-11-03 05:02:302359 navigation_state->user_script_idle_scheduler()->DidFinishLoad();
[email protected]3d9689372009-09-10 04:29:172360}
2361
2362void RenderView::didChangeLocationWithinPage(
2363 WebFrame* frame, bool is_new_navigation) {
2364 // If this was a reference fragment navigation that we initiated, then we
2365 // could end up having a non-null pending navigation state. We just need to
2366 // update the ExtraData on the datasource so that others who read the
2367 // ExtraData will get the new NavigationState. Similarly, if we did not
2368 // initiate this navigation, then we need to take care to reset any pre-
2369 // existing navigation state to a content-initiated navigation state.
2370 // DidCreateDataSource conveniently takes care of this for us.
2371 didCreateDataSource(frame, frame->dataSource());
2372
2373 didCommitProvisionalLoad(frame, is_new_navigation);
2374
[email protected]26aa0482009-09-30 16:55:272375 UpdateTitle(frame, frame->view()->mainFrame()->dataSource()->pageTitle());
[email protected]3d9689372009-09-10 04:29:172376}
2377
[email protected]476b6f82009-09-10 21:00:592378void RenderView::didUpdateCurrentHistoryItem(WebFrame* frame) {
[email protected]882daa92009-11-05 16:31:312379 StartNavStateSyncTimerIfNecessary();
[email protected]476b6f82009-09-10 21:00:592380}
2381
[email protected]3d9689372009-09-10 04:29:172382void RenderView::assignIdentifierToRequest(
2383 WebFrame* frame, unsigned identifier, const WebURLRequest& request) {
2384 // Ignore
2385}
2386
2387void RenderView::willSendRequest(
2388 WebFrame* frame, unsigned identifier, WebURLRequest& request,
2389 const WebURLResponse& redirect_response) {
[email protected]5e369672009-11-03 23:48:302390 WebFrame* top_frame = frame->top();
2391 if (!top_frame)
2392 top_frame = frame;
2393 WebDataSource* data_source = top_frame->provisionalDataSource();
2394 if (!data_source)
2395 data_source = top_frame->dataSource();
2396 if (data_source) {
2397 NavigationState* state = NavigationState::FromDataSource(data_source);
2398 if (state && state->is_cache_policy_override_set())
2399 request.setCachePolicy(state->cache_policy_override());
2400 }
[email protected]3d9689372009-09-10 04:29:172401 request.setRequestorID(routing_id_);
2402}
2403
2404void RenderView::didReceiveResponse(
2405 WebFrame* frame, unsigned identifier, const WebURLResponse& response) {
2406 // Consider loading an alternate error page for 404 responses.
2407 if (response.httpStatusCode() != 404)
2408 return;
2409
2410 // Only do this for responses that correspond to a provisional data source
2411 // of the top-most frame. If we have a provisional data source, then we
2412 // can't have any sub-resources yet, so we know that this response must
2413 // correspond to a frame load.
2414 if (!frame->provisionalDataSource() || frame->parent())
2415 return;
2416
2417 // If we are in view source mode, then just let the user see the source of
2418 // the server's 404 error page.
2419 if (frame->isViewSourceModeEnabled())
2420 return;
2421
2422 // Can we even load an alternate error page for this URL?
2423 if (!GetAlternateErrorPageURL(response.url(), HTTP_404).is_valid())
2424 return;
2425
2426 NavigationState* navigation_state =
2427 NavigationState::FromDataSource(frame->provisionalDataSource());
2428 navigation_state->set_postpone_loading_data(true);
2429 navigation_state->clear_postponed_data();
2430}
2431
2432void RenderView::didFinishResourceLoad(
2433 WebFrame* frame, unsigned identifier) {
2434 NavigationState* navigation_state =
2435 NavigationState::FromDataSource(frame->dataSource());
2436 if (!navigation_state->postpone_loading_data())
2437 return;
2438
2439 // The server returned a 404 and the content was < 512 bytes (which we
2440 // suppressed). Go ahead and fetch the alternate page content.
2441
2442 const GURL& frame_url = frame->url();
2443
2444 const GURL& error_page_url = GetAlternateErrorPageURL(frame_url, HTTP_404);
2445 DCHECK(error_page_url.is_valid());
2446
2447 WebURLError original_error;
2448 original_error.unreachableURL = frame_url;
2449
2450 navigation_state->set_alt_error_page_fetcher(
2451 new AltErrorPageResourceFetcher(
2452 error_page_url, frame, original_error,
2453 NewCallback(this, &RenderView::AltErrorPageFinished)));
2454}
2455
2456void RenderView::didFailResourceLoad(
2457 WebFrame* frame, unsigned identifier, const WebURLError& error) {
2458 // Ignore
2459}
2460
2461void RenderView::didLoadResourceFromMemoryCache(
2462 WebFrame* frame, const WebURLRequest& request,
2463 const WebURLResponse& response) {
2464 // Let the browser know we loaded a resource from the memory cache. This
2465 // message is needed to display the correct SSL indicators.
2466 Send(new ViewHostMsg_DidLoadResourceFromMemoryCache(
2467 routing_id_,
2468 request.url(),
[email protected]91733b62009-09-18 06:21:092469 frame->securityOrigin().toString().utf8(),
2470 frame->top()->securityOrigin().toString().utf8(),
[email protected]3d9689372009-09-10 04:29:172471 response.securityInfo()));
2472}
2473
[email protected]6069da8c2009-10-20 20:33:492474void RenderView::didDisplayInsecureContent(WebFrame* frame) {
[email protected]e3d60e5d2009-09-25 21:08:292475 Send(new ViewHostMsg_DidDisplayInsecureContent(routing_id_));
2476}
2477
2478void RenderView::didRunInsecureContent(
2479 WebFrame* frame, const WebSecurityOrigin& origin) {
2480 Send(new ViewHostMsg_DidRunInsecureContent(
2481 routing_id_,
2482 origin.toString().utf8()));
2483}
2484
[email protected]7ea093ba2009-11-03 05:54:592485bool RenderView::allowScript(WebFrame* frame, bool enabled_per_settings) {
2486 if (enabled_per_settings)
2487 return true;
2488
2489 WebSecurityOrigin origin = frame->securityOrigin();
2490 if (origin.isEmpty())
2491 return false; // Uninitialized document?
2492
2493 if (EqualsASCII(origin.protocol(), chrome::kChromeUIScheme))
2494 return true; // Browser UI elements should still work.
2495
2496 // If the scheme is ftp: or file:, an empty file name indicates a directory
2497 // listing, which requires JavaScript to function properly.
2498 GURL frame_url = frame->url();
2499 const char* kDirProtocols[] = { "ftp", "file" };
2500 for (size_t i = 0; i < arraysize(kDirProtocols); ++i) {
2501 if (EqualsASCII(origin.protocol(), kDirProtocols[i])) {
2502 return frame_url.SchemeIs(kDirProtocols[i]) &&
2503 frame_url.ExtractFileName().empty();
2504 }
2505 }
2506
2507 return false; // Other protocols fall through here.
2508}
2509
[email protected]3d9689372009-09-10 04:29:172510void RenderView::didExhaustMemoryAvailableForScript(WebFrame* frame) {
2511 Send(new ViewHostMsg_JSOutOfMemory(routing_id_));
2512}
2513
[email protected]0c882b282009-10-07 17:01:282514void RenderView::didCreateScriptContext(WebFrame* frame) {
2515 EventBindings::HandleContextCreated(frame, false);
2516}
2517
2518void RenderView::didDestroyScriptContext(WebFrame* frame) {
2519 EventBindings::HandleContextDestroyed(frame);
2520}
2521
2522void RenderView::didCreateIsolatedScriptContext(WebFrame* frame) {
2523 EventBindings::HandleContextCreated(frame, true);
2524}
2525
[email protected]3d9689372009-09-10 04:29:172526void RenderView::didChangeContentsSize(WebFrame* frame, const WebSize& size) {
2527 // We don't always want to send the change messages over IPC, only if we've
[email protected]ab32b16c2009-10-16 14:57:252528 // be put in that mode by getting a |ViewMsg_EnablePreferredSizeChangedMode|
[email protected]3d9689372009-09-10 04:29:172529 // message.
[email protected]ab32b16c2009-10-16 14:57:252530 if (send_preferred_size_changes_) {
[email protected]3d9689372009-09-10 04:29:172531 // WebCore likes to tell us things have changed even when they haven't, so
[email protected]ab32b16c2009-10-16 14:57:252532 // cache the width and height and only send the IPC message when we're sure
2533 // they're different.
[email protected]26aa0482009-09-30 16:55:272534 int width = webview()->mainFrame()->contentsPreferredWidth();
[email protected]ab32b16c2009-10-16 14:57:252535 if (width != preferred_size_.width() ||
2536 size.height != preferred_size_.height()) {
2537 preferred_size_.set_width(width);
2538
2539 // TODO(erikkay) the contents size is not really the same as the
2540 // preferred size. It's just the current size. This means that for
2541 // height, it will only ever grow, it will never shrink.
2542 preferred_size_.set_height(size.height);
2543 Send(new ViewHostMsg_DidContentsPreferredSizeChange(routing_id_,
2544 preferred_size_));
[email protected]3d9689372009-09-10 04:29:172545 }
2546 }
2547}
2548
[email protected]143dcd592009-11-06 21:33:492549void RenderView::didChangeScrollOffset(WebFrame* frame) {
2550 StartNavStateSyncTimerIfNecessary();
2551}
2552
[email protected]8922e1f2009-10-03 05:01:262553void RenderView::reportFindInPageMatchCount(int request_id, int count,
2554 bool final_update) {
2555 // If we have a message that has been queued up, then we should just replace
2556 // it. The ACK from the browser will make sure it gets sent when the browser
2557 // wants it.
2558 if (queued_find_reply_message_.get()) {
2559 IPC::Message* msg = new ViewHostMsg_Find_Reply(
2560 routing_id_,
2561 request_id,
2562 count,
2563 gfx::Rect(),
2564 -1, // Don't update active match ordinal.
2565 final_update);
2566 queued_find_reply_message_.reset(msg);
2567 } else {
2568 // Send the search result over to the browser process.
2569 Send(new ViewHostMsg_Find_Reply(
2570 routing_id_,
2571 request_id,
2572 count,
2573 gfx::Rect(),
2574 -1, // // Don't update active match ordinal.
2575 final_update));
2576 }
2577}
2578
2579void RenderView::reportFindInPageSelection(int request_id,
2580 int active_match_ordinal,
2581 const WebRect& selection_rect) {
2582 // Send the search result over to the browser process.
2583 Send(new ViewHostMsg_Find_Reply(routing_id_,
2584 request_id,
2585 -1,
2586 selection_rect,
2587 active_match_ordinal,
2588 false));
2589}
2590
[email protected]79dbc662009-09-04 05:42:512591// webkit_glue::WebPluginPageDelegate -----------------------------------------
2592
[email protected]f103ab72009-09-02 17:10:592593webkit_glue::WebPluginDelegate* RenderView::CreatePluginDelegate(
2594 const GURL& url,
2595 const std::string& mime_type,
[email protected]f103ab72009-09-02 17:10:592596 std::string* actual_mime_type) {
2597 if (!PluginChannelHost::IsListening())
2598 return NULL;
2599
2600 GURL policy_url;
[email protected]26aa0482009-09-30 16:55:272601 WebFrame* main_frame = webview()->mainFrame();
[email protected]f103ab72009-09-02 17:10:592602 if (main_frame)
2603 policy_url = main_frame->url();
2604
2605 FilePath path;
[email protected]610c0892009-09-08 19:46:182606 render_thread_->Send(new ViewHostMsg_GetPluginPath(
2607 url, policy_url, mime_type, &path, actual_mime_type));
[email protected]f103ab72009-09-02 17:10:592608 if (path.value().empty())
2609 return NULL;
2610
2611 const std::string* mime_type_to_use;
2612 if (!actual_mime_type->empty())
2613 mime_type_to_use = actual_mime_type;
2614 else
2615 mime_type_to_use = &mime_type;
2616
[email protected]26e8d5e2009-10-13 02:47:162617#if defined(PEPPER_APIS_ENABLED)
2618 const char kPepperPrefix[] = "pepper-";
2619 if (StartsWithASCII(*mime_type_to_use, kPepperPrefix, true)) {
[email protected]d439ba072009-10-17 22:32:292620 return WebPluginDelegatePepper::Create(
[email protected]26e8d5e2009-10-13 02:47:162621 path, *mime_type_to_use, gfx::NativeViewFromId(host_window_));
2622 }
2623#endif
2624
[email protected]d032f492009-09-29 00:33:462625 bool in_process_plugin = RenderProcess::current()->in_process_plugins();
2626 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kInternalNaCl)) {
2627 if (mime_type == "application/x-nacl-srpc") {
2628 in_process_plugin = true;
2629 }
2630 }
2631 if (in_process_plugin) {
[email protected]f103ab72009-09-02 17:10:592632#if defined(OS_WIN) // In-proc plugins aren't supported on Linux or Mac.
[email protected]8a3b7962009-09-04 05:53:232633 return WebPluginDelegateImpl::Create(
[email protected]f103ab72009-09-02 17:10:592634 path, *mime_type_to_use, gfx::NativeViewFromId(host_window_));
2635#else
2636 NOTIMPLEMENTED();
2637 return NULL;
2638#endif
2639 }
2640
[email protected]610c0892009-09-08 19:46:182641 return new WebPluginDelegateProxy(*mime_type_to_use, AsWeakPtr());
[email protected]f103ab72009-09-02 17:10:592642}
2643
2644void RenderView::CreatedPluginWindow(gfx::PluginWindowHandle window) {
2645#if defined(OS_LINUX)
2646 RenderThread::current()->Send(new ViewHostMsg_CreatePluginContainer(
2647 routing_id(), window));
2648#endif
2649}
2650
2651void RenderView::WillDestroyPluginWindow(gfx::PluginWindowHandle window) {
2652#if defined(OS_LINUX)
2653 RenderThread::current()->Send(new ViewHostMsg_DestroyPluginContainer(
2654 routing_id(), window));
2655#endif
2656 CleanupWindowInPluginMoves(window);
2657}
2658
2659void RenderView::DidMovePlugin(const webkit_glue::WebPluginGeometry& move) {
2660 SchedulePluginMove(move);
2661}
2662
2663void RenderView::DidStartLoadingForPlugin() {
2664 // TODO(darin): Make is_loading_ be a counter!
[email protected]48c9cf2d2009-09-16 16:47:522665 didStartLoading();
[email protected]f103ab72009-09-02 17:10:592666}
2667
2668void RenderView::DidStopLoadingForPlugin() {
2669 // TODO(darin): Make is_loading_ be a counter!
[email protected]48c9cf2d2009-09-16 16:47:522670 didStopLoading();
[email protected]f103ab72009-09-02 17:10:592671}
2672
2673void RenderView::ShowModalHTMLDialogForPlugin(
2674 const GURL& url,
2675 const gfx::Size& size,
2676 const std::string& json_arguments,
2677 std::string* json_retval) {
[email protected]12636df2009-09-28 22:32:212678 SendAndRunNestedMessageLoop(new ViewHostMsg_ShowModalHTMLDialog(
[email protected]f103ab72009-09-02 17:10:592679 routing_id_, url, size.width(), size.height(), json_arguments,
[email protected]12636df2009-09-28 22:32:212680 json_retval));
[email protected]f103ab72009-09-02 17:10:592681}
2682
initial.commit09911bf2008-07-26 23:55:292683void RenderView::SyncNavigationState() {
2684 if (!webview())
2685 return;
2686
[email protected]26aa0482009-09-30 16:55:272687 const WebHistoryItem& item = webview()->mainFrame()->currentHistoryItem();
[email protected]ca948a22009-06-25 19:36:172688 if (item.isNull())
initial.commit09911bf2008-07-26 23:55:292689 return;
[email protected]ca948a22009-06-25 19:36:172690
2691 Send(new ViewHostMsg_UpdateState(
2692 routing_id_, page_id_, webkit_glue::HistoryItemToString(item)));
initial.commit09911bf2008-07-26 23:55:292693}
2694
[email protected]b0950a72009-09-29 23:16:172695bool RenderView::DownloadImage(int id, const GURL& image_url, int image_size) {
2696 // Make sure webview was not shut down.
2697 if (!webview())
2698 return false;
2699 // Create an image resource fetcher and assign it with a call back object.
2700 image_fetchers_.insert(new ImageResourceFetcher(
[email protected]26aa0482009-09-30 16:55:272701 image_url, webview()->mainFrame(), id, image_size,
[email protected]b0950a72009-09-29 23:16:172702 NewCallback(this, &RenderView::DidDownloadImage)));
2703 return true;
2704}
2705
2706void RenderView::DidDownloadImage(ImageResourceFetcher* fetcher,
initial.commit09911bf2008-07-26 23:55:292707 const SkBitmap& image) {
[email protected]b0950a72009-09-29 23:16:172708 // Notify requester of image download status.
[email protected]51bd36612009-10-20 22:49:472709 Send(new ViewHostMsg_DidDownloadFavIcon(routing_id_,
2710 fetcher->id(),
2711 fetcher->image_url(),
2712 image.isNull(),
2713 image));
[email protected]b0950a72009-09-29 23:16:172714 // Dispose of the image fetcher.
2715 DCHECK(image_fetchers_.find(fetcher) != image_fetchers_.end());
2716 image_fetchers_.erase(fetcher);
2717 // We're in the callback from the ImageResourceFetcher, best to delay
2718 // deletion.
2719 MessageLoop::current()->DeleteSoon(FROM_HERE, fetcher);
initial.commit09911bf2008-07-26 23:55:292720}
2721
[email protected]bf5c2ff392009-07-08 16:24:332722void RenderView::OnDownloadFavIcon(int id,
2723 const GURL& image_url,
2724 int image_size) {
[email protected]f11ca0732009-04-11 00:09:342725 bool data_image_failed = false;
2726 if (image_url.SchemeIs("data")) {
2727 SkBitmap data_image = ImageFromDataUrl(image_url);
2728 data_image_failed = data_image.empty();
2729 if (!data_image_failed) {
[email protected]bf5c2ff392009-07-08 16:24:332730 Send(new ViewHostMsg_DidDownloadFavIcon(routing_id_, id, image_url, false,
2731 data_image));
[email protected]f11ca0732009-04-11 00:09:342732 }
2733 }
2734
[email protected]bf5c2ff392009-07-08 16:24:332735 if (data_image_failed ||
[email protected]b0950a72009-09-29 23:16:172736 !DownloadImage(id, image_url, image_size)) {
[email protected]bf5c2ff392009-07-08 16:24:332737 Send(new ViewHostMsg_DidDownloadFavIcon(routing_id_, id, image_url, true,
2738 SkBitmap()));
2739 }
initial.commit09911bf2008-07-26 23:55:292740}
2741
[email protected]f11ca0732009-04-11 00:09:342742SkBitmap RenderView::ImageFromDataUrl(const GURL& url) const {
2743 std::string mime_type, char_set, data;
2744 if (net::DataURL::Parse(url, &mime_type, &char_set, &data) && !data.empty()) {
2745 // Decode the favicon using WebKit's image decoder.
2746 webkit_glue::ImageDecoder decoder(gfx::Size(kFavIconSize, kFavIconSize));
2747 const unsigned char* src_data =
2748 reinterpret_cast<const unsigned char*>(&data[0]);
2749
2750 return decoder.Decode(src_data, data.size());
2751 }
2752 return SkBitmap();
2753}
2754
initial.commit09911bf2008-07-26 23:55:292755void RenderView::OnGetApplicationInfo(int page_id) {
2756 webkit_glue::WebApplicationInfo app_info;
2757 if (page_id == page_id_)
2758 webkit_glue::GetApplicationInfo(webview(), &app_info);
2759
2760 // Prune out any data URLs in the set of icons. The browser process expects
2761 // any icon with a data URL to have originated from a favicon. We don't want
2762 // to decode arbitrary data URLs in the browser process. See
2763 // http://b/issue?id=1162972
2764 for (size_t i = 0; i < app_info.icons.size(); ++i) {
[email protected]6de74452009-02-25 18:04:592765 if (app_info.icons[i].url.SchemeIs(chrome::kDataScheme)) {
initial.commit09911bf2008-07-26 23:55:292766 app_info.icons.erase(app_info.icons.begin() + i);
2767 --i;
2768 }
2769 }
2770
2771 Send(new ViewHostMsg_DidGetApplicationInfo(routing_id_, page_id, app_info));
2772}
2773
[email protected]7ccddb8c2009-08-04 17:36:552774GURL RenderView::GetAlternateErrorPageURL(const GURL& failed_url,
initial.commit09911bf2008-07-26 23:55:292775 ErrorPageType error_type) {
[email protected]7ccddb8c2009-08-04 17:36:552776 if (failed_url.SchemeIsSecure()) {
initial.commit09911bf2008-07-26 23:55:292777 // If the URL that failed was secure, then the embedding web page was not
2778 // expecting a network attacker to be able to manipulate its contents. As
2779 // we fetch alternate error pages over HTTP, we would be allowing a network
2780 // attacker to manipulate the contents of the response if we tried to use
2781 // the link doctor here.
2782 return GURL::EmptyGURL();
2783 }
2784
2785 // Grab the base URL from the browser process.
2786 if (!alternate_error_page_url_.is_valid())
2787 return GURL::EmptyGURL();
2788
2789 // Strip query params from the failed URL.
2790 GURL::Replacements remove_params;
2791 remove_params.ClearUsername();
2792 remove_params.ClearPassword();
2793 remove_params.ClearQuery();
2794 remove_params.ClearRef();
[email protected]7ccddb8c2009-08-04 17:36:552795 const GURL url_to_send = failed_url.ReplaceComponents(remove_params);
initial.commit09911bf2008-07-26 23:55:292796
2797 // Construct the query params to send to link doctor.
2798 std::string params(alternate_error_page_url_.query());
2799 params.append("&url=");
2800 params.append(EscapeQueryParamValue(url_to_send.spec()));
2801 params.append("&sourceid=chrome");
2802 params.append("&error=");
2803 switch (error_type) {
2804 case DNS_ERROR:
2805 params.append("dnserror");
2806 break;
2807
2808 case HTTP_404:
2809 params.append("http404");
2810 break;
2811
[email protected]5df266ac2008-10-15 19:50:132812 case CONNECTION_ERROR:
[email protected]e1f934b2009-01-26 20:41:332813 params.append("connectionfailure");
[email protected]5df266ac2008-10-15 19:50:132814 break;
2815
initial.commit09911bf2008-07-26 23:55:292816 default:
2817 NOTREACHED() << "unknown ErrorPageType";
2818 }
2819
2820 // OK, build the final url to return.
2821 GURL::Replacements link_doctor_params;
2822 link_doctor_params.SetQueryStr(params);
2823 GURL url = alternate_error_page_url_.ReplaceComponents(link_doctor_params);
2824 return url;
2825}
2826
[email protected]6069da8c2009-10-20 20:33:492827void RenderView::OnFind(int request_id, const string16& search_text,
2828 const WebFindOptions& options) {
[email protected]26aa0482009-09-30 16:55:272829 WebFrame* main_frame = webview()->mainFrame();
[email protected]b4bb2502009-10-01 22:35:272830 WebFrame* frame_after_main = main_frame->traverseNext(true);
[email protected]26aa0482009-09-30 16:55:272831 WebFrame* focused_frame = webview()->focusedFrame();
initial.commit09911bf2008-07-26 23:55:292832 WebFrame* search_frame = focused_frame; // start searching focused frame.
2833
2834 bool multi_frame = (frame_after_main != main_frame);
2835
2836 // If we have multiple frames, we don't want to wrap the search within the
2837 // frame, so we check here if we only have main_frame in the chain.
2838 bool wrap_within_frame = !multi_frame;
2839
[email protected]b3f2b912009-04-09 16:18:522840 WebRect selection_rect;
initial.commit09911bf2008-07-26 23:55:292841 bool result = false;
2842
[email protected]7830da3e2009-11-06 16:27:262843 // If something is selected when we start searching it means we cannot just
2844 // increment the current match ordinal; we need to re-generate it.
2845 WebRange current_selection = focused_frame->selectionRange();
2846
initial.commit09911bf2008-07-26 23:55:292847 do {
[email protected]dd7daa82009-08-10 05:46:452848 result = search_frame->find(
[email protected]7ea066a2009-04-06 20:21:592849 request_id, search_text, options, wrap_within_frame, &selection_rect);
initial.commit09911bf2008-07-26 23:55:292850
2851 if (!result) {
2852 // don't leave text selected as you move to the next frame.
[email protected]a100d76bb2009-08-14 17:50:222853 search_frame->executeCommand(WebString::fromUTF8("Unselect"));
initial.commit09911bf2008-07-26 23:55:292854
2855 // Find the next frame, but skip the invisible ones.
2856 do {
2857 // What is the next frame to search? (we might be going backwards). Note
2858 // that we specify wrap=true so that search_frame never becomes NULL.
[email protected]7ea066a2009-04-06 20:21:592859 search_frame = options.forward ?
[email protected]b4bb2502009-10-01 22:35:272860 search_frame->traverseNext(true) :
2861 search_frame->traversePrevious(true);
[email protected]dd7daa82009-08-10 05:46:452862 } while (!search_frame->hasVisibleContent() &&
2863 search_frame != focused_frame);
initial.commit09911bf2008-07-26 23:55:292864
[email protected]884db412008-11-24 23:46:502865 // Make sure selection doesn't affect the search operation in new frame.
[email protected]a100d76bb2009-08-14 17:50:222866 search_frame->executeCommand(WebString::fromUTF8("Unselect"));
initial.commit09911bf2008-07-26 23:55:292867
2868 // If we have multiple frames and we have wrapped back around to the
2869 // focused frame, we need to search it once more allowing wrap within
2870 // the frame, otherwise it will report 'no match' if the focused frame has
2871 // reported matches, but no frames after the focused_frame contain a
2872 // match for the search word(s).
2873 if (multi_frame && search_frame == focused_frame) {
[email protected]dd7daa82009-08-10 05:46:452874 result = search_frame->find(
[email protected]7ea066a2009-04-06 20:21:592875 request_id, search_text, options, true, // Force wrapping.
2876 &selection_rect);
initial.commit09911bf2008-07-26 23:55:292877 }
2878 }
2879
[email protected]26aa0482009-09-30 16:55:272880 webview()->setFocusedFrame(search_frame);
initial.commit09911bf2008-07-26 23:55:292881 } while (!result && search_frame != focused_frame);
2882
[email protected]7830da3e2009-11-06 16:27:262883 if (options.findNext && current_selection.isNull()) {
[email protected]4f3dc372009-02-24 00:10:292884 // Force the main_frame to report the actual count.
[email protected]dd7daa82009-08-10 05:46:452885 main_frame->increaseMatchCount(0, request_id);
[email protected]4f3dc372009-02-24 00:10:292886 } else {
2887 // If nothing is found, set result to "0 of 0", otherwise, set it to
2888 // "-1 of 1" to indicate that we found at least one item, but we don't know
2889 // yet what is active.
2890 int ordinal = result ? -1 : 0; // -1 here means, we might know more later.
2891 int match_count = result ? 1 : 0; // 1 here means possibly more coming.
initial.commit09911bf2008-07-26 23:55:292892
[email protected]4f3dc372009-02-24 00:10:292893 // If we find no matches then this will be our last status update.
2894 // Otherwise the scoping effort will send more results.
2895 bool final_status_update = !result;
initial.commit09911bf2008-07-26 23:55:292896
[email protected]4f3dc372009-02-24 00:10:292897 // Send the search result over to the browser process.
[email protected]4f999132009-03-31 18:08:402898 Send(new ViewHostMsg_Find_Reply(routing_id_,
[email protected]7ea066a2009-04-06 20:21:592899 request_id,
[email protected]4f3dc372009-02-24 00:10:292900 match_count,
2901 selection_rect,
2902 ordinal,
2903 final_status_update));
initial.commit09911bf2008-07-26 23:55:292904
initial.commit09911bf2008-07-26 23:55:292905 // Scoping effort begins, starting with the mainframe.
2906 search_frame = main_frame;
2907
[email protected]dd7daa82009-08-10 05:46:452908 main_frame->resetMatchCount();
initial.commit09911bf2008-07-26 23:55:292909
2910 do {
2911 // Cancel all old scoping requests before starting a new one.
[email protected]dd7daa82009-08-10 05:46:452912 search_frame->cancelPendingScopingEffort();
initial.commit09911bf2008-07-26 23:55:292913
2914 // We don't start another scoping effort unless at least one match has
2915 // been found.
2916 if (result) {
2917 // Start new scoping request. If the scoping function determines that it
2918 // needs to scope, it will defer until later.
[email protected]dd7daa82009-08-10 05:46:452919 search_frame->scopeStringMatches(request_id,
[email protected]7ea066a2009-04-06 20:21:592920 search_text,
2921 options,
initial.commit09911bf2008-07-26 23:55:292922 true); // reset the tickmarks
2923 }
2924
2925 // Iterate to the next frame. The frame will not necessarily scope, for
2926 // example if it is not visible.
[email protected]b4bb2502009-10-01 22:35:272927 search_frame = search_frame->traverseNext(true);
initial.commit09911bf2008-07-26 23:55:292928 } while (search_frame != main_frame);
2929 }
2930}
2931
[email protected]5c4266922009-07-10 16:41:272932void RenderView::OnDeterminePageText() {
2933 if (!is_loading_) {
2934 if (!webview())
2935 return;
[email protected]26aa0482009-09-30 16:55:272936 WebFrame* main_frame = webview()->mainFrame();
[email protected]5c4266922009-07-10 16:41:272937 std::wstring contents;
2938 CaptureText(main_frame, &contents);
2939 Send(new ViewMsg_DeterminePageText_Reply(routing_id_, contents));
2940 determine_page_text_after_loading_stops_ = false;
2941 return;
2942 }
2943
2944 // We set |determine_page_text_after_loading_stops_| true here so that,
2945 // after page has been loaded completely, the text in the page is captured.
2946 determine_page_text_after_loading_stops_ = true;
2947}
2948
initial.commit09911bf2008-07-26 23:55:292949void RenderView::DnsPrefetch(const std::vector<std::string>& host_names) {
2950 Send(new ViewHostMsg_DnsPrefetch(host_names));
2951}
2952
[email protected]630e26b2008-10-14 22:55:172953void RenderView::OnZoom(int function) {
2954 static const bool kZoomIsTextOnly = false;
2955 switch (function) {
2956 case PageZoom::SMALLER:
[email protected]26aa0482009-09-30 16:55:272957 webview()->zoomOut(kZoomIsTextOnly);
initial.commit09911bf2008-07-26 23:55:292958 break;
[email protected]630e26b2008-10-14 22:55:172959 case PageZoom::STANDARD:
[email protected]26aa0482009-09-30 16:55:272960 webview()->zoomDefault();
initial.commit09911bf2008-07-26 23:55:292961 break;
[email protected]630e26b2008-10-14 22:55:172962 case PageZoom::LARGER:
[email protected]26aa0482009-09-30 16:55:272963 webview()->zoomIn(kZoomIsTextOnly);
initial.commit09911bf2008-07-26 23:55:292964 break;
2965 default:
2966 NOTREACHED();
2967 }
2968}
2969
[email protected]41fc0322009-09-04 22:23:402970void RenderView::OnSetPageEncoding(const std::string& encoding_name) {
[email protected]26aa0482009-09-30 16:55:272971 webview()->setPageEncoding(WebString::fromUTF8(encoding_name));
initial.commit09911bf2008-07-26 23:55:292972}
2973
[email protected]a697f4c2009-09-14 22:30:182974void RenderView::OnResetPageEncodingToDefault() {
[email protected]26aa0482009-09-30 16:55:272975 WebString no_encoding;
2976 webview()->setPageEncoding(no_encoding);
[email protected]a697f4c2009-09-14 22:30:182977}
2978
[email protected]dd7daa82009-08-10 05:46:452979WebFrame* RenderView::GetChildFrame(const std::wstring& xpath) const {
2980 if (xpath.empty())
[email protected]26aa0482009-09-30 16:55:272981 return webview()->mainFrame();
[email protected]dd7daa82009-08-10 05:46:452982
2983 // xpath string can represent a frame deep down the tree (across multiple
2984 // frame DOMs).
2985 // Example, /html/body/table/tbody/tr/td/iframe\n/frameset/frame[0]
2986 // should break into 2 xpaths
2987 // /html/body/table/tbody/tr/td/iframe & /frameset/frame[0]
2988
[email protected]26aa0482009-09-30 16:55:272989 WebFrame* frame = webview()->mainFrame();
[email protected]dd7daa82009-08-10 05:46:452990
2991 std::wstring xpath_remaining = xpath;
2992 while (!xpath_remaining.empty()) {
2993 std::wstring::size_type delim_pos = xpath_remaining.find_first_of(L'\n');
2994 std::wstring xpath_child;
2995 if (delim_pos != std::wstring::npos) {
2996 xpath_child = xpath_remaining.substr(0, delim_pos);
2997 xpath_remaining.erase(0, delim_pos + 1);
2998 } else {
2999 xpath_remaining.swap(xpath_child);
3000 }
3001 frame = frame->findChildByExpression(WideToUTF16Hack(xpath_child));
initial.commit09911bf2008-07-26 23:55:293002 }
3003
[email protected]dd7daa82009-08-10 05:46:453004 return frame;
initial.commit09911bf2008-07-26 23:55:293005}
3006
[email protected]f29acf52008-11-03 20:08:333007void RenderView::EvaluateScript(const std::wstring& frame_xpath,
3008 const std::wstring& script) {
initial.commit09911bf2008-07-26 23:55:293009 WebFrame* web_frame = GetChildFrame(frame_xpath);
3010 if (!web_frame)
3011 return;
3012
[email protected]dd7daa82009-08-10 05:46:453013 web_frame->executeScript(WebScriptSource(WideToUTF16Hack(script)));
initial.commit09911bf2008-07-26 23:55:293014}
3015
[email protected]1810e132009-03-24 23:35:483016void RenderView::InsertCSS(const std::wstring& frame_xpath,
[email protected]ffaef0c2009-09-15 17:08:083017 const std::string& css,
3018 const std::string& id) {
[email protected]1810e132009-03-24 23:35:483019 WebFrame* web_frame = GetChildFrame(frame_xpath);
3020 if (!web_frame)
3021 return;
3022
[email protected]ffaef0c2009-09-15 17:08:083023 web_frame->insertStyleText(WebString::fromUTF8(css), WebString::fromUTF8(id));
[email protected]1810e132009-03-24 23:35:483024}
3025
initial.commit09911bf2008-07-26 23:55:293026void RenderView::OnScriptEvalRequest(const std::wstring& frame_xpath,
3027 const std::wstring& jscript) {
[email protected]f29acf52008-11-03 20:08:333028 EvaluateScript(frame_xpath, jscript);
initial.commit09911bf2008-07-26 23:55:293029}
3030
[email protected]1810e132009-03-24 23:35:483031void RenderView::OnCSSInsertRequest(const std::wstring& frame_xpath,
[email protected]ffaef0c2009-09-15 17:08:083032 const std::string& css,
3033 const std::string& id) {
3034 InsertCSS(frame_xpath, css, id);
[email protected]ae461542009-06-19 19:03:413035
3036 // Notify RenderViewHost that css has been inserted into the frame.
3037 Send(new ViewHostMsg_OnCSSInserted(routing_id_));
[email protected]1810e132009-03-24 23:35:483038}
3039
[email protected]7ea066a2009-04-06 20:21:593040void RenderView::OnAddMessageToConsole(
3041 const string16& frame_xpath,
3042 const string16& message,
3043 const WebConsoleMessage::Level& level) {
3044 WebFrame* web_frame = GetChildFrame(UTF16ToWideHack(frame_xpath));
[email protected]0dea3ea2009-03-31 23:30:593045 if (web_frame)
[email protected]dd7daa82009-08-10 05:46:453046 web_frame->addMessageToConsole(WebConsoleMessage(level, message));
initial.commit09911bf2008-07-26 23:55:293047}
3048
[email protected]81e63782009-02-27 19:35:093049void RenderView::OnAllowBindings(int enabled_bindings_flags) {
3050 enabled_bindings_ |= enabled_bindings_flags;
initial.commit09911bf2008-07-26 23:55:293051}
3052
3053void RenderView::OnSetDOMUIProperty(const std::string& name,
3054 const std::string& value) {
[email protected]81e63782009-02-27 19:35:093055 DCHECK(BindingsPolicy::is_dom_ui_enabled(enabled_bindings_));
initial.commit09911bf2008-07-26 23:55:293056 dom_ui_bindings_.SetProperty(name, value);
3057}
3058
3059void RenderView::OnReservePageIDRange(int size_of_range) {
3060 next_page_id_ += size_of_range + 1;
3061}
3062
[email protected]e80c73b2009-04-07 23:24:583063void RenderView::OnDragSourceEndedOrMoved(const gfx::Point& client_point,
3064 const gfx::Point& screen_point,
[email protected]1d9f4132009-09-08 17:29:253065 bool ended,
3066 WebDragOperation op) {
[email protected]5f9ae6c2009-07-08 02:38:033067 if (ended) {
[email protected]26aa0482009-09-30 16:55:273068 webview()->dragSourceEndedAt(client_point, screen_point, op);
[email protected]5f9ae6c2009-07-08 02:38:033069 } else {
[email protected]26aa0482009-09-30 16:55:273070 webview()->dragSourceMovedTo(client_point, screen_point);
[email protected]5f9ae6c2009-07-08 02:38:033071 }
initial.commit09911bf2008-07-26 23:55:293072}
3073
3074void RenderView::OnDragSourceSystemDragEnded() {
[email protected]26aa0482009-09-30 16:55:273075 webview()->dragSourceSystemDragEnded();
initial.commit09911bf2008-07-26 23:55:293076}
3077
initial.commit09911bf2008-07-26 23:55:293078void RenderView::OnFormFill(const FormData& form) {
3079 webkit_glue::FillForm(this->webview(), form);
3080}
3081
3082void RenderView::OnFillPasswordForm(
[email protected]daa8c58e2009-06-15 17:21:103083 const webkit_glue::PasswordFormDomManager::FillData& form_data) {
initial.commit09911bf2008-07-26 23:55:293084 webkit_glue::FillPasswordForm(this->webview(), form_data);
3085}
3086
3087void RenderView::OnDragTargetDragEnter(const WebDropData& drop_data,
[email protected]e80c73b2009-04-07 23:24:583088 const gfx::Point& client_point,
[email protected]1d9f4132009-09-08 17:29:253089 const gfx::Point& screen_point,
3090 WebDragOperationsMask ops) {
[email protected]26aa0482009-09-30 16:55:273091 WebDragOperation operation = webview()->dragTargetDragEnter(
[email protected]e80c73b2009-04-07 23:24:583092 drop_data.ToDragData(),
3093 drop_data.identity,
3094 client_point,
[email protected]1d9f4132009-09-08 17:29:253095 screen_point,
3096 ops);
initial.commit09911bf2008-07-26 23:55:293097
[email protected]1d9f4132009-09-08 17:29:253098 Send(new ViewHostMsg_UpdateDragCursor(routing_id_, operation));
initial.commit09911bf2008-07-26 23:55:293099}
3100
[email protected]e80c73b2009-04-07 23:24:583101void RenderView::OnDragTargetDragOver(const gfx::Point& client_point,
[email protected]1d9f4132009-09-08 17:29:253102 const gfx::Point& screen_point,
3103 WebDragOperationsMask ops) {
[email protected]26aa0482009-09-30 16:55:273104 WebDragOperation operation = webview()->dragTargetDragOver(
[email protected]1d9f4132009-09-08 17:29:253105 client_point,
3106 screen_point,
3107 ops);
initial.commit09911bf2008-07-26 23:55:293108
[email protected]1d9f4132009-09-08 17:29:253109 Send(new ViewHostMsg_UpdateDragCursor(routing_id_, operation));
initial.commit09911bf2008-07-26 23:55:293110}
3111
3112void RenderView::OnDragTargetDragLeave() {
[email protected]26aa0482009-09-30 16:55:273113 webview()->dragTargetDragLeave();
initial.commit09911bf2008-07-26 23:55:293114}
3115
[email protected]e80c73b2009-04-07 23:24:583116void RenderView::OnDragTargetDrop(const gfx::Point& client_point,
3117 const gfx::Point& screen_point) {
[email protected]26aa0482009-09-30 16:55:273118 webview()->dragTargetDrop(client_point, screen_point);
initial.commit09911bf2008-07-26 23:55:293119}
3120
3121void RenderView::OnUpdateWebPreferences(const WebPreferences& prefs) {
[email protected]2fab253a2009-08-17 23:00:593122 webkit_preferences_ = prefs;
3123 webkit_preferences_.Apply(webview());
initial.commit09911bf2008-07-26 23:55:293124}
3125
3126void RenderView::OnSetAltErrorPageURL(const GURL& url) {
3127 alternate_error_page_url_ = url;
3128}
3129
initial.commit09911bf2008-07-26 23:55:293130void RenderView::OnInstallMissingPlugin() {
3131 // This could happen when the first default plugin is deleted.
[email protected]f103ab72009-09-02 17:10:593132 if (first_default_plugin_)
3133 first_default_plugin_->InstallMissingPlugin();
initial.commit09911bf2008-07-26 23:55:293134}
3135
[email protected]b62d1a8c2009-01-13 23:54:573136void RenderView::OnFileChooserResponse(
[email protected]561abe62009-04-06 18:08:343137 const std::vector<FilePath>& file_names) {
[email protected]8029f5672009-03-20 22:33:363138 // This could happen if we navigated to a different page before the user
3139 // closed the chooser.
[email protected]a1128322009-10-06 18:38:463140 if (!file_chooser_completion_)
[email protected]8029f5672009-03-20 22:33:363141 return;
3142
[email protected]6069da8c2009-10-20 20:33:493143 WebVector<WebString> ws_file_names(file_names.size());
[email protected]a1128322009-10-06 18:38:463144 for (size_t i = 0; i < file_names.size(); ++i) {
3145 ws_file_names[i] = webkit_glue::FilePathToWebString(file_names[i]);
3146 }
3147
3148 file_chooser_completion_->didChooseFile(ws_file_names);
3149 // Reset the chooser pointer
3150 file_chooser_completion_ = NULL;
initial.commit09911bf2008-07-26 23:55:293151}
3152
3153void RenderView::OnEnableViewSourceMode() {
3154 if (!webview())
3155 return;
[email protected]26aa0482009-09-30 16:55:273156 WebFrame* main_frame = webview()->mainFrame();
initial.commit09911bf2008-07-26 23:55:293157 if (!main_frame)
3158 return;
3159
[email protected]dd7daa82009-08-10 05:46:453160 main_frame->enableViewSourceMode(true);
initial.commit09911bf2008-07-26 23:55:293161}
3162
[email protected]ab32b16c2009-10-16 14:57:253163void RenderView::OnEnablePreferredSizeChangedMode() {
3164 send_preferred_size_changes_ = true;
[email protected]0666aef2009-05-13 19:48:083165}
3166
[email protected]80d96fa2009-06-10 22:34:513167void RenderView::OnSetRendererPrefs(const RendererPreferences& renderer_prefs) {
3168 renderer_preferences_ = renderer_prefs;
[email protected]6e282c92009-07-24 01:19:373169 UpdateFontRenderingFromRendererPrefs();
[email protected]033970a2009-10-14 16:45:053170#if defined(OS_LINUX) && !defined(TOOLKIT_VIEWS)
[email protected]1c83eb42009-09-11 21:08:413171 WebColorName name = WebKit::WebColorWebkitFocusRingColor;
3172 WebKit::setNamedColors(&name, &renderer_prefs.focus_ring_color, 1);
[email protected]7a74e102009-09-03 00:16:563173#endif
[email protected]80d96fa2009-06-10 22:34:513174}
3175
[email protected]952cb702009-10-07 05:50:283176void RenderView::OnMediaPlayerActionAt(const gfx::Point& location,
3177 const WebMediaPlayerAction& action) {
3178 if (webview())
3179 webview()->performMediaPlayerAction(action, location);
[email protected]581b87eb2009-07-23 23:06:563180}
3181
[email protected]7b291f92009-08-14 05:43:533182void RenderView::OnNotifyRendererViewType(ViewType::Type type) {
[email protected]078b34612009-09-19 19:31:513183 // When this is first set, the bindings aren't fully loaded. We only need
3184 // to call through this API after the page has already been loaded. It's
3185 // also called in didCreateDocumentElement to bootstrap.
3186 if (view_type_ != ViewType::INVALID) {
3187 if (type == ViewType::EXTENSION_MOLE ||
3188 type == ViewType::EXTENSION_TOOLSTRIP) {
3189 ExtensionProcessBindings::SetViewType(webview(), type);
3190 }
3191 }
[email protected]7b291f92009-08-14 05:43:533192 view_type_ = type;
3193}
3194
3195void RenderView::OnUpdateBrowserWindowId(int window_id) {
3196 browser_window_id_ = window_id;
3197}
3198
initial.commit09911bf2008-07-26 23:55:293199void RenderView::OnUpdateBackForwardListCount(int back_list_count,
3200 int forward_list_count) {
3201 history_back_list_count_ = back_list_count;
3202 history_forward_list_count_ = forward_list_count;
3203}
3204
[email protected]266eb6f2008-09-30 23:56:503205void RenderView::OnGetAccessibilityInfo(
[email protected]6a983b42009-03-20 20:12:253206 const webkit_glue::WebAccessibility::InParams& in_params,
3207 webkit_glue::WebAccessibility::OutParams* out_params) {
[email protected]6c8afae52009-01-22 02:24:573208#if defined(OS_WIN)
[email protected]c7287a92009-11-04 20:06:153209 if (!accessibility_.get()) {
3210 // TODO(dglazkov): Once implemented for all ports, remove lazy
3211 // instantiation of accessibility_.
3212 accessibility_.reset(WebAccessibilityCache::create());
3213 accessibility_->initialize(webview());
[email protected]6a983b42009-03-20 20:12:253214 }
[email protected]266eb6f2008-09-30 23:56:503215
[email protected]c7287a92009-11-04 20:06:153216 webkit_glue::WebAccessibility::GetAccObjInfo(accessibility_.get(),
3217 in_params,
3218 out_params);
3219
[email protected]6c8afae52009-01-22 02:24:573220#else // defined(OS_WIN)
3221 // TODO(port): accessibility not yet implemented
3222 NOTIMPLEMENTED();
3223#endif
[email protected]266eb6f2008-09-30 23:56:503224}
3225
[email protected]6a983b42009-03-20 20:12:253226void RenderView::OnClearAccessibilityInfo(int acc_obj_id, bool clear_all) {
[email protected]6c8afae52009-01-22 02:24:573227#if defined(OS_WIN)
[email protected]c7287a92009-11-04 20:06:153228 if (!accessibility_.get()) {
[email protected]266eb6f2008-09-30 23:56:503229 // If accessibility is not activated, ignore clearing message.
3230 return;
3231 }
[email protected]e846d0d2009-05-20 00:53:063232
[email protected]c7287a92009-11-04 20:06:153233 if (clear_all) {
3234 accessibility_->clear();
[email protected]266eb6f2008-09-30 23:56:503235 return;
[email protected]c7287a92009-11-04 20:06:153236 }
3237
3238 accessibility_->remove(acc_obj_id);
[email protected]e846d0d2009-05-20 00:53:063239
[email protected]6c8afae52009-01-22 02:24:573240#else // defined(OS_WIN)
3241 // TODO(port): accessibility not yet implemented
3242 NOTIMPLEMENTED();
3243#endif
[email protected]266eb6f2008-09-30 23:56:503244}
3245
initial.commit09911bf2008-07-26 23:55:293246void RenderView::OnGetAllSavableResourceLinksForCurrentPage(
3247 const GURL& page_url) {
3248 // Prepare list to storage all savable resource links.
3249 std::vector<GURL> resources_list;
3250 std::vector<GURL> referrers_list;
3251 std::vector<GURL> frames_list;
3252 webkit_glue::SavableResourcesResult result(&resources_list,
3253 &referrers_list,
3254 &frames_list);
3255
[email protected]dbeb3952009-10-13 18:01:183256 if (!webkit_glue::GetAllSavableResourceLinksForCurrentPage(
3257 webview(),
3258 page_url,
3259 &result,
3260 chrome::kSavableSchemes)) {
initial.commit09911bf2008-07-26 23:55:293261 // If something is wrong when collecting all savable resource links,
3262 // send empty list to embedder(browser) to tell it failed.
3263 referrers_list.clear();
3264 resources_list.clear();
3265 frames_list.clear();
3266 }
3267
3268 // Send result of all savable resource links to embedder.
3269 Send(new ViewHostMsg_SendCurrentPageAllSavableResourceLinks(routing_id_,
3270 resources_list,
3271 referrers_list,
3272 frames_list));
3273}
3274
3275void RenderView::OnGetSerializedHtmlDataForCurrentPageWithLocalLinks(
[email protected]f6b48532009-02-12 01:56:323276 const std::vector<GURL>& links,
[email protected]fde6714d12009-02-18 22:39:313277 const std::vector<FilePath>& local_paths,
3278 const FilePath& local_directory_name) {
[email protected]26aa0482009-09-30 16:55:273279 webkit_glue::DomSerializer dom_serializer(webview()->mainFrame(),
initial.commit09911bf2008-07-26 23:55:293280 true,
3281 this,
3282 links,
3283 local_paths,
3284 local_directory_name);
3285 dom_serializer.SerializeDom();
3286}
3287
3288void RenderView::DidSerializeDataForFrame(const GURL& frame_url,
3289 const std::string& data, PageSavingSerializationStatus status) {
3290 Send(new ViewHostMsg_SendSerializedHtmlData(routing_id_,
3291 frame_url, data, static_cast<int32>(status)));
3292}
3293
[email protected]04b4a6c2008-08-02 00:44:473294void RenderView::OnMsgShouldClose() {
[email protected]26aa0482009-09-30 16:55:273295 bool should_close = webview()->dispatchBeforeUnloadEvent();
[email protected]04b4a6c2008-08-02 00:44:473296 Send(new ViewHostMsg_ShouldClose_ACK(routing_id_, should_close));
initial.commit09911bf2008-07-26 23:55:293297}
3298
[email protected]eb6b87a2009-07-24 15:57:393299void RenderView::OnClosePage(const ViewMsg_ClosePage_Params& params) {
initial.commit09911bf2008-07-26 23:55:293300 // TODO(creis): We'd rather use webview()->Close() here, but that currently
3301 // sets the WebView's delegate_ to NULL, preventing any JavaScript dialogs
3302 // in the onunload handler from appearing. For now, we're bypassing that and
3303 // calling the FrameLoader's CloseURL method directly. This should be
3304 // revisited to avoid having two ways to close a page. Having a single way
3305 // to close that can run onunload is also useful for fixing
3306 // http://b/issue?id=753080.
[email protected]26aa0482009-09-30 16:55:273307 WebFrame* main_frame = webview()->mainFrame();
[email protected]7a9b51f2009-06-29 21:28:293308 if (main_frame) {
[email protected]dd7daa82009-08-10 05:46:453309 const GURL& url = main_frame->url();
[email protected]3d9689372009-09-10 04:29:173310 // TODO(davemoore) this code should be removed once willClose() gets
[email protected]7a9b51f2009-06-29 21:28:293311 // called when a page is destroyed. DumpLoadHistograms() is safe to call
3312 // multiple times for the same frame, but it will simplify things.
[email protected]dd7daa82009-08-10 05:46:453313 if (url.SchemeIs(chrome::kHttpScheme) ||
3314 url.SchemeIs(chrome::kHttpsScheme))
[email protected]7a9b51f2009-06-29 21:28:293315 DumpLoadHistograms();
[email protected]7a9b51f2009-06-29 21:28:293316 }
[email protected]26aa0482009-09-30 16:55:273317 webview()->dispatchUnloadEvent();
initial.commit09911bf2008-07-26 23:55:293318
[email protected]eb6b87a2009-07-24 15:57:393319 // Just echo back the params in the ACK.
3320 Send(new ViewHostMsg_ClosePage_ACK(routing_id_, params));
initial.commit09911bf2008-07-26 23:55:293321}
3322
3323void RenderView::OnThemeChanged() {
[email protected]6c8afae52009-01-22 02:24:573324#if defined(OS_WIN)
initial.commit09911bf2008-07-26 23:55:293325 gfx::NativeTheme::instance()->CloseHandles();
3326 gfx::Rect view_rect(0, 0, size_.width(), size_.height());
[email protected]4873c7d2009-07-16 06:36:283327 didInvalidateRect(view_rect);
[email protected]6c8afae52009-01-22 02:24:573328#else // defined(OS_WIN)
3329 // TODO(port): we don't support theming on non-Windows platforms yet
3330 NOTIMPLEMENTED();
3331#endif
initial.commit09911bf2008-07-26 23:55:293332}
3333
[email protected]28790922009-03-09 19:48:373334void RenderView::OnMessageFromExternalHost(const std::string& message,
3335 const std::string& origin,
3336 const std::string& target) {
[email protected]3ac14a052008-08-15 21:22:153337 if (message.empty())
3338 return;
3339
[email protected]28790922009-03-09 19:48:373340 external_host_bindings_.ForwardMessageFromExternalHost(message, origin,
3341 target);
[email protected]3ac14a052008-08-15 21:22:153342}
3343
[email protected]0aa55312008-10-17 21:53:083344void RenderView::OnDisassociateFromPopupCount() {
3345 if (decrement_shared_popup_at_destruction_)
3346 shared_popup_counter_->data--;
3347 shared_popup_counter_ = new SharedRenderViewCounter(0);
3348 decrement_shared_popup_at_destruction_ = false;
3349}
3350
[email protected]15d79e12009-08-02 19:23:453351bool RenderView::MaybeLoadAlternateErrorPage(WebFrame* frame,
3352 const WebURLError& error,
3353 bool replace) {
3354 // We only show alternate error pages in the main frame. They are
3355 // intended to assist the user when navigating, so there is not much
3356 // value in showing them for failed subframes. Ideally, we would be
3357 // able to use the TYPED transition type for this, but that flag is
3358 // not preserved across page reloads.
[email protected]dd7daa82009-08-10 05:46:453359 if (frame->parent())
[email protected]15d79e12009-08-02 19:23:453360 return false;
3361
3362 // Use the alternate error page service if this is a DNS failure or
[email protected]c53976d52009-08-07 18:58:373363 // connection failure.
[email protected]15d79e12009-08-02 19:23:453364 int ec = error.reason;
3365 if (ec != net::ERR_NAME_NOT_RESOLVED &&
3366 ec != net::ERR_CONNECTION_FAILED &&
3367 ec != net::ERR_CONNECTION_REFUSED &&
3368 ec != net::ERR_ADDRESS_UNREACHABLE &&
[email protected]c53976d52009-08-07 18:58:373369 ec != net::ERR_CONNECTION_TIMED_OUT)
[email protected]15d79e12009-08-02 19:23:453370 return false;
3371
3372 const GURL& error_page_url = GetAlternateErrorPageURL(error.unreachableURL,
[email protected]7ccddb8c2009-08-04 17:36:553373 ec == net::ERR_NAME_NOT_RESOLVED ? DNS_ERROR : CONNECTION_ERROR);
[email protected]15d79e12009-08-02 19:23:453374 if (!error_page_url.is_valid())
3375 return false;
3376
3377 // Load an empty page first so there is an immediate response to the error,
3378 // and then kick off a request for the alternate error page.
[email protected]dd7daa82009-08-10 05:46:453379 frame->loadHTMLString(std::string(),
[email protected]15d79e12009-08-02 19:23:453380 GURL(kUnreachableWebDataURL),
3381 error.unreachableURL,
3382 replace);
3383
3384 // Now, create a fetcher for the error page and associate it with the data
3385 // source we just created via the LoadHTMLString call. That way if another
3386 // navigation occurs, the fetcher will get destroyed.
3387 NavigationState* navigation_state =
[email protected]dd7daa82009-08-10 05:46:453388 NavigationState::FromDataSource(frame->provisionalDataSource());
[email protected]15d79e12009-08-02 19:23:453389 navigation_state->set_alt_error_page_fetcher(
3390 new AltErrorPageResourceFetcher(
3391 error_page_url, frame, error,
3392 NewCallback(this, &RenderView::AltErrorPageFinished)));
3393 return true;
3394}
3395
initial.commit09911bf2008-07-26 23:55:293396std::string RenderView::GetAltHTMLForTemplate(
3397 const DictionaryValue& error_strings, int template_resource_id) const {
[email protected]8a16266e2009-09-10 21:08:393398 const base::StringPiece template_html(
initial.commit09911bf2008-07-26 23:55:293399 ResourceBundle::GetSharedInstance().GetRawDataResource(
3400 template_resource_id));
3401
3402 if (template_html.empty()) {
3403 NOTREACHED() << "unable to load template. ID: " << template_resource_id;
3404 return "";
3405 }
[email protected]7cd22a52009-07-14 00:40:253406
initial.commit09911bf2008-07-26 23:55:293407 // "t" is the id of the templates root node.
[email protected]7cd22a52009-07-14 00:40:253408 return jstemplate_builder::GetTemplatesHtml(
initial.commit09911bf2008-07-26 23:55:293409 template_html, &error_strings, "t");
3410}
[email protected]0e79b9e2009-02-13 04:20:483411
[email protected]15d79e12009-08-02 19:23:453412void RenderView::AltErrorPageFinished(WebFrame* frame,
3413 const WebURLError& original_error,
3414 const std::string& html) {
3415 // Here, we replace the blank page we loaded previously.
[email protected]7ccddb8c2009-08-04 17:36:553416
3417 // If we failed to download the alternate error page, fall back to the
3418 // original error page if present. Otherwise, LoadNavigationErrorPage
3419 // will simply display a default error page.
3420 const std::string* html_to_load = &html;
3421 if (html.empty()) {
3422 NavigationState* navigation_state =
[email protected]dd7daa82009-08-10 05:46:453423 NavigationState::FromDataSource(frame->dataSource());
[email protected]7ccddb8c2009-08-04 17:36:553424 html_to_load = &navigation_state->postponed_data();
3425 }
3426 LoadNavigationErrorPage(
3427 frame, WebURLRequest(), original_error, *html_to_load, true);
[email protected]15d79e12009-08-02 19:23:453428}
3429
[email protected]30f75e62009-02-25 22:01:003430void RenderView::OnMoveOrResizeStarted() {
3431 if (webview())
[email protected]acca2a12009-10-16 03:53:393432 webview()->hideAutofillPopup();
[email protected]30f75e62009-02-25 22:01:003433}
3434
[email protected]30f75e62009-02-25 22:01:003435void RenderView::OnResize(const gfx::Size& new_size,
3436 const gfx::Rect& resizer_rect) {
3437 if (webview())
[email protected]acca2a12009-10-16 03:53:393438 webview()->hideAutofillPopup();
[email protected]30f75e62009-02-25 22:01:003439 RenderWidget::OnResize(new_size, resizer_rect);
3440}
[email protected]0aa477bd2009-03-23 22:21:433441
[email protected]05d478752009-04-08 23:38:163442void RenderView::OnClearFocusedNode() {
3443 if (webview())
[email protected]26aa0482009-09-30 16:55:273444 webview()->clearFocusedNode();
[email protected]05d478752009-04-08 23:38:163445}
3446
[email protected]699ab0d2009-04-23 23:19:143447void RenderView::OnSetBackground(const SkBitmap& background) {
3448 if (webview())
[email protected]b4bb2502009-10-01 22:35:273449 webview()->setIsTransparent(!background.empty());
[email protected]699ab0d2009-04-23 23:19:143450
3451 SetBackground(background);
3452}
3453
[email protected]8c66c5a2009-07-22 17:26:343454void RenderView::OnSetActive(bool active) {
3455 if (webview())
[email protected]b4bb2502009-10-01 22:35:273456 webview()->setIsActive(active);
[email protected]8c66c5a2009-07-22 17:26:343457}
3458
[email protected]309d7a282009-03-24 09:18:273459void RenderView::SendExtensionRequest(const std::string& name,
[email protected]e4dad9fb2009-10-06 18:15:583460 const ListValue& args,
[email protected]c6619182009-05-12 14:59:323461 int request_id,
[email protected]2f25d7b92009-06-10 00:06:473462 bool has_callback) {
[email protected]c6619182009-05-12 14:59:323463 Send(new ViewHostMsg_ExtensionRequest(routing_id_, name, args, request_id,
[email protected]2f25d7b92009-06-10 00:06:473464 has_callback));
[email protected]309d7a282009-03-24 09:18:273465}
3466
[email protected]c6619182009-05-12 14:59:323467void RenderView::OnExtensionResponse(int request_id,
3468 bool success,
3469 const std::string& response,
3470 const std::string& error) {
[email protected]0f6053962009-07-09 19:26:353471 ExtensionProcessBindings::HandleResponse(
3472 request_id, success, response, error);
[email protected]309d7a282009-03-24 09:18:273473}
[email protected]c20210e62009-04-03 21:39:263474
[email protected]078b34612009-09-19 19:31:513475void RenderView::InjectToolstripCSS() {
3476 if (view_type_ != ViewType::EXTENSION_TOOLSTRIP)
3477 return;
3478
3479 static const base::StringPiece toolstrip_css(
3480 ResourceBundle::GetSharedInstance().GetRawDataResource(
3481 IDR_EXTENSION_TOOLSTRIP_CSS));
3482 std::string css = toolstrip_css.as_string();
3483 InsertCSS(L"", css, "ToolstripDefaultCSS");
3484}
3485
[email protected]7120f132009-07-20 21:05:373486void RenderView::OnExtensionMessageInvoke(const std::string& function_name,
3487 const ListValue& args) {
3488 RendererExtensionBindings::Invoke(function_name, args, this);
3489}
3490
[email protected]e7e4f3c2009-04-21 15:24:083491// Dump all load time histograms.
[email protected]c20210e62009-04-03 21:39:263492//
[email protected]7a9b51f2009-06-29 21:28:293493// There are 13 histograms measuring various times.
[email protected]c20210e62009-04-03 21:39:263494// The time points we keep are
3495// request: time document was requested by user
3496// start: time load of document started
[email protected]a2f6bc112009-06-27 16:27:253497// commit: time load of document started
[email protected]7a9b51f2009-06-29 21:28:293498// finish_document: main document loaded, before onload()
[email protected]c20210e62009-04-03 21:39:263499// finish: after onload() and all resources are loaded
[email protected]7a9b51f2009-06-29 21:28:293500// first_paint: first paint performed
3501// first_paint_after_load: first paint performed after load is finished
3502// begin: request if it was user requested, start otherwise
3503//
[email protected]c20210e62009-04-03 21:39:263504// The times that we histogram are
[email protected]a2f6bc112009-06-27 16:27:253505// request->start,
[email protected]7a9b51f2009-06-29 21:28:293506// start->commit,
3507// commit->finish_document,
3508// finish_document->finish,
3509// begin->commit,
3510// begin->finishDoc,
3511// begin->finish,
3512// begin->first_paint,
3513// begin->first_paint_after_load
3514// commit->finishDoc,
3515// commit->first_paint,
3516// commit->first_paint_after_load,
3517// finish->first_paint_after_load,
[email protected]c20210e62009-04-03 21:39:263518//
[email protected]e7e4f3c2009-04-21 15:24:083519// It's possible for the request time not to be set, if a client
3520// redirect had been done (the user never requested the page)
3521// Also, it's possible to load a page without ever laying it out
[email protected]7a9b51f2009-06-29 21:28:293522// so first_paint and first_paint_after_load can be 0.
[email protected]c20210e62009-04-03 21:39:263523void RenderView::DumpLoadHistograms() const {
[email protected]26aa0482009-09-30 16:55:273524 WebFrame* main_frame = webview()->mainFrame();
[email protected]ed3fb032009-06-16 19:50:563525 NavigationState* navigation_state =
[email protected]dd7daa82009-08-10 05:46:453526 NavigationState::FromDataSource(main_frame->dataSource());
[email protected]7a9b51f2009-06-29 21:28:293527 Time finish = navigation_state->finish_load_time();
[email protected]ed3fb032009-06-16 19:50:563528
[email protected]7a9b51f2009-06-29 21:28:293529 // If we've already dumped or we haven't finished loading, do nothing.
3530 if (navigation_state->load_histograms_recorded() || finish.is_null())
3531 return;
[email protected]ed3fb032009-06-16 19:50:563532
[email protected]f8999642009-10-27 21:39:423533 LogNavigationState(navigation_state, main_frame->dataSource());
3534
[email protected]7a9b51f2009-06-29 21:28:293535 Time request = navigation_state->request_time();
3536 Time start = navigation_state->start_load_time();
3537 Time commit = navigation_state->commit_load_time();
3538 Time finish_doc = navigation_state->finish_document_load_time();
3539 Time first_paint = navigation_state->first_paint_time();
3540 Time first_paint_after_load =
3541 navigation_state->first_paint_after_load_time();
[email protected]c20210e62009-04-03 21:39:263542
[email protected]7a9b51f2009-06-29 21:28:293543 Time begin;
3544 // Client side redirects will have no request time.
3545 if (request.is_null()) {
3546 begin = start;
3547 } else {
3548 begin = request;
3549 UMA_HISTOGRAM_MEDIUM_TIMES("Renderer4.RequestToStart", start - request);
[email protected]e7e4f3c2009-04-21 15:24:083550 }
[email protected]7a9b51f2009-06-29 21:28:293551 UMA_HISTOGRAM_MEDIUM_TIMES("Renderer4.StartToCommit", commit - start);
3552 UMA_HISTOGRAM_MEDIUM_TIMES(
3553 "Renderer4.CommitToFinishDoc", finish_doc - commit);
3554 UMA_HISTOGRAM_MEDIUM_TIMES(
3555 "Renderer4.FinishDocToFinish", finish - finish_doc);
3556
3557 UMA_HISTOGRAM_MEDIUM_TIMES("Renderer4.BeginToCommit", commit - begin);
3558 UMA_HISTOGRAM_MEDIUM_TIMES("Renderer4.BeginToFinishDoc", finish_doc - begin);
[email protected]e695fbd62009-06-30 16:31:543559
3560 static const TimeDelta kBeginToFinishMin(TimeDelta::FromMilliseconds(10));
3561 static const TimeDelta kBeginToFinishMax(TimeDelta::FromMinutes(10));
3562 static const size_t kBeginToFinishBucketCount(100);
3563
3564 UMA_HISTOGRAM_CUSTOM_TIMES("Renderer4.BeginToFinish",
3565 finish - begin, kBeginToFinishMin,
3566 kBeginToFinishMax, kBeginToFinishBucketCount);
[email protected]0a32257a2009-07-09 18:10:413567 UMA_HISTOGRAM_CUSTOM_TIMES("Renderer4.StartToFinish",
3568 finish - start, kBeginToFinishMin,
3569 kBeginToFinishMax, kBeginToFinishBucketCount);
3570 if (!request.is_null())
3571 UMA_HISTOGRAM_CUSTOM_TIMES("Renderer4.RequestToFinish",
3572 finish - request, kBeginToFinishMin,
3573 kBeginToFinishMax, kBeginToFinishBucketCount);
[email protected]e695fbd62009-06-30 16:31:543574
[email protected]36285b52009-06-30 19:10:003575 static bool use_dns_histogram(FieldTrialList::Find("DnsImpact") &&
3576 !FieldTrialList::Find("DnsImpact")->group_name().empty());
[email protected]0a32257a2009-07-09 18:10:413577 if (use_dns_histogram) {
[email protected]36285b52009-06-30 19:10:003578 UMA_HISTOGRAM_CUSTOM_TIMES(
3579 FieldTrial::MakeName("Renderer4.BeginToFinish", "DnsImpact").data(),
3580 finish - begin, kBeginToFinishMin,
3581 kBeginToFinishMax, kBeginToFinishBucketCount);
[email protected]0a32257a2009-07-09 18:10:413582 UMA_HISTOGRAM_CUSTOM_TIMES(
3583 FieldTrial::MakeName("Renderer4.StartToFinish", "DnsImpact").data(),
3584 finish - start, kBeginToFinishMin,
3585 kBeginToFinishMax, kBeginToFinishBucketCount);
3586 if (!request.is_null())
3587 UMA_HISTOGRAM_CUSTOM_TIMES(
3588 FieldTrial::MakeName("Renderer4.RequestToFinish", "DnsImpact").data(),
3589 finish - request, kBeginToFinishMin,
3590 kBeginToFinishMax, kBeginToFinishBucketCount);
3591 }
[email protected]e695fbd62009-06-30 16:31:543592
[email protected]36285b52009-06-30 19:10:003593 static bool use_sdch_histogram(FieldTrialList::Find("GlobalSdch") &&
3594 !FieldTrialList::Find("GlobalSdch")->group_name().empty());
[email protected]0a32257a2009-07-09 18:10:413595 if (use_sdch_histogram) {
[email protected]36285b52009-06-30 19:10:003596 UMA_HISTOGRAM_CUSTOM_TIMES(
3597 FieldTrial::MakeName("Renderer4.BeginToFinish", "GlobalSdch").data(),
3598 finish - begin, kBeginToFinishMin,
3599 kBeginToFinishMax, kBeginToFinishBucketCount);
[email protected]0a32257a2009-07-09 18:10:413600 UMA_HISTOGRAM_CUSTOM_TIMES(
3601 FieldTrial::MakeName("Renderer4.StartToFinish", "GlobalSdch").data(),
3602 finish - start, kBeginToFinishMin,
3603 kBeginToFinishMax, kBeginToFinishBucketCount);
3604 if (!request.is_null())
3605 UMA_HISTOGRAM_CUSTOM_TIMES(
3606 FieldTrial::MakeName("Renderer4.RequestToFinish",
3607 "GlobalSdch").data(),
3608 finish - request, kBeginToFinishMin,
3609 kBeginToFinishMax, kBeginToFinishBucketCount);
3610 }
[email protected]7a9b51f2009-06-29 21:28:293611
[email protected]5fff93f2009-08-02 04:27:343612 static bool use_socket_late_binding_histogram =
3613 FieldTrialList::Find("SocketLateBinding") &&
3614 !FieldTrialList::Find("SocketLateBinding")->group_name().empty();
3615 if (use_socket_late_binding_histogram) {
3616 UMA_HISTOGRAM_CUSTOM_TIMES(
3617 FieldTrial::MakeName("Renderer4.BeginToFinish",
3618 "SocketLateBinding").data(),
3619 finish - begin, kBeginToFinishMin,
3620 kBeginToFinishMax, kBeginToFinishBucketCount);
3621 UMA_HISTOGRAM_CUSTOM_TIMES(
3622 FieldTrial::MakeName("Renderer4.StartToFinish",
3623 "SocketLateBinding").data(),
3624 finish - start, kBeginToFinishMin,
3625 kBeginToFinishMax, kBeginToFinishBucketCount);
3626 if (!request.is_null())
3627 UMA_HISTOGRAM_CUSTOM_TIMES(
3628 FieldTrial::MakeName("Renderer4.RequestToFinish",
3629 "SocketLateBinding").data(),
3630 finish - request, kBeginToFinishMin,
3631 kBeginToFinishMax, kBeginToFinishBucketCount);
3632 }
3633
[email protected]7e05f6c42009-07-11 01:50:483634 static bool use_cache_histogram1(FieldTrialList::Find("CacheSize") &&
3635 !FieldTrialList::Find("CacheSize")->group_name().empty());
3636 if (use_cache_histogram1)
3637 UMA_HISTOGRAM_CUSTOM_TIMES(
3638 FieldTrial::MakeName("Renderer4.StartToFinish", "CacheSize").data(),
3639 finish - start, kBeginToFinishMin,
3640 kBeginToFinishMax, kBeginToFinishBucketCount);
3641
3642 static bool use_cache_histogram2(FieldTrialList::Find("NewEviction") &&
3643 !FieldTrialList::Find("NewEviction")->group_name().empty());
3644 if (use_cache_histogram2)
3645 UMA_HISTOGRAM_CUSTOM_TIMES(
3646 FieldTrial::MakeName("Renderer4.StartToFinish", "NewEviction").data(),
3647 finish - start, kBeginToFinishMin,
3648 kBeginToFinishMax, kBeginToFinishBucketCount);
3649
[email protected]ab0729e2009-09-30 04:42:463650 static bool use_async_tcp(FieldTrialList::Find("AsyncSlowStart") &&
3651 !FieldTrialList::Find("AsyncSlowStart")->group_name().empty());
3652 if (use_async_tcp) {
3653 UMA_HISTOGRAM_CUSTOM_TIMES(
3654 FieldTrial::MakeName("Renderer4.StartToFinish",
3655 "AsyncSlowStart").data(),
3656 finish - start, kBeginToFinishMin,
3657 kBeginToFinishMax, kBeginToFinishBucketCount);
3658 }
3659
[email protected]7a9b51f2009-06-29 21:28:293660 UMA_HISTOGRAM_MEDIUM_TIMES("Renderer4.CommitToFinish", finish - commit);
3661
3662 if (!first_paint.is_null()) {
3663 UMA_HISTOGRAM_MEDIUM_TIMES(
3664 "Renderer4.BeginToFirstPaint", first_paint - begin);
3665 UMA_HISTOGRAM_MEDIUM_TIMES(
3666 "Renderer4.CommitToFirstPaint", first_paint - commit);
[email protected]c20210e62009-04-03 21:39:263667 }
[email protected]7a9b51f2009-06-29 21:28:293668
3669 if (!first_paint_after_load.is_null()) {
3670 UMA_HISTOGRAM_MEDIUM_TIMES(
3671 "Renderer4.BeginToFirstPaintAfterLoad", first_paint_after_load - begin);
3672 UMA_HISTOGRAM_MEDIUM_TIMES(
3673 "Renderer4.CommitToFirstPaintAfterLoad",
3674 first_paint_after_load - commit);
3675 UMA_HISTOGRAM_MEDIUM_TIMES(
3676 "Renderer4.FinishToFirstPaintAfterLoad",
3677 first_paint_after_load - finish);
3678 }
3679
3680 navigation_state->set_load_histograms_recorded(true);
[email protected]c20210e62009-04-03 21:39:263681}
[email protected]e846d0d2009-05-20 00:53:063682
[email protected]f8999642009-10-27 21:39:423683void RenderView::LogNavigationState(const NavigationState* state,
3684 const WebDataSource* ds) const {
3685 // Because this function gets called on every page load,
3686 // take extra care to optimize it away if logging is turned off.
3687 if (logging::LOG_INFO < logging::GetMinLogLevel())
3688 return;
3689
3690 DCHECK(state);
3691 DCHECK(ds);
3692 GURL url(ds->request().url());
3693 Time start = state->start_load_time();
3694 Time finish = state->finish_load_time();
3695 // TODO(mbelshe): should we log more stats?
3696 LOG(INFO) << "PLT: "
3697 << (finish - start).InMilliseconds()
3698 << "ms "
3699 << url.spec();
3700}
3701
[email protected]cc0445f2009-10-13 16:09:083702void RenderView::focusAccessibilityObject(
3703 const WebAccessibilityObject& acc_obj) {
[email protected]e846d0d2009-05-20 00:53:063704#if defined(OS_WIN)
[email protected]c7287a92009-11-04 20:06:153705 // TODO(dglazkov): Current logic implies that focus change can only be made
3706 // after at least one call to RenderView::OnGetAccessibilityInfo, which is
3707 // where accessibility is initialized. We should determine whether that's
3708 // right.
3709 if (!accessibility_.get())
3710 return;
[email protected]e846d0d2009-05-20 00:53:063711
3712 // Retrieve the accessibility object id of the AccessibilityObject.
[email protected]c7287a92009-11-04 20:06:153713 int acc_obj_id = accessibility_->addOrGetId(acc_obj);
[email protected]e846d0d2009-05-20 00:53:063714
3715 // If id is valid, alert the browser side that an accessibility focus change
3716 // occurred.
3717 if (acc_obj_id >= 0)
3718 Send(new ViewHostMsg_AccessibilityFocusChange(routing_id_, acc_obj_id));
3719
3720#else // defined(OS_WIN)
3721 // TODO(port): accessibility not yet implemented
3722 NOTIMPLEMENTED();
3723#endif
3724}
[email protected]daa8c58e2009-06-15 17:21:103725
3726void RenderView::SendPasswordForms(WebFrame* frame) {
[email protected]979c28b2009-11-07 01:30:483727 WebVector<WebFormElement> forms;
[email protected]dd7daa82009-08-10 05:46:453728 frame->forms(forms);
[email protected]daa8c58e2009-06-15 17:21:103729
3730 std::vector<PasswordForm> password_forms;
3731 for (size_t i = 0; i < forms.size(); ++i) {
[email protected]979c28b2009-11-07 01:30:483732 const WebFormElement& form = forms[i];
[email protected]daa8c58e2009-06-15 17:21:103733
3734 // Respect autocomplete=off.
[email protected]979c28b2009-11-07 01:30:483735 if (form.autoComplete()) {
[email protected]daa8c58e2009-06-15 17:21:103736 scoped_ptr<PasswordForm> password_form(
3737 PasswordFormDomManager::CreatePasswordForm(form));
3738 if (password_form.get())
3739 password_forms.push_back(*password_form);
3740 }
3741 }
3742
3743 if (!password_forms.empty())
3744 Send(new ViewHostMsg_PasswordFormsSeen(routing_id_, password_forms));
3745}
[email protected]0fda7272009-06-26 15:49:333746
3747void RenderView::Print(WebFrame* frame, bool script_initiated) {
3748 DCHECK(frame);
3749 if (print_helper_.get() == NULL) {
3750 print_helper_.reset(new PrintWebViewHelper(this));
3751 }
3752 print_helper_->Print(frame, script_initiated);
3753}
[email protected]446705872009-09-10 07:22:483754
3755void RenderView::OnSetEditCommandsForNextKeyEvent(
3756 const EditCommands& edit_commands) {
3757 edit_commands_ = edit_commands;
3758}
3759
[email protected]912256b32009-09-18 09:47:353760void RenderView::OnExecuteCode(int request_id, const std::string& extension_id,
3761 bool is_js_code,
3762 const std::string& code_string) {
[email protected]26aa0482009-09-30 16:55:273763 WebFrame* main_frame = webview() ? webview()->mainFrame() : NULL;
[email protected]912256b32009-09-18 09:47:353764 if (!main_frame) {
3765 Send(new ViewMsg_ExecuteCodeFinished(routing_id_, request_id, false));
3766 return;
3767 }
3768
[email protected]fa7b6b542009-11-03 05:02:303769 WebDataSource* ds = main_frame->dataSource();
3770 NavigationState* navigation_state = NavigationState::FromDataSource(ds);
3771 if (!navigation_state->user_script_idle_scheduler()->has_run()) {
3772 scoped_refptr<CodeExecutionInfo> info = new CodeExecutionInfo(
3773 request_id, extension_id, is_js_code, code_string);
3774 pending_code_execution_queue_.push(info);
3775 return;
3776 }
3777
3778 ExecuteCodeImpl(main_frame, request_id, extension_id, is_js_code,
3779 code_string);
3780}
3781
3782void RenderView::ExecuteCodeImpl(WebFrame* frame,
3783 int request_id,
3784 const std::string& extension_id,
3785 bool is_js_code,
3786 const std::string& code_string) {
[email protected]912256b32009-09-18 09:47:353787 if (is_js_code) {
3788 std::vector<WebScriptSource> sources;
3789 sources.push_back(
3790 WebScriptSource(WebString::fromUTF8(code_string)));
3791 UserScriptSlave::InsertInitExtensionCode(&sources, extension_id);
[email protected]fa7b6b542009-11-03 05:02:303792 frame->executeScriptInIsolatedWorld(
[email protected]146486ff2009-10-08 01:52:563793 UserScriptSlave::GetIsolatedWorldId(extension_id),
3794 &sources.front(), sources.size(), EXTENSION_GROUP_CONTENT_SCRIPTS);
[email protected]912256b32009-09-18 09:47:353795 } else {
[email protected]fa7b6b542009-11-03 05:02:303796 frame->insertStyleText(WebString::fromUTF8(code_string), WebString());
[email protected]912256b32009-09-18 09:47:353797 }
3798
3799 Send(new ViewMsg_ExecuteCodeFinished(routing_id_, request_id, true));
3800}
3801
[email protected]60c42a8c72009-10-09 04:08:593802void RenderView::Close() {
3803 // We need to grab a pointer to the doomed WebView before we destroy it.
3804 WebView* doomed = webview();
3805 RenderWidget::Close();
3806 Singleton<ViewMap>::get()->erase(doomed);
3807}
3808
[email protected]446705872009-09-10 07:22:483809void RenderView::DidHandleKeyEvent() {
3810 edit_commands_.clear();
3811}
3812
[email protected]83dde542009-09-11 20:59:553813void RenderView::EnsureDocumentTag() {
3814 // TODO(darin): There's actually no reason for this to be here. We should
3815 // have the browser side manage the document tag.
3816#if defined(OS_MACOSX)
3817 if (!has_document_tag_) {
3818 // Make the call to get the tag.
3819 Send(new ViewHostMsg_GetDocumentTag(routing_id_, &document_tag_));
3820 has_document_tag_ = true;
3821 }
3822#endif
3823}
[email protected]12636df2009-09-28 22:32:213824
3825bool RenderView::SendAndRunNestedMessageLoop(IPC::SyncMessage* message) {
[email protected]8beff0762009-09-29 02:18:303826 PluginChannelHost::Broadcast(
3827 new PluginMsg_SignalModalDialogEvent(host_window_));
[email protected]12636df2009-09-28 22:32:213828
3829 message->EnableMessagePumping(); // Runs a nested message loop.
3830 bool rv = Send(message);
3831
[email protected]8beff0762009-09-29 02:18:303832 PluginChannelHost::Broadcast(
3833 new PluginMsg_ResetModalDialogEvent(host_window_));
[email protected]12636df2009-09-28 22:32:213834
3835 return rv;
3836}