blob: d5b20f0164d11f9597c14fe9bf02b3f17a55a840 [file] [log] [blame]
[email protected]810a52ef2010-01-08 01:22:151// Copyright (c) 2010 The Chromium Authors. All rights reserved.
license.botbf09a502008-08-24 00:55:552// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
initial.commit09911bf2008-07-26 23:55:294
5#include "chrome/renderer/render_view.h"
6
7#include <algorithm>
8#include <string>
9#include <vector>
10
[email protected]91e81ae2009-05-08 22:14:3811#include "app/gfx/color_utils.h"
[email protected]37126212009-05-06 02:23:3112#include "app/gfx/favicon_size.h"
[email protected]010ea08a2009-10-11 20:21:3213#include "app/gfx/native_widget_types.h"
[email protected]a92b8642009-05-05 23:38:5614#include "app/l10n_util.h"
[email protected]37126212009-05-06 02:23:3115#include "app/message_box_flags.h"
[email protected]9929da92009-05-05 02:05:1116#include "app/resource_bundle.h"
initial.commit09911bf2008-07-26 23:55:2917#include "base/command_line.h"
[email protected]bb063b72009-03-27 23:18:5018#include "base/compiler_specific.h"
[email protected]4646f292009-05-20 03:49:0519#include "base/field_trial.h"
[email protected]30507922010-01-15 16:48:2320#include "base/histogram.h"
[email protected]8380c092009-06-25 17:45:5121#include "base/process_util.h"
[email protected]7b291f92009-08-14 05:43:5322#include "base/singleton.h"
initial.commit09911bf2008-07-26 23:55:2923#include "base/string_piece.h"
24#include "base/string_util.h"
[email protected]30507922010-01-15 16:48:2325#include "base/time.h"
[email protected]6c8afae52009-01-22 02:24:5726#include "build/build_config.h"
[email protected]81e63782009-02-27 19:35:0927#include "chrome/common/bindings_policy.h"
[email protected]ef916272009-07-08 21:40:5528#include "chrome/common/child_process_logging.h"
initial.commit09911bf2008-07-26 23:55:2929#include "chrome/common/chrome_switches.h"
[email protected]f0af6a72009-05-30 05:25:1730#include "chrome/common/chrome_constants.h"
[email protected]1f4fc8e8c2010-01-02 00:46:4131#include "chrome/common/histogram_synchronizer.h"
[email protected]d146b832009-12-23 02:45:4832#include "chrome/common/extensions/extension_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]bd92c3a2010-01-13 05:02:3455#include "chrome/renderer/renderer_webstoragenamespace_impl.h"
[email protected]85c55dc2009-11-06 03:05:4656#include "chrome/renderer/spellchecker/spellcheck.h"
[email protected]0938d3c2009-01-09 20:37:3557#include "chrome/renderer/user_script_slave.h"
initial.commit09911bf2008-07-26 23:55:2958#include "chrome/renderer/visitedlink_slave.h"
[email protected]d439ba072009-10-17 22:32:2959#include "chrome/renderer/webplugin_delegate_pepper.h"
[email protected]ba4b17f2009-02-11 21:32:2960#include "chrome/renderer/webplugin_delegate_proxy.h"
[email protected]9c00f002009-11-05 22:37:4261#include "chrome/renderer/websharedworker_proxy.h"
[email protected]eb47a132009-03-04 00:39:5662#include "chrome/renderer/webworker_proxy.h"
[email protected]34ac8f32009-02-22 23:03:2763#include "grit/generated_resources.h"
64#include "grit/renderer_resources.h"
[email protected]f11ca0732009-04-11 00:09:3465#include "net/base/data_url.h"
initial.commit09911bf2008-07-26 23:55:2966#include "net/base/escape.h"
67#include "net/base/net_errors.h"
[email protected]c399a8a2008-11-22 19:38:0068#include "skia/ext/bitmap_platform_device.h"
[email protected]83c9e6552008-12-03 16:22:1069#include "skia/ext/image_operations.h"
[email protected]651272792010-02-04 23:16:3070#include "third_party/cld/encodings/compact_lang_det/win/cld_unicodetext.h"
[email protected]418ed5ab2009-11-12 01:14:4971#include "third_party/WebKit/WebKit/chromium/public/WebAccessibilityCache.h"
72#include "third_party/WebKit/WebKit/chromium/public/WebAccessibilityObject.h"
[email protected]d9ec5c0f2009-12-23 11:55:0773#include "third_party/WebKit/WebKit/chromium/public/WebCString.h"
[email protected]418ed5ab2009-11-12 01:14:4974#include "third_party/WebKit/WebKit/chromium/public/WebDataSource.h"
75#include "third_party/WebKit/WebKit/chromium/public/WebDevToolsAgent.h"
[email protected]0bedb8a2010-01-14 19:36:3276#include "third_party/WebKit/WebKit/chromium/public/WebDocument.h"
[email protected]418ed5ab2009-11-12 01:14:4977#include "third_party/WebKit/WebKit/chromium/public/WebDragData.h"
[email protected]01178b52010-01-15 06:59:3578#include "third_party/WebKit/WebKit/chromium/public/WebFileChooserParams.h"
[email protected]418ed5ab2009-11-12 01:14:4979#include "third_party/WebKit/WebKit/chromium/public/WebFormElement.h"
80#include "third_party/WebKit/WebKit/chromium/public/WebFrame.h"
81#include "third_party/WebKit/WebKit/chromium/public/WebHistoryItem.h"
82#include "third_party/WebKit/WebKit/chromium/public/WebNode.h"
[email protected]0bedb8a2010-01-14 19:36:3283#include "third_party/WebKit/WebKit/chromium/public/WebNodeList.h"
[email protected]d9ec5c0f2009-12-23 11:55:0784#include "third_party/WebKit/WebKit/chromium/public/WebPageSerializer.h"
[email protected]418ed5ab2009-11-12 01:14:4985#include "third_party/WebKit/WebKit/chromium/public/WebPoint.h"
86#include "third_party/WebKit/WebKit/chromium/public/WebRange.h"
87#include "third_party/WebKit/WebKit/chromium/public/WebRect.h"
88#include "third_party/WebKit/WebKit/chromium/public/WebScriptSource.h"
89#include "third_party/WebKit/WebKit/chromium/public/WebSearchableFormData.h"
90#include "third_party/WebKit/WebKit/chromium/public/WebSecurityOrigin.h"
91#include "third_party/WebKit/WebKit/chromium/public/WebSize.h"
[email protected]bd92c3a2010-01-13 05:02:3492#include "third_party/WebKit/WebKit/chromium/public/WebStorageNamespace.h"
[email protected]418ed5ab2009-11-12 01:14:4993#include "third_party/WebKit/WebKit/chromium/public/WebString.h"
94#include "third_party/WebKit/WebKit/chromium/public/WebURL.h"
95#include "third_party/WebKit/WebKit/chromium/public/WebURLError.h"
96#include "third_party/WebKit/WebKit/chromium/public/WebURLRequest.h"
97#include "third_party/WebKit/WebKit/chromium/public/WebURLResponse.h"
98#include "third_party/WebKit/WebKit/chromium/public/WebVector.h"
[email protected]80f584d92010-01-21 03:59:0499#include "webkit/appcache/web_application_cache_host_impl.h"
[email protected]ba4b17f2009-02-11 21:32:29100#include "webkit/default_plugin/default_plugin_shared.h"
[email protected]ca948a22009-06-25 19:36:17101#include "webkit/glue/glue_serialize.h"
initial.commit09911bf2008-07-26 23:55:29102#include "webkit/glue/dom_operations.h"
[email protected]f11ca0732009-04-11 00:09:34103#include "webkit/glue/image_decoder.h"
[email protected]8e296bbd2009-07-22 21:37:17104#include "webkit/glue/media/buffered_data_source.h"
[email protected]8380c092009-06-25 17:45:51105#include "webkit/glue/media/simple_data_source.h"
initial.commit09911bf2008-07-26 23:55:29106#include "webkit/glue/password_form.h"
[email protected]ba4b17f2009-02-11 21:32:29107#include "webkit/glue/plugins/plugin_list.h"
[email protected]8a3b7962009-09-04 05:53:23108#include "webkit/glue/plugins/webplugin_delegate_impl.h"
initial.commit09911bf2008-07-26 23:55:29109#include "webkit/glue/webdropdata.h"
initial.commit09911bf2008-07-26 23:55:29110#include "webkit/glue/webkit_glue.h"
[email protected]add51772009-06-11 18:25:17111#include "webkit/glue/webmediaplayer_impl.h"
[email protected]f103ab72009-09-02 17:10:59112#include "webkit/glue/webplugin_impl.h"
initial.commit09911bf2008-07-26 23:55:29113
[email protected]6c8afae52009-01-22 02:24:57114#if defined(OS_WIN)
115// TODO(port): these files are currently Windows only because they concern:
[email protected]6c8afae52009-01-22 02:24:57116// * theming
[email protected]86281ad2009-10-07 20:07:17117#include "app/gfx/native_theme_win.h"
[email protected]39cd64ed2010-02-05 02:18:46118#elif defined(OS_LINUX)
119#include "third_party/WebKit/WebKit/chromium/public/linux/WebRenderTheme.h"
[email protected]6c8afae52009-01-22 02:24:57120#endif
121
[email protected]80f584d92010-01-21 03:59:04122using appcache::WebApplicationCacheHostImpl;
[email protected]c20210e62009-04-03 21:39:26123using base::Time;
[email protected]e1acf6f2008-10-27 20:43:33124using base::TimeDelta;
[email protected]15d79e12009-08-02 19:23:45125using webkit_glue::AltErrorPageResourceFetcher;
[email protected]51bd36612009-10-20 22:49:47126using webkit_glue::FormFieldValues;
[email protected]b0950a72009-09-29 23:16:17127using webkit_glue::ImageResourceFetcher;
[email protected]ed3fb032009-06-16 19:50:56128using webkit_glue::PasswordForm;
[email protected]daa8c58e2009-06-15 17:21:10129using webkit_glue::PasswordFormDomManager;
[email protected]c7287a92009-11-04 20:06:15130using WebKit::WebAccessibilityCache;
[email protected]cc0445f2009-10-13 16:09:08131using WebKit::WebAccessibilityObject;
[email protected]1c83eb42009-09-11 21:08:41132using WebKit::WebColor;
133using WebKit::WebColorName;
[email protected]0dea3ea2009-03-31 23:30:59134using WebKit::WebConsoleMessage;
[email protected]79e37442009-10-09 18:17:44135using WebKit::WebContextMenuData;
[email protected]d9ec5c0f2009-12-23 11:55:07136using WebKit::WebCString;
[email protected]e6f546c32009-07-01 17:12:55137using WebKit::WebData;
[email protected]726985e22009-06-18 21:09:28138using WebKit::WebDataSource;
[email protected]2661b332009-11-03 18:42:29139using WebKit::WebDevToolsAgent;
[email protected]e80c73b2009-04-07 23:24:58140using WebKit::WebDragData;
[email protected]1d9f4132009-09-08 17:29:25141using WebKit::WebDragOperation;
142using WebKit::WebDragOperationsMask;
[email protected]79dbc662009-09-04 05:42:51143using WebKit::WebEditingAction;
[email protected]6069da8c2009-10-20 20:33:49144using WebKit::WebFindOptions;
[email protected]979c28b2009-11-07 01:30:48145using WebKit::WebFormElement;
[email protected]dd7daa82009-08-10 05:46:45146using WebKit::WebFrame;
[email protected]ca948a22009-06-25 19:36:17147using WebKit::WebHistoryItem;
[email protected]3d9689372009-09-10 04:29:17148using WebKit::WebMediaPlayer;
[email protected]952cb702009-10-07 05:50:28149using WebKit::WebMediaPlayerAction;
[email protected]3d9689372009-09-10 04:29:17150using WebKit::WebMediaPlayerClient;
[email protected]4873c7d2009-07-16 06:36:28151using WebKit::WebNavigationPolicy;
[email protected]726985e22009-06-18 21:09:28152using WebKit::WebNavigationType;
[email protected]79dbc662009-09-04 05:42:51153using WebKit::WebNode;
[email protected]d9ec5c0f2009-12-23 11:55:07154using WebKit::WebPageSerializer;
155using WebKit::WebPageSerializerClient;
[email protected]3d9689372009-09-10 04:29:17156using WebKit::WebPlugin;
157using WebKit::WebPluginParams;
[email protected]48c9cf2d2009-09-16 16:47:52158using WebKit::WebPoint;
[email protected]88efb7ec2009-07-14 16:32:59159using WebKit::WebPopupMenuInfo;
[email protected]79dbc662009-09-04 05:42:51160using WebKit::WebRange;
[email protected]b3f2b912009-04-09 16:18:52161using WebKit::WebRect;
[email protected]4f999132009-03-31 18:08:40162using WebKit::WebScriptSource;
[email protected]ce0e250d2009-10-23 21:00:35163using WebKit::WebSearchableFormData;
[email protected]e3d60e5d2009-09-25 21:08:29164using WebKit::WebSecurityOrigin;
[email protected]2fab253a2009-08-17 23:00:59165using WebKit::WebSettings;
[email protected]9c00f002009-11-05 22:37:42166using WebKit::WebSharedWorker;
[email protected]8649fb32009-06-26 17:51:02167using WebKit::WebSize;
[email protected]bd92c3a2010-01-13 05:02:34168using WebKit::WebStorageNamespace;
[email protected]726985e22009-06-18 21:09:28169using WebKit::WebString;
[email protected]79dbc662009-09-04 05:42:51170using WebKit::WebTextAffinity;
[email protected]de570ef2009-07-29 18:27:52171using WebKit::WebTextDirection;
[email protected]726985e22009-06-18 21:09:28172using WebKit::WebURL;
173using WebKit::WebURLError;
174using WebKit::WebURLRequest;
175using WebKit::WebURLResponse;
[email protected]4873c7d2009-07-16 06:36:28176using WebKit::WebVector;
[email protected]50ae00ef2009-10-19 05:11:03177using WebKit::WebView;
[email protected]4873c7d2009-07-16 06:36:28178using WebKit::WebWidget;
[email protected]27ba8532009-04-24 20:22:43179using WebKit::WebWorker;
180using WebKit::WebWorkerClient;
[email protected]e1acf6f2008-10-27 20:43:33181
initial.commit09911bf2008-07-26 23:55:29182//-----------------------------------------------------------------------------
183
184// define to write the time necessary for thumbnail/DOM text retrieval,
185// respectively, into the system debug log
initial.commit09911bf2008-07-26 23:55:29186// #define TIME_TEXT_RETRIEVAL
187
188// maximum number of characters in the document to index, any text beyond this
189// point will be clipped
[email protected]6c8afae52009-01-22 02:24:57190static const size_t kMaxIndexChars = 65535;
initial.commit09911bf2008-07-26 23:55:29191
192// Size of the thumbnails that we'll generate
[email protected]8b4f4892009-09-04 21:52:37193static const int kThumbnailWidth = 212;
194static const int kThumbnailHeight = 132;
initial.commit09911bf2008-07-26 23:55:29195
196// Delay in milliseconds that we'll wait before capturing the page contents
197// and thumbnail.
198static const int kDelayForCaptureMs = 500;
199
200// Typically, we capture the page data once the page is loaded.
201// Sometimes, the page never finishes to load, preventing the page capture
202// To workaround this problem, we always perform a capture after the following
203// delay.
204static const int kDelayForForcedCaptureMs = 6000;
205
[email protected]882daa92009-11-05 16:31:31206// Time, in seconds, we delay before sending content state changes (such as form
207// state and scroll position) to the browser. We delay sending changes to avoid
208// spamming the browser.
209// To avoid having tab/session restore require sending a message to get the
210// current content state during tab closing we use a shorter timeout for the
211// foreground renderer. This means there is a small window of time from which
212// content state is modified and not sent to session restore, but this is
213// better than having to wake up all renderers during shutdown.
214static const int kDelaySecondsForContentStateSyncHidden = 5;
215static const int kDelaySecondsForContentStateSync = 1;
initial.commit09911bf2008-07-26 23:55:29216
[email protected]0aa55312008-10-17 21:53:08217// The maximum number of popups that can be spawned from one page.
218static const int kMaximumNumberOfUnacknowledgedPopups = 25;
219
initial.commit09911bf2008-07-26 23:55:29220static const char* const kUnreachableWebDataURL =
[email protected]60e448982009-05-06 04:21:16221 "chrome://chromewebdata/";
initial.commit09911bf2008-07-26 23:55:29222
[email protected]50b691c2008-10-31 19:08:35223static const char* const kBackForwardNavigationScheme = "history";
224
[email protected]8c4cdd42010-01-12 21:31:13225// The string returned in DetectLanguage if we failed to detect the language.
[email protected]8dc5a2052010-01-19 21:32:42226static const char* const kUnknownLanguageCode = "und";
[email protected]8c4cdd42010-01-12 21:31:13227
[email protected]726985e22009-06-18 21:09:28228static void GetRedirectChain(WebDataSource* ds, std::vector<GURL>* result) {
229 WebVector<WebURL> urls;
230 ds->redirectChain(urls);
231 result->reserve(urls.size());
232 for (size_t i = 0; i < urls.size(); ++i)
233 result->push_back(urls[i]);
234}
235
[email protected]61f5a7b2009-12-22 22:21:20236static bool UrlMatchesPermissions(
237 const GURL& url, const std::vector<URLPattern>& host_permissions) {
238 for (size_t i = 0; i < host_permissions.size(); ++i) {
239 if (host_permissions[i].MatchesUrl(url))
240 return true;
241 }
242
243 return false;
244}
245
[email protected]30507922010-01-15 16:48:23246static bool PaintViewIntoCanvas(WebView* view,
247 skia::PlatformCanvas& canvas) {
248 view->layout();
249 const WebSize& size = view->size();
250
251 if (!canvas.initialize(size.width, size.height, true))
252 return false;
253
254 view->paint(webkit_glue::ToWebCanvas(&canvas),
255 WebRect(0, 0, size.width, size.height));
256 // TODO: Add a way to snapshot the whole page, not just the currently
257 // visible part.
258
259 return true;
260}
261
262// Calculates how "boring" a thumbnail is. The boring score is the
263// 0,1 ranged percentage of pixels that are the most common
264// luma. Higher boring scores indicate that a higher percentage of a
265// bitmap are all the same brightness.
266static double CalculateBoringScore(SkBitmap* bitmap) {
267 int histogram[256] = {0};
268 color_utils::BuildLumaHistogram(bitmap, histogram);
269
270 int color_count = *std::max_element(histogram, histogram + 256);
271 int pixel_count = bitmap->width() * bitmap->height();
272 return static_cast<double>(color_count) / pixel_count;
273}
274
initial.commit09911bf2008-07-26 23:55:29275///////////////////////////////////////////////////////////////////////////////
276
[email protected]60c42a8c72009-10-09 04:08:59277int32 RenderView::next_page_id_ = 1;
278
[email protected]2fab253a2009-08-17 23:00:59279RenderView::RenderView(RenderThreadBase* render_thread,
[email protected]4e6419c2010-01-15 04:50:34280 const WebPreferences& webkit_preferences,
281 int64 session_storage_namespace_id)
[email protected]81a34412009-01-05 19:17:24282 : RenderWidget(render_thread, true),
[email protected]81e63782009-02-27 19:35:09283 enabled_bindings_(0),
[email protected]e75cb49e2009-01-05 23:13:21284 target_url_status_(TARGET_NONE),
[email protected]81a34412009-01-05 19:17:24285 is_loading_(false),
[email protected]e75cb49e2009-01-05 23:13:21286 navigation_gesture_(NavigationGestureUnknown),
[email protected]81a34412009-01-05 19:17:24287 page_id_(-1),
288 last_page_id_sent_to_browser_(-1),
289 last_indexed_page_id_(-1),
[email protected]81a34412009-01-05 19:17:24290 opened_by_user_gesture_(true),
[email protected]007a848b2009-10-26 15:55:46291 opener_suppressed_(false),
[email protected]bb063b72009-03-27 23:18:50292 ALLOW_THIS_IN_INITIALIZER_LIST(method_factory_(this)),
[email protected]e4ac5df2009-03-17 15:33:11293 devtools_agent_(NULL),
294 devtools_client_(NULL),
[email protected]a1128322009-10-06 18:38:46295 file_chooser_completion_(NULL),
[email protected]81a34412009-01-05 19:17:24296 history_back_list_count_(0),
297 history_forward_list_count_(0),
[email protected]81a34412009-01-05 19:17:24298 has_unload_listener_(false),
299 decrement_shared_popup_at_destruction_(false),
[email protected]acca2a1f2009-10-16 03:53:39300 autofill_query_id_(0),
[email protected]81a34412009-01-05 19:17:24301 popup_notification_visible_(false),
[email protected]8922e1f2009-10-03 05:01:26302 spelling_panel_visible_(false),
[email protected]882daa92009-11-05 16:31:31303 send_content_state_immediately_(false),
[email protected]ab32b16c2009-10-16 14:57:25304 send_preferred_size_changes_(false),
[email protected]b6849bda2009-10-14 23:59:26305 ALLOW_THIS_IN_INITIALIZER_LIST(
306 notification_provider_(new NotificationProvider(this))),
[email protected]7b291f92009-08-14 05:43:53307 view_type_(ViewType::INVALID),
308 browser_window_id_(-1),
[email protected]83dde542009-09-11 20:59:55309 last_top_level_navigation_page_id_(-1),
310#if defined(OS_MACOSX)
311 has_document_tag_(false),
312#endif
[email protected]98324892009-09-09 21:16:05313 document_tag_(0),
[email protected]0bedb8a2010-01-14 19:36:32314 webkit_preferences_(webkit_preferences),
[email protected]4e6419c2010-01-15 04:50:34315 session_storage_namespace_id_(session_storage_namespace_id),
[email protected]0bedb8a2010-01-14 19:36:32316 ALLOW_THIS_IN_INITIALIZER_LIST(text_translator_(this)) {
[email protected]0de80162010-02-03 04:52:35317 ClearBlockedContentSettings();
[email protected]7e0831b2010-02-01 08:45:15318 page_translator_.reset(new PageTranslator(&text_translator_, this));
initial.commit09911bf2008-07-26 23:55:29319}
320
321RenderView::~RenderView() {
[email protected]0aa55312008-10-17 21:53:08322 if (decrement_shared_popup_at_destruction_)
323 shared_popup_counter_->data--;
324
[email protected]b0950a72009-09-29 23:16:17325 // Dispose of un-disposed image fetchers.
326 for (ImageResourceFetcherSet::iterator i = image_fetchers_.begin();
327 i != image_fetchers_.end(); ++i) {
328 delete *i;
329 }
330
[email protected]a1128322009-10-06 18:38:46331 // If file chooser is still waiting for answer, dispatch empty answer.
332 if (file_chooser_completion_)
333 file_chooser_completion_->didChooseFile(WebVector<WebString>());
334
[email protected]83dde542009-09-11 20:59:55335#if defined(OS_MACOSX)
[email protected]98324892009-09-09 21:16:05336 // Tell the spellchecker that the document is closed.
[email protected]83dde542009-09-11 20:59:55337 if (has_document_tag_)
338 Send(new ViewHostMsg_DocumentWithTagClosed(routing_id_, document_tag_));
339#endif
[email protected]98324892009-09-09 21:16:05340
[email protected]5fb88962009-04-16 19:03:25341 render_thread_->RemoveFilter(audio_message_filter_);
[email protected]60c42a8c72009-10-09 04:08:59342
343#ifndef NDEBUG
344 // Make sure we are no longer referenced by the ViewMap.
345 ViewMap* views = Singleton<ViewMap>::get();
346 for (ViewMap::iterator it = views->begin(); it != views->end(); ++it)
347 DCHECK_NE(this, it->second) << "Failed to call Close?";
348#endif
349}
350
351/*static*/
352void RenderView::ForEach(RenderViewVisitor* visitor) {
353 ViewMap* views = Singleton<ViewMap>::get();
354 for (ViewMap::iterator it = views->begin(); it != views->end(); ++it) {
355 if (!visitor->Visit(it->second))
356 return;
357 }
358}
359
360/*static*/
361RenderView* RenderView::FromWebView(WebView* webview) {
362 ViewMap* views = Singleton<ViewMap>::get();
363 ViewMap::iterator it = views->find(webview);
364 return it == views->end() ? NULL : it->second;
initial.commit09911bf2008-07-26 23:55:29365}
366
367/*static*/
[email protected]0aa55312008-10-17 21:53:08368RenderView* RenderView::Create(
[email protected]81a34412009-01-05 19:17:24369 RenderThreadBase* render_thread,
[email protected]18bcc3c2009-01-27 21:39:15370 gfx::NativeViewId parent_hwnd,
[email protected]0aa55312008-10-17 21:53:08371 int32 opener_id,
[email protected]80d96fa2009-06-10 22:34:51372 const RendererPreferences& renderer_prefs,
[email protected]0aa55312008-10-17 21:53:08373 const WebPreferences& webkit_prefs,
374 SharedRenderViewCounter* counter,
[email protected]4e6419c2010-01-15 04:50:34375 int32 routing_id,
376 int64 session_storage_namespace_id) {
initial.commit09911bf2008-07-26 23:55:29377 DCHECK(routing_id != MSG_ROUTING_NONE);
[email protected]4e6419c2010-01-15 04:50:34378 scoped_refptr<RenderView> view = new RenderView(render_thread, webkit_prefs,
379 session_storage_namespace_id);
initial.commit09911bf2008-07-26 23:55:29380 view->Init(parent_hwnd,
initial.commit09911bf2008-07-26 23:55:29381 opener_id,
[email protected]80d96fa2009-06-10 22:34:51382 renderer_prefs,
[email protected]0aa55312008-10-17 21:53:08383 counter,
initial.commit09911bf2008-07-26 23:55:29384 routing_id); // adds reference
385 return view;
386}
387
388/*static*/
389void RenderView::SetNextPageID(int32 next_page_id) {
390 // This method should only be called during process startup, and the given
391 // page id had better not exceed our current next page id!
[email protected]4646f292009-05-20 03:49:05392 DCHECK_EQ(next_page_id_, 1);
initial.commit09911bf2008-07-26 23:55:29393 DCHECK(next_page_id >= next_page_id_);
394 next_page_id_ = next_page_id;
395}
396
[email protected]afe3a1672009-11-17 19:04:12397void RenderView::UserMetricsRecordAction(const std::string& action) {
[email protected]1dbafaf72009-09-23 19:43:56398 Send(new ViewHostMsg_UserMetricsRecordAction(routing_id_, action));
399}
400
[email protected]a3a8fb6d2009-10-22 20:12:51401void RenderView::PluginCrashed(const FilePath& plugin_path) {
402 Send(new ViewHostMsg_CrashedPlugin(routing_id_, plugin_path));
initial.commit09911bf2008-07-26 23:55:29403}
404
[email protected]d8fd6fa2010-02-01 15:54:26405#if defined(OS_MACOSX)
406void RenderView::RegisterPluginDelegate(WebPluginDelegateProxy* delegate) {
407 plugin_delegates_.insert(delegate);
408}
409
410void RenderView::UnregisterPluginDelegate(WebPluginDelegateProxy* delegate) {
411 plugin_delegates_.erase(delegate);
412}
413#endif
414
[email protected]18bcc3c2009-01-27 21:39:15415void RenderView::Init(gfx::NativeViewId parent_hwnd,
initial.commit09911bf2008-07-26 23:55:29416 int32 opener_id,
[email protected]80d96fa2009-06-10 22:34:51417 const RendererPreferences& renderer_prefs,
[email protected]0aa55312008-10-17 21:53:08418 SharedRenderViewCounter* counter,
initial.commit09911bf2008-07-26 23:55:29419 int32 routing_id) {
420 DCHECK(!webview());
421
422 if (opener_id != MSG_ROUTING_NONE)
423 opener_id_ = opener_id;
424
[email protected]0aa55312008-10-17 21:53:08425 if (counter) {
426 shared_popup_counter_ = counter;
427 shared_popup_counter_->data++;
428 decrement_shared_popup_at_destruction_ = true;
429 } else {
430 shared_popup_counter_ = new SharedRenderViewCounter(0);
431 decrement_shared_popup_at_destruction_ = false;
432 }
433
[email protected]58bfc6b2009-06-24 09:45:02434 devtools_agent_.reset(new DevToolsAgent(routing_id, this));
[email protected]9b9d7282009-04-08 14:13:04435
[email protected]50ae00ef2009-10-19 05:11:03436 webwidget_ = WebView::create(this);
[email protected]60c42a8c72009-10-09 04:08:59437 Singleton<ViewMap>::get()->insert(std::make_pair(webview(), this));
[email protected]2fab253a2009-08-17 23:00:59438 webkit_preferences_.Apply(webview());
[email protected]b4bb2502009-10-01 22:35:27439 webview()->initializeMainFrame(this);
[email protected]2661b332009-11-03 18:42:29440 webview()->setDevToolsAgent(
441 WebDevToolsAgent::create(webview(), devtools_agent_.get()));
initial.commit09911bf2008-07-26 23:55:29442
[email protected]d3ba77272009-09-03 00:06:09443 OnSetRendererPrefs(renderer_prefs);
444
initial.commit09911bf2008-07-26 23:55:29445 routing_id_ = routing_id;
[email protected]81a34412009-01-05 19:17:24446 render_thread_->AddRoute(routing_id_, this);
initial.commit09911bf2008-07-26 23:55:29447 // Take a reference on behalf of the RenderThread. This will be balanced
448 // when we receive ViewMsg_Close.
449 AddRef();
450
451 // If this is a popup, we must wait for the CreatingNew_ACK message before
452 // completing initialization. Otherwise, we can finish it now.
453 if (opener_id == MSG_ROUTING_NONE) {
454 did_show_ = true;
455 CompleteInit(parent_hwnd);
456 }
457
458 host_window_ = parent_hwnd;
initial.commit09911bf2008-07-26 23:55:29459
[email protected]58bfc6b2009-06-24 09:45:02460 const CommandLine& command_line = *CommandLine::ForCurrentProcess();
[email protected]81e63782009-02-27 19:35:09461 if (command_line.HasSwitch(switches::kDomAutomationController))
462 enabled_bindings_ |= BindingsPolicy::DOM_AUTOMATION;
initial.commit09911bf2008-07-26 23:55:29463
[email protected]5fb88962009-04-16 19:03:25464 audio_message_filter_ = new AudioMessageFilter(routing_id_);
465 render_thread_->AddFilter(audio_message_filter_);
initial.commit09911bf2008-07-26 23:55:29466}
467
468void RenderView::OnMessageReceived(const IPC::Message& message) {
[email protected]26aa0482009-09-30 16:55:27469 WebFrame* main_frame = webview() ? webview()->mainFrame() : NULL;
[email protected]a9f607e2009-10-23 19:59:27470 if (main_frame)
471 child_process_logging::SetActiveURL(main_frame->url());
[email protected]f8b6b6f2009-03-10 16:48:26472
[email protected]b2abac72009-02-26 12:39:28473 // If this is developer tools renderer intercept tools messages first.
[email protected]e4ac5df2009-03-17 15:33:11474 if (devtools_client_.get() && devtools_client_->OnMessageReceived(message))
[email protected]b2abac72009-02-26 12:39:28475 return;
[email protected]b4b967e2009-04-22 11:33:05476 if (devtools_agent_.get() && devtools_agent_->OnMessageReceived(message))
477 return;
[email protected]b6849bda2009-10-14 23:59:26478 if (notification_provider_->OnMessageReceived(message))
479 return;
[email protected]b2abac72009-02-26 12:39:28480
initial.commit09911bf2008-07-26 23:55:29481 IPC_BEGIN_MESSAGE_MAP(RenderView, message)
initial.commit09911bf2008-07-26 23:55:29482 IPC_MESSAGE_HANDLER(ViewMsg_CaptureThumbnail, SendThumbnail)
[email protected]30507922010-01-15 16:48:23483 IPC_MESSAGE_HANDLER(ViewMsg_CaptureSnapshot, SendSnapshot)
initial.commit09911bf2008-07-26 23:55:29484 IPC_MESSAGE_HANDLER(ViewMsg_PrintPages, OnPrintPages)
[email protected]82270452009-06-19 15:58:01485 IPC_MESSAGE_HANDLER(ViewMsg_PrintingDone, OnPrintingDone)
initial.commit09911bf2008-07-26 23:55:29486 IPC_MESSAGE_HANDLER(ViewMsg_Navigate, OnNavigate)
487 IPC_MESSAGE_HANDLER(ViewMsg_Stop, OnStop)
[email protected]1dda4022010-01-28 18:24:56488 IPC_MESSAGE_HANDLER(ViewMsg_ReloadFrame, OnReloadFrame)
initial.commit09911bf2008-07-26 23:55:29489 IPC_MESSAGE_HANDLER(ViewMsg_LoadAlternateHTMLText, OnLoadAlternateHTMLText)
490 IPC_MESSAGE_HANDLER(ViewMsg_StopFinding, OnStopFinding)
491 IPC_MESSAGE_HANDLER(ViewMsg_Undo, OnUndo)
492 IPC_MESSAGE_HANDLER(ViewMsg_Redo, OnRedo)
493 IPC_MESSAGE_HANDLER(ViewMsg_Cut, OnCut)
494 IPC_MESSAGE_HANDLER(ViewMsg_Copy, OnCopy)
[email protected]c0cc3092009-09-12 08:27:27495#if defined(OS_MACOSX)
[email protected]a954bf72009-09-12 07:30:35496 IPC_MESSAGE_HANDLER(ViewMsg_CopyToFindPboard, OnCopyToFindPboard)
[email protected]c0cc3092009-09-12 08:27:27497#endif
initial.commit09911bf2008-07-26 23:55:29498 IPC_MESSAGE_HANDLER(ViewMsg_Paste, OnPaste)
499 IPC_MESSAGE_HANDLER(ViewMsg_Replace, OnReplace)
[email protected]98324892009-09-09 21:16:05500 IPC_MESSAGE_HANDLER(ViewMsg_ToggleSpellPanel, OnToggleSpellPanel)
501 IPC_MESSAGE_HANDLER(ViewMsg_AdvanceToNextMisspelling,
502 OnAdvanceToNextMisspelling)
[email protected]bbbd545c2008-12-15 20:18:04503 IPC_MESSAGE_HANDLER(ViewMsg_ToggleSpellCheck, OnToggleSpellCheck)
initial.commit09911bf2008-07-26 23:55:29504 IPC_MESSAGE_HANDLER(ViewMsg_Delete, OnDelete)
505 IPC_MESSAGE_HANDLER(ViewMsg_SelectAll, OnSelectAll)
506 IPC_MESSAGE_HANDLER(ViewMsg_CopyImageAt, OnCopyImageAt)
[email protected]4b59ae602009-06-23 20:58:15507 IPC_MESSAGE_HANDLER(ViewMsg_ExecuteEditCommand, OnExecuteEditCommand)
initial.commit09911bf2008-07-26 23:55:29508 IPC_MESSAGE_HANDLER(ViewMsg_Find, OnFind)
[email protected]630e26b2008-10-14 22:55:17509 IPC_MESSAGE_HANDLER(ViewMsg_Zoom, OnZoom)
[email protected]f85f0702010-01-30 09:31:01510 IPC_MESSAGE_HANDLER(ViewMsg_SetContentSettingsForLoadingHost,
511 OnSetContentSettingsForLoadingHost)
[email protected]40bd6582009-12-04 23:49:51512 IPC_MESSAGE_HANDLER(ViewMsg_SetZoomLevelForLoadingHost,
513 OnSetZoomLevelForLoadingHost)
initial.commit09911bf2008-07-26 23:55:29514 IPC_MESSAGE_HANDLER(ViewMsg_SetPageEncoding, OnSetPageEncoding)
[email protected]a697f4c2009-09-14 22:30:18515 IPC_MESSAGE_HANDLER(ViewMsg_ResetPageEncodingToDefault,
516 OnResetPageEncodingToDefault)
[email protected]b2abac72009-02-26 12:39:28517 IPC_MESSAGE_HANDLER(ViewMsg_SetupDevToolsClient, OnSetupDevToolsClient)
[email protected]bf5c2ff392009-07-08 16:24:33518 IPC_MESSAGE_HANDLER(ViewMsg_DownloadFavIcon, OnDownloadFavIcon)
initial.commit09911bf2008-07-26 23:55:29519 IPC_MESSAGE_HANDLER(ViewMsg_ScriptEvalRequest, OnScriptEvalRequest)
[email protected]1810e132009-03-24 23:35:48520 IPC_MESSAGE_HANDLER(ViewMsg_CSSInsertRequest, OnCSSInsertRequest)
initial.commit09911bf2008-07-26 23:55:29521 IPC_MESSAGE_HANDLER(ViewMsg_AddMessageToConsole, OnAddMessageToConsole)
initial.commit09911bf2008-07-26 23:55:29522 IPC_MESSAGE_HANDLER(ViewMsg_ReservePageIDRange, OnReservePageIDRange)
initial.commit09911bf2008-07-26 23:55:29523 IPC_MESSAGE_HANDLER(ViewMsg_FormFill, OnFormFill)
524 IPC_MESSAGE_HANDLER(ViewMsg_FillPasswordForm, OnFillPasswordForm)
525 IPC_MESSAGE_HANDLER(ViewMsg_DragTargetDragEnter, OnDragTargetDragEnter)
526 IPC_MESSAGE_HANDLER(ViewMsg_DragTargetDragOver, OnDragTargetDragOver)
527 IPC_MESSAGE_HANDLER(ViewMsg_DragTargetDragLeave, OnDragTargetDragLeave)
528 IPC_MESSAGE_HANDLER(ViewMsg_DragTargetDrop, OnDragTargetDrop)
[email protected]18cb2572008-08-21 20:34:45529 IPC_MESSAGE_HANDLER(ViewMsg_AllowBindings, OnAllowBindings)
initial.commit09911bf2008-07-26 23:55:29530 IPC_MESSAGE_HANDLER(ViewMsg_SetDOMUIProperty, OnSetDOMUIProperty)
[email protected]266eb6f2008-09-30 23:56:50531 IPC_MESSAGE_HANDLER(ViewMsg_DragSourceEndedOrMoved,
532 OnDragSourceEndedOrMoved)
initial.commit09911bf2008-07-26 23:55:29533 IPC_MESSAGE_HANDLER(ViewMsg_DragSourceSystemDragEnded,
534 OnDragSourceSystemDragEnded)
535 IPC_MESSAGE_HANDLER(ViewMsg_SetInitialFocus, OnSetInitialFocus)
536 IPC_MESSAGE_HANDLER(ViewMsg_FindReplyACK, OnFindReplyAck)
537 IPC_MESSAGE_HANDLER(ViewMsg_UpdateTargetURL_ACK, OnUpdateTargetURLAck)
538 IPC_MESSAGE_HANDLER(ViewMsg_UpdateWebPreferences, OnUpdateWebPreferences)
539 IPC_MESSAGE_HANDLER(ViewMsg_SetAltErrorPageURL, OnSetAltErrorPageURL)
540 IPC_MESSAGE_HANDLER(ViewMsg_InstallMissingPlugin, OnInstallMissingPlugin)
541 IPC_MESSAGE_HANDLER(ViewMsg_RunFileChooserResponse, OnFileChooserResponse)
542 IPC_MESSAGE_HANDLER(ViewMsg_EnableViewSourceMode, OnEnableViewSourceMode)
543 IPC_MESSAGE_HANDLER(ViewMsg_UpdateBackForwardListCount,
544 OnUpdateBackForwardListCount)
545 IPC_MESSAGE_HANDLER(ViewMsg_GetAllSavableResourceLinksForCurrentPage,
546 OnGetAllSavableResourceLinksForCurrentPage)
[email protected]f09c7182009-03-10 12:54:04547 IPC_MESSAGE_HANDLER(
548 ViewMsg_GetSerializedHtmlDataForCurrentPageWithLocalLinks,
549 OnGetSerializedHtmlDataForCurrentPageWithLocalLinks)
initial.commit09911bf2008-07-26 23:55:29550 IPC_MESSAGE_HANDLER(ViewMsg_GetApplicationInfo, OnGetApplicationInfo)
[email protected]266eb6f2008-09-30 23:56:50551 IPC_MESSAGE_HANDLER(ViewMsg_GetAccessibilityInfo, OnGetAccessibilityInfo)
552 IPC_MESSAGE_HANDLER(ViewMsg_ClearAccessibilityInfo,
553 OnClearAccessibilityInfo)
initial.commit09911bf2008-07-26 23:55:29554 IPC_MESSAGE_HANDLER(ViewMsg_ShouldClose, OnMsgShouldClose)
555 IPC_MESSAGE_HANDLER(ViewMsg_ClosePage, OnClosePage)
556 IPC_MESSAGE_HANDLER(ViewMsg_ThemeChanged, OnThemeChanged)
[email protected]18cb2572008-08-21 20:34:45557 IPC_MESSAGE_HANDLER(ViewMsg_HandleMessageFromExternalHost,
558 OnMessageFromExternalHost)
[email protected]0aa55312008-10-17 21:53:08559 IPC_MESSAGE_HANDLER(ViewMsg_DisassociateFromPopupCount,
560 OnDisassociateFromPopupCount)
[email protected]842936a2009-10-14 06:00:36561 IPC_MESSAGE_HANDLER(ViewMsg_QueryFormFieldAutofill_ACK,
562 OnQueryFormFieldAutofillAck)
[email protected]2c4410d2009-05-06 23:46:22563 IPC_MESSAGE_HANDLER(ViewMsg_PopupNotificationVisibilityChanged,
564 OnPopupNotificationVisibilityChanged)
[email protected]30f75e62009-02-25 22:01:00565 IPC_MESSAGE_HANDLER(ViewMsg_MoveOrResizeStarted, OnMoveOrResizeStarted)
[email protected]309d7a282009-03-24 09:18:27566 IPC_MESSAGE_HANDLER(ViewMsg_ExtensionResponse, OnExtensionResponse)
[email protected]7120f132009-07-20 21:05:37567 IPC_MESSAGE_HANDLER(ViewMsg_ExtensionMessageInvoke,
568 OnExtensionMessageInvoke)
[email protected]05d478752009-04-08 23:38:16569 IPC_MESSAGE_HANDLER(ViewMsg_ClearFocusedNode, OnClearFocusedNode)
[email protected]699ab0d2009-04-23 23:19:14570 IPC_MESSAGE_HANDLER(ViewMsg_SetBackground, OnSetBackground)
[email protected]ab32b16c2009-10-16 14:57:25571 IPC_MESSAGE_HANDLER(ViewMsg_EnablePreferredSizeChangedMode,
572 OnEnablePreferredSizeChangedMode)
[email protected]80d96fa2009-06-10 22:34:51573 IPC_MESSAGE_HANDLER(ViewMsg_SetRendererPrefs, OnSetRendererPrefs)
[email protected]7b291f92009-08-14 05:43:53574 IPC_MESSAGE_HANDLER(ViewMsg_UpdateBrowserWindowId,
575 OnUpdateBrowserWindowId)
576 IPC_MESSAGE_HANDLER(ViewMsg_NotifyRenderViewType,
577 OnNotifyRendererViewType)
[email protected]581b87eb2009-07-23 23:06:56578 IPC_MESSAGE_HANDLER(ViewMsg_MediaPlayerActionAt, OnMediaPlayerActionAt)
[email protected]8c66c5a2009-07-22 17:26:34579 IPC_MESSAGE_HANDLER(ViewMsg_SetActive, OnSetActive)
[email protected]6ce7abc52010-02-02 18:40:14580#if defined(OS_MACOSX)
581 IPC_MESSAGE_HANDLER(ViewMsg_SetWindowVisibility, OnSetWindowVisibility)
[email protected]1e6e3c992010-02-08 15:52:13582 IPC_MESSAGE_HANDLER(ViewMsg_WindowFrameChanged, OnWindowFrameChanged)
[email protected]6ce7abc52010-02-02 18:40:14583#endif
[email protected]446705872009-09-10 07:22:48584 IPC_MESSAGE_HANDLER(ViewMsg_SetEditCommandsForNextKeyEvent,
[email protected]a0c7153e2009-12-09 14:36:33585 OnSetEditCommandsForNextKeyEvent)
[email protected]912256b32009-09-18 09:47:35586 IPC_MESSAGE_HANDLER(ViewMsg_ExecuteCode,
587 OnExecuteCode)
[email protected]a0c7153e2009-12-09 14:36:33588 IPC_MESSAGE_HANDLER(ViewMsg_CustomContextMenuAction,
589 OnCustomContextMenuAction)
[email protected]d4a00a72010-01-29 01:44:42590 IPC_MESSAGE_HANDLER(ViewMsg_TranslatePage, OnTranslatePage)
[email protected]0bedb8a2010-01-14 19:36:32591 IPC_MESSAGE_HANDLER(ViewMsg_TranslateTextReponse, OnTranslateTextResponse)
[email protected]634a6f92008-12-01 21:39:31592
initial.commit09911bf2008-07-26 23:55:29593 // Have the super handle all other messages.
594 IPC_MESSAGE_UNHANDLED(RenderWidget::OnMessageReceived(message))
595 IPC_END_MESSAGE_MAP()
596}
597
initial.commit09911bf2008-07-26 23:55:29598void RenderView::SendThumbnail() {
[email protected]26aa0482009-09-30 16:55:27599 WebFrame* main_frame = webview()->mainFrame();
initial.commit09911bf2008-07-26 23:55:29600 if (!main_frame)
601 return;
602
603 // get the URL for this page
[email protected]dd7daa82009-08-10 05:46:45604 GURL url(main_frame->url());
initial.commit09911bf2008-07-26 23:55:29605 if (url.is_empty())
606 return;
607
608 if (size_.IsEmpty())
609 return; // Don't create an empty thumbnail!
610
611 ThumbnailScore score;
612 SkBitmap thumbnail;
[email protected]8649fb32009-06-26 17:51:02613 if (!CaptureThumbnail(webview(), kThumbnailWidth, kThumbnailHeight,
[email protected]b6e4bec2008-11-12 01:17:15614 &thumbnail, &score))
615 return;
616
initial.commit09911bf2008-07-26 23:55:29617 // send the thumbnail message to the browser process
[email protected]674741932009-02-04 23:44:46618 Send(new ViewHostMsg_Thumbnail(routing_id_, url, score, thumbnail));
initial.commit09911bf2008-07-26 23:55:29619}
620
[email protected]30507922010-01-15 16:48:23621void RenderView::SendSnapshot() {
622 SkBitmap snapshot;
623 bool error = false;
624
625 WebFrame* main_frame = webview()->mainFrame();
626 if (!main_frame)
627 error = true;
628
629 if (!error && !CaptureSnapshot(webview(), &snapshot))
630 error = true;
631
632 DCHECK(error == snapshot.empty()) <<
633 "Snapshot should be empty on error, non-empty otherwise.";
634
635 // Send the snapshot to the browser process.
636 Send(new ViewHostMsg_Snapshot(routing_id_, snapshot));
637}
638
[email protected]068637222009-01-29 16:58:07639void RenderView::OnPrintPages() {
initial.commit09911bf2008-07-26 23:55:29640 DCHECK(webview());
[email protected]aa82249f2009-07-16 17:23:58641 if (webview()) {
642 // If the user has selected text in the currently focused frame we print
643 // only that frame (this makes print selection work for multiple frames).
[email protected]26aa0482009-09-30 16:55:27644 if (webview()->focusedFrame()->hasSelection())
645 Print(webview()->focusedFrame(), false);
[email protected]aa82249f2009-07-16 17:23:58646 else
[email protected]26aa0482009-09-30 16:55:27647 Print(webview()->mainFrame(), false);
[email protected]aa82249f2009-07-16 17:23:58648 }
initial.commit09911bf2008-07-26 23:55:29649}
650
[email protected]82270452009-06-19 15:58:01651void RenderView::OnPrintingDone(int document_cookie, bool success) {
652 // Ignoring document cookie here since only one print job can be outstanding
653 // per renderer and document_cookie is 0 when printing is successful.
654 DCHECK(print_helper_.get());
655 if (print_helper_.get() != NULL) {
656 print_helper_->DidFinishPrinting(success);
657 }
658}
659
initial.commit09911bf2008-07-26 23:55:29660void RenderView::CapturePageInfo(int load_id, bool preliminary_capture) {
661 if (load_id != page_id_)
662 return; // this capture call is no longer relevant due to navigation
663 if (load_id == last_indexed_page_id_)
664 return; // we already indexed this page
665
666 if (!webview())
667 return;
668
[email protected]26aa0482009-09-30 16:55:27669 WebFrame* main_frame = webview()->mainFrame();
initial.commit09911bf2008-07-26 23:55:29670 if (!main_frame)
671 return;
672
673 // Don't index/capture pages that are in view source mode.
[email protected]dd7daa82009-08-10 05:46:45674 if (main_frame->isViewSourceModeEnabled())
initial.commit09911bf2008-07-26 23:55:29675 return;
676
677 // Don't index/capture pages that failed to load. This only checks the top
678 // level frame so the thumbnail may contain a frame that failed to load.
[email protected]dd7daa82009-08-10 05:46:45679 WebDataSource* ds = main_frame->dataSource();
[email protected]726985e22009-06-18 21:09:28680 if (ds && ds->hasUnreachableURL())
initial.commit09911bf2008-07-26 23:55:29681 return;
682
683 if (!preliminary_capture)
684 last_indexed_page_id_ = load_id;
685
[email protected]a8a81292010-01-21 00:32:45686 // Get the URL for this page.
[email protected]dd7daa82009-08-10 05:46:45687 GURL url(main_frame->url());
initial.commit09911bf2008-07-26 23:55:29688 if (url.is_empty())
689 return;
690
[email protected]a8a81292010-01-21 00:32:45691 // Retrieve the frame's full text.
initial.commit09911bf2008-07-26 23:55:29692 std::wstring contents;
693 CaptureText(main_frame, &contents);
694 if (contents.size()) {
[email protected]a8a81292010-01-21 00:32:45695 base::TimeTicks begin_time = base::TimeTicks::Now();
696 std::string language = DetermineTextLanguage(contents);
697 UMA_HISTOGRAM_MEDIUM_TIMES("Renderer4.LanguageDetection",
698 base::TimeTicks::Now() - begin_time);
[email protected]7893a982010-01-07 23:25:52699
[email protected]a8a81292010-01-21 00:32:45700 // Send the text to the browser for indexing (the browser might decide not
701 // to index, if the URL is HTTPS for instance) and language discovery.
702 Send(new ViewHostMsg_PageContents(routing_id_, url, load_id, contents,
703 language));
[email protected]5c4266922009-07-10 16:41:27704 }
705
initial.commit09911bf2008-07-26 23:55:29706 // thumbnail
707 SendThumbnail();
708}
709
710void RenderView::CaptureText(WebFrame* frame, std::wstring* contents) {
711 contents->clear();
712 if (!frame)
713 return;
714
715#ifdef TIME_TEXT_RETRIEVAL
716 double begin = time_util::GetHighResolutionTimeNow();
717#endif
718
719 // get the contents of the frame
[email protected]dd7daa82009-08-10 05:46:45720 *contents = UTF16ToWideHack(frame->contentAsText(kMaxIndexChars));
initial.commit09911bf2008-07-26 23:55:29721
722#ifdef TIME_TEXT_RETRIEVAL
723 double end = time_util::GetHighResolutionTimeNow();
724 char buf[128];
725 sprintf_s(buf, "%d chars retrieved for indexing in %gms\n",
726 contents.size(), (end - begin)*1000);
727 OutputDebugStringA(buf);
728#endif
729
730 // When the contents are clipped to the maximum, we don't want to have a
731 // partial word indexed at the end that might have been clipped. Therefore,
732 // terminate the string at the last space to ensure no words are clipped.
733 if (contents->size() == kMaxIndexChars) {
734 size_t last_space_index = contents->find_last_of(kWhitespaceWide);
735 if (last_space_index == std::wstring::npos)
736 return; // don't index if we got a huge block of text with no spaces
737 contents->resize(last_space_index);
738 }
739}
740
[email protected]8649fb32009-06-26 17:51:02741bool RenderView::CaptureThumbnail(WebView* view,
initial.commit09911bf2008-07-26 23:55:29742 int w,
743 int h,
744 SkBitmap* thumbnail,
745 ThumbnailScore* score) {
[email protected]30507922010-01-15 16:48:23746 base::TimeTicks beginning_time = base::TimeTicks::Now();
[email protected]b6e4bec2008-11-12 01:17:15747
[email protected]8649fb32009-06-26 17:51:02748 skia::PlatformCanvas canvas;
[email protected]30507922010-01-15 16:48:23749
750 // Paint |view| into |canvas|.
751 if (!PaintViewIntoCanvas(view, canvas))
[email protected]8649fb32009-06-26 17:51:02752 return false;
[email protected]8649fb32009-06-26 17:51:02753
754 skia::BitmapPlatformDevice& device =
755 static_cast<skia::BitmapPlatformDevice&>(canvas.getTopPlatformDevice());
756
757 const SkBitmap& src_bmp = device.accessBitmap(false);
initial.commit09911bf2008-07-26 23:55:29758
[email protected]cab34d6a2009-09-24 01:14:52759 SkRect dest_rect = { 0, 0, SkIntToScalar(w), SkIntToScalar(h) };
initial.commit09911bf2008-07-26 23:55:29760 float dest_aspect = dest_rect.width() / dest_rect.height();
761
762 // Get the src rect so that we can preserve the aspect ratio while filling
763 // the destination.
764 SkIRect src_rect;
765 if (src_bmp.width() < dest_rect.width() ||
766 src_bmp.height() < dest_rect.height()) {
767 // Source image is smaller: we clip the part of source image within the
768 // dest rect, and then stretch it to fill the dest rect. We don't respect
769 // the aspect ratio in this case.
770 src_rect.set(0, 0, static_cast<S16CPU>(dest_rect.width()),
771 static_cast<S16CPU>(dest_rect.height()));
772 score->good_clipping = false;
773 } else {
774 float src_aspect = static_cast<float>(src_bmp.width()) / src_bmp.height();
775 if (src_aspect > dest_aspect) {
776 // Wider than tall, clip horizontally: we center the smaller thumbnail in
777 // the wider screen.
778 S16CPU new_width = static_cast<S16CPU>(src_bmp.height() * dest_aspect);
779 S16CPU x_offset = (src_bmp.width() - new_width) / 2;
780 src_rect.set(x_offset, 0, new_width + x_offset, src_bmp.height());
781 score->good_clipping = false;
782 } else {
783 src_rect.set(0, 0, src_bmp.width(),
784 static_cast<S16CPU>(src_bmp.width() / dest_aspect));
785 score->good_clipping = true;
786 }
787 }
788
[email protected]26aa0482009-09-30 16:55:27789 score->at_top = (view->mainFrame()->scrollOffset().height == 0);
initial.commit09911bf2008-07-26 23:55:29790
791 SkBitmap subset;
[email protected]8649fb32009-06-26 17:51:02792 device.accessBitmap(false).extractSubset(&subset, src_rect);
initial.commit09911bf2008-07-26 23:55:29793
794 // Resample the subset that we want to get it the right size.
[email protected]465b34b72008-12-12 20:19:14795 *thumbnail = skia::ImageOperations::Resize(
796 subset, skia::ImageOperations::RESIZE_LANCZOS3, w, h);
initial.commit09911bf2008-07-26 23:55:29797
798 score->boring_score = CalculateBoringScore(thumbnail);
799
[email protected]30507922010-01-15 16:48:23800 HISTOGRAM_TIMES("Renderer4.Thumbnail",
801 base::TimeTicks::Now() - beginning_time);
[email protected]b6e4bec2008-11-12 01:17:15802 return true;
initial.commit09911bf2008-07-26 23:55:29803}
804
[email protected]30507922010-01-15 16:48:23805bool RenderView::CaptureSnapshot(WebView* view, SkBitmap* snapshot) {
806 base::TimeTicks beginning_time = base::TimeTicks::Now();
initial.commit09911bf2008-07-26 23:55:29807
[email protected]30507922010-01-15 16:48:23808 skia::PlatformCanvas canvas;
809 if (!PaintViewIntoCanvas(view, canvas))
810 return false;
811
812 skia::BitmapPlatformDevice& device =
813 static_cast<skia::BitmapPlatformDevice&>(canvas.getTopPlatformDevice());
814
815 const SkBitmap& bitmap = device.accessBitmap(false);
816 if (!bitmap.copyTo(snapshot, SkBitmap::kARGB_8888_Config))
817 return false;
818
819 HISTOGRAM_TIMES("Renderer4.Snapshot",
820 base::TimeTicks::Now() - beginning_time);
821 return true;
initial.commit09911bf2008-07-26 23:55:29822}
823
824void RenderView::OnNavigate(const ViewMsg_Navigate_Params& params) {
825 if (!webview())
826 return;
827
[email protected]8c785c62009-07-13 14:20:15828 if (devtools_agent_.get())
829 devtools_agent_->OnNavigate();
830
[email protected]422197532010-01-25 17:38:23831 if (notification_provider_.get())
832 notification_provider_->OnNavigate();
833
[email protected]a9f607e2009-10-23 19:59:27834 child_process_logging::SetActiveURL(params.url);
[email protected]f8b6b6f2009-03-10 16:48:26835
initial.commit09911bf2008-07-26 23:55:29836 AboutHandler::MaybeHandle(params.url);
837
[email protected]5e369672009-11-03 23:48:30838 bool is_reload = (params.navigation_type == ViewMsg_Navigate_Params::RELOAD);
initial.commit09911bf2008-07-26 23:55:29839
[email protected]26aa0482009-09-30 16:55:27840 WebFrame* main_frame = webview()->mainFrame();
[email protected]dd7daa82009-08-10 05:46:45841 if (is_reload && main_frame->currentHistoryItem().isNull()) {
initial.commit09911bf2008-07-26 23:55:29842 // We cannot reload if we do not have any history state. This happens, for
843 // example, when recovering from a crash. Our workaround here is a bit of
844 // a hack since it means that reload after a crashed tab does not cause an
845 // end-to-end cache validation.
846 is_reload = false;
847 }
848
[email protected]77f17a82009-05-21 04:42:54849 // A navigation resulting from loading a javascript URL should not be treated
850 // as a browser initiated event. Instead, we want it to look as if the page
851 // initiated any load resulting from JS execution.
852 if (!params.url.SchemeIs(chrome::kJavaScriptScheme)) {
[email protected]5e369672009-11-03 23:48:30853 NavigationState* state = NavigationState::CreateBrowserInitiated(
854 params.page_id, params.transition, params.request_time);
855 if (params.navigation_type == ViewMsg_Navigate_Params::RESTORE) {
856 // We're doing a load of a page that was restored from the last session.
857 // By default this prefers the cache over loading (LOAD_PREFERRING_CACHE)
858 // which can result in stale data for pages that are set to expire. We
859 // explicitly override that by setting the policy here so that as
860 // necessary we load from the network.
861 state->set_cache_policy_override(WebURLRequest::UseProtocolCachePolicy);
862 }
863 pending_navigation_state_.reset(state);
[email protected]77f17a82009-05-21 04:42:54864 }
initial.commit09911bf2008-07-26 23:55:29865
[email protected]a7ccc4d2010-01-27 08:14:48866 NavigationState* navigation_state = pending_navigation_state_.get();
867
[email protected]04d3c6e2009-05-22 17:00:13868 // If we are reloading, then WebKit will use the history state of the current
869 // page, so we should just ignore any given history state. Otherwise, if we
870 // have history state, then we need to navigate to it, which corresponds to a
871 // back/forward navigation event.
[email protected]e6f546c32009-07-01 17:12:55872 if (is_reload) {
[email protected]a7ccc4d2010-01-27 08:14:48873 if (navigation_state)
874 navigation_state->set_load_type(NavigationState::RELOAD);
[email protected]dd7daa82009-08-10 05:46:45875 main_frame->reload();
[email protected]e6f546c32009-07-01 17:12:55876 } else if (!params.state.empty()) {
[email protected]04d3c6e2009-05-22 17:00:13877 // We must know the page ID of the page we are navigating back to.
[email protected]f929f2f22009-06-12 16:56:58878 DCHECK_NE(params.page_id, -1);
[email protected]a7ccc4d2010-01-27 08:14:48879 if (navigation_state)
880 navigation_state->set_load_type(NavigationState::HISTORY_LOAD);
[email protected]dd7daa82009-08-10 05:46:45881 main_frame->loadHistoryItem(
[email protected]ca948a22009-06-25 19:36:17882 webkit_glue::HistoryItemFromString(params.state));
[email protected]04d3c6e2009-05-22 17:00:13883 } else {
884 // Navigate to the given URL.
[email protected]726985e22009-06-18 21:09:28885 WebURLRequest request(params.url);
initial.commit09911bf2008-07-26 23:55:29886
[email protected]e6f546c32009-07-01 17:12:55887 // A session history navigation should have been accompanied by state.
888 DCHECK_EQ(params.page_id, -1);
[email protected]04d3c6e2009-05-22 17:00:13889
[email protected]dd7daa82009-08-10 05:46:45890 if (main_frame->isViewSourceModeEnabled())
[email protected]e6f546c32009-07-01 17:12:55891 request.setCachePolicy(WebURLRequest::ReturnCacheDataElseLoad);
[email protected]04d3c6e2009-05-22 17:00:13892
[email protected]726985e22009-06-18 21:09:28893 if (params.referrer.is_valid()) {
894 request.setHTTPHeaderField(WebString::fromUTF8("Referer"),
895 WebString::fromUTF8(params.referrer.spec()));
896 }
[email protected]04d3c6e2009-05-22 17:00:13897
[email protected]a7ccc4d2010-01-27 08:14:48898 if (navigation_state)
899 navigation_state->set_load_type(NavigationState::NORMAL_LOAD);
[email protected]dd7daa82009-08-10 05:46:45900 main_frame->loadRequest(request);
[email protected]c0588052008-10-27 23:01:50901 }
902
[email protected]77f17a82009-05-21 04:42:54903 // In case LoadRequest failed before DidCreateDataSource was called.
904 pending_navigation_state_.reset();
initial.commit09911bf2008-07-26 23:55:29905}
906
907// Stop loading the current page
908void RenderView::OnStop() {
909 if (webview())
[email protected]b4bb2502009-10-01 22:35:27910 webview()->mainFrame()->stopLoading();
initial.commit09911bf2008-07-26 23:55:29911}
912
[email protected]1dda4022010-01-28 18:24:56913// Reload current focused frame
914void RenderView::OnReloadFrame() {
915 if (webview() && webview()->focusedFrame())
916 webview()->focusedFrame()->reload();
917}
918
[email protected]e6f546c32009-07-01 17:12:55919void RenderView::OnLoadAlternateHTMLText(const std::string& html,
initial.commit09911bf2008-07-26 23:55:29920 bool new_navigation,
921 const GURL& display_url,
922 const std::string& security_info) {
923 if (!webview())
924 return;
925
[email protected]e6f546c32009-07-01 17:12:55926 pending_navigation_state_.reset(NavigationState::CreateBrowserInitiated(
927 new_navigation ? -1 : page_id_, PageTransition::LINK, Time::Now()));
928 pending_navigation_state_->set_security_info(security_info);
initial.commit09911bf2008-07-26 23:55:29929
[email protected]26aa0482009-09-30 16:55:27930 webview()->mainFrame()->loadHTMLString(
931 html, GURL(kUnreachableWebDataURL), display_url, !new_navigation);
[email protected]e6f546c32009-07-01 17:12:55932
933 pending_navigation_state_.reset();
initial.commit09911bf2008-07-26 23:55:29934}
935
936void RenderView::OnCopyImageAt(int x, int y) {
[email protected]26aa0482009-09-30 16:55:27937 webview()->copyImageAt(WebPoint(x, y));
initial.commit09911bf2008-07-26 23:55:29938}
939
[email protected]68b1e922009-06-23 16:00:25940void RenderView::OnExecuteEditCommand(const std::string& name,
941 const std::string& value) {
[email protected]26aa0482009-09-30 16:55:27942 if (!webview() || !webview()->focusedFrame())
[email protected]68b1e922009-06-23 16:00:25943 return;
944
[email protected]26aa0482009-09-30 16:55:27945 webview()->focusedFrame()->executeCommand(
[email protected]dd7daa82009-08-10 05:46:45946 WebString::fromUTF8(name), WebString::fromUTF8(value));
[email protected]68b1e922009-06-23 16:00:25947}
948
[email protected]b2abac72009-02-26 12:39:28949void RenderView::OnSetupDevToolsClient() {
[email protected]e4ac5df2009-03-17 15:33:11950 DCHECK(!devtools_client_.get());
951 devtools_client_.reset(new DevToolsClient(this));
[email protected]b2abac72009-02-26 12:39:28952}
953
initial.commit09911bf2008-07-26 23:55:29954void RenderView::OnStopFinding(bool clear_selection) {
955 WebView* view = webview();
956 if (!view)
957 return;
958
959 if (clear_selection)
[email protected]26aa0482009-09-30 16:55:27960 view->focusedFrame()->executeCommand(WebString::fromUTF8("Unselect"));
initial.commit09911bf2008-07-26 23:55:29961
[email protected]26aa0482009-09-30 16:55:27962 WebFrame* frame = view->mainFrame();
initial.commit09911bf2008-07-26 23:55:29963 while (frame) {
[email protected]dd7daa82009-08-10 05:46:45964 frame->stopFinding(clear_selection);
[email protected]b4bb2502009-10-01 22:35:27965 frame = frame->traverseNext(false);
initial.commit09911bf2008-07-26 23:55:29966 }
967}
968
969void RenderView::OnFindReplyAck() {
970 // Check if there is any queued up request waiting to be sent.
971 if (queued_find_reply_message_.get()) {
972 // Send the search result over to the browser process.
973 Send(queued_find_reply_message_.get());
974 queued_find_reply_message_.release();
975 }
976}
977
978void RenderView::OnUpdateTargetURLAck() {
979 // Check if there is a targeturl waiting to be sent.
980 if (target_url_status_ == TARGET_PENDING) {
981 Send(new ViewHostMsg_UpdateTargetURL(routing_id_, page_id_,
982 pending_target_url_));
983 }
984
985 target_url_status_ = TARGET_NONE;
986}
987
988void RenderView::OnUndo() {
989 if (!webview())
990 return;
991
[email protected]26aa0482009-09-30 16:55:27992 webview()->focusedFrame()->executeCommand(WebString::fromUTF8("Undo"));
[email protected]afe3a1672009-11-17 19:04:12993 UserMetricsRecordAction("Undo");
initial.commit09911bf2008-07-26 23:55:29994}
995
996void RenderView::OnRedo() {
997 if (!webview())
998 return;
999
[email protected]26aa0482009-09-30 16:55:271000 webview()->focusedFrame()->executeCommand(WebString::fromUTF8("Redo"));
[email protected]afe3a1672009-11-17 19:04:121001 UserMetricsRecordAction("Redo");
initial.commit09911bf2008-07-26 23:55:291002}
1003
1004void RenderView::OnCut() {
1005 if (!webview())
1006 return;
1007
[email protected]26aa0482009-09-30 16:55:271008 webview()->focusedFrame()->executeCommand(WebString::fromUTF8("Cut"));
[email protected]afe3a1672009-11-17 19:04:121009 UserMetricsRecordAction("Cut");
initial.commit09911bf2008-07-26 23:55:291010}
1011
1012void RenderView::OnCopy() {
1013 if (!webview())
1014 return;
1015
[email protected]26aa0482009-09-30 16:55:271016 webview()->focusedFrame()->executeCommand(WebString::fromUTF8("Copy"));
[email protected]afe3a1672009-11-17 19:04:121017 UserMetricsRecordAction("Copy");
initial.commit09911bf2008-07-26 23:55:291018}
1019
[email protected]c0cc3092009-09-12 08:27:271020#if defined(OS_MACOSX)
[email protected]a954bf72009-09-12 07:30:351021void RenderView::OnCopyToFindPboard() {
1022 if (!webview())
1023 return;
1024
1025 // Since the find pasteboard supports only plain text, this can be simpler
1026 // than the |OnCopy()| case.
[email protected]26aa0482009-09-30 16:55:271027 WebFrame* frame = webview()->focusedFrame();
[email protected]a954bf72009-09-12 07:30:351028 if (frame->hasSelection()) {
1029 string16 selection = frame->selectionAsText();
1030 RenderThread::current()->Send(
1031 new ViewHostMsg_ClipboardFindPboardWriteStringAsync(selection));
1032 }
1033
[email protected]afe3a1672009-11-17 19:04:121034 UserMetricsRecordAction("CopyToFindPboard");
[email protected]a954bf72009-09-12 07:30:351035}
[email protected]c0cc3092009-09-12 08:27:271036#endif
[email protected]a954bf72009-09-12 07:30:351037
initial.commit09911bf2008-07-26 23:55:291038void RenderView::OnPaste() {
1039 if (!webview())
1040 return;
1041
[email protected]26aa0482009-09-30 16:55:271042 webview()->focusedFrame()->executeCommand(WebString::fromUTF8("Paste"));
[email protected]afe3a1672009-11-17 19:04:121043 UserMetricsRecordAction("Paste");
initial.commit09911bf2008-07-26 23:55:291044}
1045
[email protected]2a3a7762009-10-19 19:17:321046void RenderView::OnReplace(const string16& text) {
initial.commit09911bf2008-07-26 23:55:291047 if (!webview())
1048 return;
1049
[email protected]1ff7a032010-02-03 02:46:031050 WebFrame* frame = webview()->focusedFrame();
1051 if (!frame->hasSelection())
1052 frame->selectWordAroundCaret();
1053 frame->replaceSelection(text);
initial.commit09911bf2008-07-26 23:55:291054}
1055
[email protected]98324892009-09-09 21:16:051056void RenderView::OnAdvanceToNextMisspelling() {
1057 if (!webview())
1058 return;
[email protected]26aa0482009-09-30 16:55:271059 webview()->focusedFrame()->executeCommand(
[email protected]98324892009-09-09 21:16:051060 WebString::fromUTF8("AdvanceToNextMisspelling"));
1061}
1062
1063void RenderView::OnToggleSpellPanel(bool is_currently_visible) {
1064 if (!webview())
1065 return;
1066 // We need to tell the webView whether the spelling panel is visible or not so
1067 // that it won't need to make ipc calls later.
[email protected]8922e1f2009-10-03 05:01:261068 spelling_panel_visible_ = is_currently_visible;
[email protected]26aa0482009-09-30 16:55:271069 webview()->focusedFrame()->executeCommand(
[email protected]98324892009-09-09 21:16:051070 WebString::fromUTF8("ToggleSpellPanel"));
1071}
1072
[email protected]bbbd545c2008-12-15 20:18:041073void RenderView::OnToggleSpellCheck() {
1074 if (!webview())
1075 return;
1076
[email protected]26aa0482009-09-30 16:55:271077 WebFrame* frame = webview()->focusedFrame();
[email protected]dd7daa82009-08-10 05:46:451078 frame->enableContinuousSpellChecking(
1079 !frame->isContinuousSpellCheckingEnabled());
[email protected]bbbd545c2008-12-15 20:18:041080}
1081
initial.commit09911bf2008-07-26 23:55:291082void RenderView::OnDelete() {
1083 if (!webview())
1084 return;
1085
[email protected]26aa0482009-09-30 16:55:271086 webview()->focusedFrame()->executeCommand(WebString::fromUTF8("Delete"));
[email protected]afe3a1672009-11-17 19:04:121087 UserMetricsRecordAction("DeleteSelection");
initial.commit09911bf2008-07-26 23:55:291088}
1089
1090void RenderView::OnSelectAll() {
1091 if (!webview())
1092 return;
1093
[email protected]26aa0482009-09-30 16:55:271094 webview()->focusedFrame()->executeCommand(
[email protected]a100d76bb2009-08-14 17:50:221095 WebString::fromUTF8("SelectAll"));
[email protected]afe3a1672009-11-17 19:04:121096 UserMetricsRecordAction("SelectAll");
initial.commit09911bf2008-07-26 23:55:291097}
1098
1099void RenderView::OnSetInitialFocus(bool reverse) {
1100 if (!webview())
1101 return;
[email protected]26aa0482009-09-30 16:55:271102 webview()->setInitialFocus(reverse);
initial.commit09911bf2008-07-26 23:55:291103}
1104
1105///////////////////////////////////////////////////////////////////////////////
1106
[email protected]433819d2010-01-30 20:20:011107void RenderView::SetContentSettings(const ContentSettings& settings) {
1108 current_content_settings_ = settings;
[email protected]f85f0702010-01-30 09:31:011109}
1110
initial.commit09911bf2008-07-26 23:55:291111// Tell the embedding application that the URL of the active page has changed
1112void RenderView::UpdateURL(WebFrame* frame) {
[email protected]dd7daa82009-08-10 05:46:451113 WebDataSource* ds = frame->dataSource();
initial.commit09911bf2008-07-26 23:55:291114 DCHECK(ds);
1115
[email protected]726985e22009-06-18 21:09:281116 const WebURLRequest& request = ds->request();
1117 const WebURLRequest& original_request = ds->originalRequest();
1118 const WebURLResponse& response = ds->response();
initial.commit09911bf2008-07-26 23:55:291119
[email protected]daa8c58e2009-06-15 17:21:101120 NavigationState* navigation_state = NavigationState::FromDataSource(ds);
1121 DCHECK(navigation_state);
initial.commit09911bf2008-07-26 23:55:291122
1123 ViewHostMsg_FrameNavigate_Params params;
[email protected]726985e22009-06-18 21:09:281124 params.http_status_code = response.httpStatusCode();
initial.commit09911bf2008-07-26 23:55:291125 params.is_post = false;
1126 params.page_id = page_id_;
[email protected]726985e22009-06-18 21:09:281127 params.is_content_filtered = response.isContentFiltered();
[email protected]e6f546c32009-07-01 17:12:551128 if (!navigation_state->security_info().empty()) {
initial.commit09911bf2008-07-26 23:55:291129 // SSL state specified in the request takes precedence over the one in the
1130 // response.
1131 // So far this is only intended for error pages that are not expected to be
1132 // over ssl, so we should not get any clash.
[email protected]726985e22009-06-18 21:09:281133 DCHECK(response.securityInfo().isEmpty());
[email protected]e6f546c32009-07-01 17:12:551134 params.security_info = navigation_state->security_info();
initial.commit09911bf2008-07-26 23:55:291135 } else {
[email protected]726985e22009-06-18 21:09:281136 params.security_info = response.securityInfo();
initial.commit09911bf2008-07-26 23:55:291137 }
1138
1139 // Set the URL to be displayed in the browser UI to the user.
[email protected]726985e22009-06-18 21:09:281140 if (ds->hasUnreachableURL()) {
1141 params.url = ds->unreachableURL();
initial.commit09911bf2008-07-26 23:55:291142 } else {
[email protected]726985e22009-06-18 21:09:281143 params.url = request.url();
initial.commit09911bf2008-07-26 23:55:291144 }
1145
[email protected]726985e22009-06-18 21:09:281146 GetRedirectChain(ds, &params.redirects);
1147 params.should_update_history = !ds->hasUnreachableURL();
initial.commit09911bf2008-07-26 23:55:291148
[email protected]ce0e250d2009-10-23 21:00:351149 params.searchable_form_url = navigation_state->searchable_form_url();
1150 params.searchable_form_encoding =
1151 navigation_state->searchable_form_encoding();
initial.commit09911bf2008-07-26 23:55:291152
1153 const PasswordForm* password_form_data =
[email protected]daa8c58e2009-06-15 17:21:101154 navigation_state->password_form_data();
initial.commit09911bf2008-07-26 23:55:291155 if (password_form_data)
1156 params.password_form = *password_form_data;
1157
1158 params.gesture = navigation_gesture_;
1159 navigation_gesture_ = NavigationGestureUnknown;
1160
[email protected]dd7daa82009-08-10 05:46:451161 if (!frame->parent()) {
initial.commit09911bf2008-07-26 23:55:291162 // Top-level navigation.
1163
[email protected]f85f0702010-01-30 09:31:011164 // Set content settings.
1165 HostContentSettings::iterator host_content_settings =
1166 host_content_settings_.find(GURL(request.url()).host());
1167 if (host_content_settings != host_content_settings_.end()) {
[email protected]433819d2010-01-30 20:20:011168 SetContentSettings(host_content_settings->second);
[email protected]f85f0702010-01-30 09:31:011169
1170 // These content settings were merely recorded transiently for this load.
1171 // We can erase them now. If at some point we reload this page, the
1172 // browser will send us new, up-to-date content settings.
1173 host_content_settings_.erase(host_content_settings);
1174 }
1175
[email protected]40bd6582009-12-04 23:49:511176 // Set zoom level.
[email protected]f85f0702010-01-30 09:31:011177 HostZoomLevels::iterator host_zoom =
[email protected]40bd6582009-12-04 23:49:511178 host_zoom_levels_.find(GURL(request.url()).host());
[email protected]f85f0702010-01-30 09:31:011179 if (host_zoom != host_zoom_levels_.end()) {
1180 webview()->setZoomLevel(false, host_zoom->second);
[email protected]40bd6582009-12-04 23:49:511181 // This zoom level was merely recorded transiently for this load. We can
1182 // erase it now. If at some point we reload this page, the browser will
1183 // send us a new, up-to-date zoom level.
[email protected]f85f0702010-01-30 09:31:011184 host_zoom_levels_.erase(host_zoom);
[email protected]40bd6582009-12-04 23:49:511185 }
1186
[email protected]4c408fdb2010-01-30 00:40:581187 // Drop the translated nodes.
1188 page_translator_->NavigatedToNewPage();
1189
initial.commit09911bf2008-07-26 23:55:291190 // Update contents MIME type for main frame.
[email protected]9c5645b2009-08-11 03:37:551191 params.contents_mime_type = ds->response().mimeType().utf8();
initial.commit09911bf2008-07-26 23:55:291192
[email protected]daa8c58e2009-06-15 17:21:101193 params.transition = navigation_state->transition_type();
initial.commit09911bf2008-07-26 23:55:291194 if (!PageTransition::IsMainFrame(params.transition)) {
1195 // If the main frame does a load, it should not be reported as a subframe
1196 // navigation. This can occur in the following case:
1197 // 1. You're on a site with frames.
1198 // 2. You do a subframe navigation. This is stored with transition type
1199 // MANUAL_SUBFRAME.
1200 // 3. You navigate to some non-frame site, say, google.com.
1201 // 4. You navigate back to the page from step 2. Since it was initially
1202 // MANUAL_SUBFRAME, it will be that same transition type here.
1203 // We don't want that, because any navigation that changes the toplevel
1204 // frame should be tracked as a toplevel navigation (this allows us to
1205 // update the URL bar, etc).
1206 params.transition = PageTransition::LINK;
1207 }
1208
initial.commit09911bf2008-07-26 23:55:291209 // If we have a valid consumed client redirect source,
1210 // the page contained a client redirect (meta refresh, document.loc...),
1211 // so we set the referrer and transition to match.
1212 if (completed_client_redirect_src_.is_valid()) {
[email protected]77e09a92008-08-01 18:11:041213 DCHECK(completed_client_redirect_src_ == params.redirects[0]);
initial.commit09911bf2008-07-26 23:55:291214 params.referrer = completed_client_redirect_src_;
1215 params.transition = static_cast<PageTransition::Type>(
1216 params.transition | PageTransition::CLIENT_REDIRECT);
1217 } else {
1218 // Bug 654101: the referrer will be empty on https->http transitions. It
1219 // would be nice if we could get the real referrer from somewhere.
[email protected]726985e22009-06-18 21:09:281220 params.referrer = GURL(
1221 original_request.httpHeaderField(WebString::fromUTF8("Referer")));
initial.commit09911bf2008-07-26 23:55:291222 }
1223
[email protected]726985e22009-06-18 21:09:281224 string16 method = request.httpMethod();
1225 if (EqualsASCII(method, "POST"))
initial.commit09911bf2008-07-26 23:55:291226 params.is_post = true;
1227
[email protected]c2a797d2009-09-21 16:46:321228 // Save some histogram data so we can compute the average memory used per
1229 // page load of the glyphs.
1230 UMA_HISTOGRAM_COUNTS_10000("Memory.GlyphPagesPerLoad",
1231 webkit_glue::GetGlyphPageCount());
1232
initial.commit09911bf2008-07-26 23:55:291233 Send(new ViewHostMsg_FrameNavigate(routing_id_, params));
1234 } else {
1235 // Subframe navigation: the type depends on whether this navigation
1236 // generated a new session history entry. When they do generate a session
1237 // history entry, it means the user initiated the navigation and we should
1238 // mark it as such. This test checks if this is the first time UpdateURL
1239 // has been called since WillNavigateToURL was called to initiate the load.
1240 if (page_id_ > last_page_id_sent_to_browser_)
1241 params.transition = PageTransition::MANUAL_SUBFRAME;
1242 else
1243 params.transition = PageTransition::AUTO_SUBFRAME;
1244
initial.commit09911bf2008-07-26 23:55:291245 Send(new ViewHostMsg_FrameNavigate(routing_id_, params));
1246 }
1247
1248 last_page_id_sent_to_browser_ =
1249 std::max(last_page_id_sent_to_browser_, page_id_);
1250
1251 // If we end up reusing this WebRequest (for example, due to a #ref click),
[email protected]daa8c58e2009-06-15 17:21:101252 // we don't want the transition type to persist. Just clear it.
1253 navigation_state->set_transition_type(PageTransition::LINK);
[email protected]266eb6f2008-09-30 23:56:501254
[email protected]6c8afae52009-01-22 02:24:571255#if defined(OS_WIN)
[email protected]c7287a92009-11-04 20:06:151256 if (accessibility_.get()) {
[email protected]be645db2009-02-06 20:36:331257 // Clear accessibility info cache.
[email protected]c7287a92009-11-04 20:06:151258 accessibility_->clear();
[email protected]266eb6f2008-09-30 23:56:501259 }
[email protected]6c8afae52009-01-22 02:24:571260#else
[email protected]7d926f92009-03-03 14:26:541261 // TODO(port): accessibility not yet implemented. See http://crbug.com/8288.
[email protected]6c8afae52009-01-22 02:24:571262#endif
initial.commit09911bf2008-07-26 23:55:291263}
1264
1265// Tell the embedding application that the title of the active page has changed
[email protected]3d9689372009-09-10 04:29:171266void RenderView::UpdateTitle(WebFrame* frame, const string16& title) {
initial.commit09911bf2008-07-26 23:55:291267 // Ignore all but top level navigations...
[email protected]3d9689372009-09-10 04:29:171268 if (!frame->parent()) {
[email protected]f0af6a72009-05-30 05:25:171269 Send(new ViewHostMsg_UpdateTitle(
[email protected]3d9689372009-09-10 04:29:171270 routing_id_,
1271 page_id_,
1272 UTF16ToWideHack(title.length() > chrome::kMaxTitleChars ?
1273 title.substr(0, chrome::kMaxTitleChars) : title)));
[email protected]f0af6a72009-05-30 05:25:171274 }
initial.commit09911bf2008-07-26 23:55:291275}
1276
1277void RenderView::UpdateEncoding(WebFrame* frame,
[email protected]41fc0322009-09-04 22:23:401278 const std::string& encoding_name) {
initial.commit09911bf2008-07-26 23:55:291279 // Only update main frame's encoding_name.
[email protected]26aa0482009-09-30 16:55:271280 if (webview()->mainFrame() == frame &&
initial.commit09911bf2008-07-26 23:55:291281 last_encoding_name_ != encoding_name) {
[email protected]e38f40152008-09-12 23:08:301282 // Save the encoding name for later comparing.
initial.commit09911bf2008-07-26 23:55:291283 last_encoding_name_ = encoding_name;
1284
[email protected]e38f40152008-09-12 23:08:301285 Send(new ViewHostMsg_UpdateEncoding(routing_id_, last_encoding_name_));
initial.commit09911bf2008-07-26 23:55:291286 }
1287}
1288
[email protected]f4d34b52008-11-24 23:05:011289// Sends the previous session history state to the browser so it will be saved
1290// before we navigate to a new page. This must be called *before* the page ID
1291// has been updated so we know what it was.
initial.commit09911bf2008-07-26 23:55:291292void RenderView::UpdateSessionHistory(WebFrame* frame) {
1293 // If we have a valid page ID at this point, then it corresponds to the page
1294 // we are navigating away from. Otherwise, this is the first navigation, so
1295 // there is no past session history to record.
1296 if (page_id_ == -1)
1297 return;
1298
[email protected]ca948a22009-06-25 19:36:171299 const WebHistoryItem& item =
[email protected]26aa0482009-09-30 16:55:271300 webview()->mainFrame()->previousHistoryItem();
[email protected]ca948a22009-06-25 19:36:171301 if (item.isNull())
initial.commit09911bf2008-07-26 23:55:291302 return;
[email protected]ca948a22009-06-25 19:36:171303
1304 Send(new ViewHostMsg_UpdateState(
1305 routing_id_, page_id_, webkit_glue::HistoryItemToString(item)));
initial.commit09911bf2008-07-26 23:55:291306}
1307
[email protected]3d9689372009-09-10 04:29:171308void RenderView::OpenURL(
1309 const GURL& url, const GURL& referrer, WebNavigationPolicy policy) {
1310 Send(new ViewHostMsg_OpenURL(
1311 routing_id_, url, referrer, NavigationPolicyToDisposition(policy)));
1312}
1313
[email protected]79dbc662009-09-04 05:42:511314// WebViewDelegate ------------------------------------------------------------
initial.commit09911bf2008-07-26 23:55:291315
[email protected]a2f6bc112009-06-27 16:27:251316void RenderView::DidPaint() {
[email protected]26aa0482009-09-30 16:55:271317 WebFrame* main_frame = webview()->mainFrame();
[email protected]a2f6bc112009-06-27 16:27:251318
[email protected]dd7daa82009-08-10 05:46:451319 if (main_frame->provisionalDataSource()) {
[email protected]a2f6bc112009-06-27 16:27:251320 // If we have a provisional frame we are between the start
1321 // and commit stages of loading...ignore this paint.
1322 return;
1323 }
1324
[email protected]dd7daa82009-08-10 05:46:451325 WebDataSource* ds = main_frame->dataSource();
[email protected]a2f6bc112009-06-27 16:27:251326 NavigationState* navigation_state = NavigationState::FromDataSource(ds);
[email protected]78a3a6f2009-07-02 16:15:011327 DCHECK(navigation_state);
1328
1329 Time now = Time::Now();
1330 if (navigation_state->first_paint_time().is_null()) {
1331 navigation_state->set_first_paint_time(now);
1332 }
1333 if (navigation_state->first_paint_after_load_time().is_null() &&
1334 !navigation_state->finish_load_time().is_null()) {
1335 navigation_state->set_first_paint_after_load_time(now);
[email protected]a2f6bc112009-06-27 16:27:251336 }
1337}
1338
initial.commit09911bf2008-07-26 23:55:291339void RenderView::LoadNavigationErrorPage(WebFrame* frame,
[email protected]726985e22009-06-18 21:09:281340 const WebURLRequest& failed_request,
1341 const WebURLError& error,
initial.commit09911bf2008-07-26 23:55:291342 const std::string& html,
1343 bool replace) {
[email protected]726985e22009-06-18 21:09:281344 GURL failed_url = error.unreachableURL;
initial.commit09911bf2008-07-26 23:55:291345
1346 std::string alt_html;
1347 if (html.empty()) {
1348 // Use a local error page.
1349 int resource_id;
1350 DictionaryValue error_strings;
[email protected]726985e22009-06-18 21:09:281351 if (error.reason == net::ERR_CACHE_MISS &&
1352 EqualsASCII(failed_request.httpMethod(), "POST")) {
initial.commit09911bf2008-07-26 23:55:291353 GetFormRepostErrorValues(failed_url, &error_strings);
1354 resource_id = IDR_ERROR_NO_DETAILS_HTML;
1355 } else {
1356 GetLocalizedErrorValues(error, &error_strings);
1357 resource_id = IDR_NET_ERROR_HTML;
1358 }
[email protected]8e50b602009-03-03 22:59:431359 error_strings.SetString(L"textdirection",
1360 (l10n_util::GetTextDirection() == l10n_util::RIGHT_TO_LEFT) ?
1361 L"rtl" : L"ltr");
initial.commit09911bf2008-07-26 23:55:291362
1363 alt_html = GetAltHTMLForTemplate(error_strings, resource_id);
1364 } else {
1365 alt_html = html;
1366 }
1367
[email protected]dd7daa82009-08-10 05:46:451368 frame->loadHTMLString(alt_html,
[email protected]e6f546c32009-07-01 17:12:551369 GURL(kUnreachableWebDataURL),
1370 failed_url,
1371 replace);
initial.commit09911bf2008-07-26 23:55:291372}
1373
[email protected]7ccddb8c2009-08-04 17:36:551374void RenderView::BindDOMAutomationController(WebFrame* frame) {
initial.commit09911bf2008-07-26 23:55:291375 dom_automation_controller_.set_message_sender(this);
1376 dom_automation_controller_.set_routing_id(routing_id_);
[email protected]7ccddb8c2009-08-04 17:36:551377 dom_automation_controller_.BindToJavascript(frame,
initial.commit09911bf2008-07-26 23:55:291378 L"domAutomationController");
1379}
1380
initial.commit09911bf2008-07-26 23:55:291381bool RenderView::RunJavaScriptMessage(int type,
1382 const std::wstring& message,
1383 const std::wstring& default_value,
[email protected]a455d3812009-03-05 20:18:071384 const GURL& frame_url,
initial.commit09911bf2008-07-26 23:55:291385 std::wstring* result) {
1386 bool success = false;
1387 std::wstring result_temp;
1388 if (!result)
1389 result = &result_temp;
initial.commit09911bf2008-07-26 23:55:291390
[email protected]12636df2009-09-28 22:32:211391 SendAndRunNestedMessageLoop(new ViewHostMsg_RunJavaScriptMessage(
1392 routing_id_, message, default_value, frame_url, type, &success, result));
initial.commit09911bf2008-07-26 23:55:291393 return success;
1394}
1395
1396void RenderView::AddGURLSearchProvider(const GURL& osd_url, bool autodetected) {
1397 if (!osd_url.is_empty())
1398 Send(new ViewHostMsg_PageHasOSDD(routing_id_, page_id_, osd_url,
1399 autodetected));
1400}
1401
[email protected]842936a2009-10-14 06:00:361402void RenderView::OnQueryFormFieldAutofillAck(
[email protected]acca2a1f2009-10-16 03:53:391403 int query_id,
1404 const std::vector<string16>& suggestions,
[email protected]0ebf3872008-11-07 21:35:031405 int default_suggestion_index) {
[email protected]7e089f272009-11-03 17:07:181406 if (webview() && query_id == autofill_query_id_) {
[email protected]acca2a1f2009-10-16 03:53:391407 webview()->applyAutofillSuggestions(
1408 autofill_query_node_, suggestions, default_suggestion_index);
1409 }
1410 autofill_query_node_.reset();
[email protected]0ebf3872008-11-07 21:35:031411}
1412
[email protected]2c4410d2009-05-06 23:46:221413void RenderView::OnPopupNotificationVisibilityChanged(bool visible) {
[email protected]634a6f92008-12-01 21:39:311414 popup_notification_visible_ = visible;
1415}
1416
initial.commit09911bf2008-07-26 23:55:291417uint32 RenderView::GetCPBrowsingContext() {
1418 uint32 context = 0;
1419 Send(new ViewHostMsg_GetCPBrowsingContext(&context));
1420 return context;
1421}
1422
initial.commit09911bf2008-07-26 23:55:291423void RenderView::AddSearchProvider(const std::string& url) {
1424 AddGURLSearchProvider(GURL(url),
1425 false); // not autodetected
1426}
1427
[email protected]f103ab72009-09-02 17:10:591428void RenderView::OnMissingPluginStatus(
1429 WebPluginDelegateProxy* delegate,
1430 int status) {
[email protected]6c8afae52009-01-22 02:24:571431#if defined(OS_WIN)
[email protected]f103ab72009-09-02 17:10:591432 if (!first_default_plugin_) {
initial.commit09911bf2008-07-26 23:55:291433 // Show the InfoBar for the first available plugin.
1434 if (status == default_plugin::MISSING_PLUGIN_AVAILABLE) {
[email protected]f103ab72009-09-02 17:10:591435 first_default_plugin_ = delegate->AsWeakPtr();
initial.commit09911bf2008-07-26 23:55:291436 Send(new ViewHostMsg_MissingPluginStatus(routing_id_, status));
1437 }
1438 } else {
1439 // Closes the InfoBar if user clicks on the plugin (instead of the InfoBar)
1440 // to start the download/install.
1441 if (status == default_plugin::MISSING_PLUGIN_USER_STARTED_DOWNLOAD) {
1442 Send(new ViewHostMsg_MissingPluginStatus(routing_id_, status));
1443 }
1444 }
[email protected]6c8afae52009-01-22 02:24:571445#else
1446 // TODO(port): plugins current not supported
1447 NOTIMPLEMENTED();
1448#endif
initial.commit09911bf2008-07-26 23:55:291449}
1450
[email protected]48c9cf2d2009-09-16 16:47:521451// WebKit::WebViewClient ------------------------------------------------------
1452
1453WebView* RenderView::createView(WebFrame* creator) {
1454 // Check to make sure we aren't overloading on popups.
1455 if (shared_popup_counter_->data > kMaximumNumberOfUnacknowledgedPopups)
1456 return NULL;
1457
1458 // This window can't be closed from a window.close() call until we receive a
1459 // message from the Browser process explicitly allowing it.
1460 popup_notification_visible_ = true;
1461
1462 int32 routing_id = MSG_ROUTING_NONE;
1463 bool user_gesture = creator->isProcessingUserGesture();
[email protected]007a848b2009-10-26 15:55:461464 bool opener_suppressed = creator->willSuppressOpenerInNewFrame();
[email protected]4e6419c2010-01-15 04:50:341465 int64 cloned_session_storage_namespace_id;
[email protected]48c9cf2d2009-09-16 16:47:521466
[email protected]48c9cf2d2009-09-16 16:47:521467 render_thread_->Send(
[email protected]4e6419c2010-01-15 04:50:341468 new ViewHostMsg_CreateWindow(routing_id_, user_gesture,
1469 session_storage_namespace_id_,
1470 &routing_id,
1471 &cloned_session_storage_namespace_id));
[email protected]12636df2009-09-28 22:32:211472 if (routing_id == MSG_ROUTING_NONE)
[email protected]48c9cf2d2009-09-16 16:47:521473 return NULL;
[email protected]48c9cf2d2009-09-16 16:47:521474
[email protected]48c9cf2d2009-09-16 16:47:521475 RenderView* view = RenderView::Create(render_thread_,
[email protected]659f73fa2009-10-13 13:43:421476 0,
[email protected]12636df2009-09-28 22:32:211477 routing_id_,
[email protected]48c9cf2d2009-09-16 16:47:521478 renderer_preferences_,
1479 webkit_preferences_,
[email protected]12636df2009-09-28 22:32:211480 shared_popup_counter_,
[email protected]4e6419c2010-01-15 04:50:341481 routing_id,
1482 cloned_session_storage_namespace_id);
[email protected]48c9cf2d2009-09-16 16:47:521483 view->opened_by_user_gesture_ = user_gesture;
1484
[email protected]007a848b2009-10-26 15:55:461485 // Record whether the creator frame is trying to suppress the opener field.
1486 view->opener_suppressed_ = opener_suppressed;
1487
[email protected]48c9cf2d2009-09-16 16:47:521488 // Record the security origin of the creator.
[email protected]91733b62009-09-18 06:21:091489 GURL creator_url(creator->securityOrigin().toString().utf8());
[email protected]48c9cf2d2009-09-16 16:47:521490 if (!creator_url.is_valid() || !creator_url.IsStandard())
1491 creator_url = GURL();
1492 view->creator_url_ = creator_url;
1493
1494 // Copy over the alternate error page URL so we can have alt error pages in
1495 // the new render view (we don't need the browser to send the URL back down).
1496 view->alternate_error_page_url_ = alternate_error_page_url_;
1497
1498 return view->webview();
1499}
1500
1501WebWidget* RenderView::createPopupMenu(bool activatable) {
1502 RenderWidget* widget = RenderWidget::Create(routing_id_,
1503 render_thread_,
1504 activatable);
1505 return widget->webwidget();
1506}
1507
1508WebWidget* RenderView::createPopupMenu(const WebPopupMenuInfo& info) {
1509 RenderWidget* widget = RenderWidget::Create(routing_id_,
1510 render_thread_,
1511 true);
1512 widget->ConfigureAsExternalPopupMenu(info);
1513 return widget->webwidget();
1514}
1515
[email protected]bd92c3a2010-01-13 05:02:341516WebStorageNamespace* RenderView::createSessionStorageNamespace() {
1517 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kSingleProcess))
1518 return WebStorageNamespace::createSessionStorageNamespace();
[email protected]59afea12010-01-20 04:48:291519 CHECK(session_storage_namespace_id_ != kInvalidSessionStorageNamespaceId);
1520 return new RendererWebStorageNamespaceImpl(DOM_STORAGE_SESSION,
1521 session_storage_namespace_id_);
[email protected]bd92c3a2010-01-13 05:02:341522}
1523
[email protected]48c9cf2d2009-09-16 16:47:521524void RenderView::didAddMessageToConsole(
1525 const WebConsoleMessage& message, const WebString& source_name,
1526 unsigned source_line) {
1527 Send(new ViewHostMsg_AddMessageToConsole(routing_id_,
1528 UTF16ToWideHack(message.text),
1529 static_cast<int32>(source_line),
1530 UTF16ToWideHack(source_name)));
1531}
1532
1533void RenderView::printPage(WebFrame* frame) {
[email protected]71a14262009-09-22 20:02:581534 DCHECK(frame);
1535 Print(frame, true);
[email protected]48c9cf2d2009-09-16 16:47:521536}
1537
1538void RenderView::didStartLoading() {
1539 if (is_loading_) {
1540 DLOG(WARNING) << "didStartLoading called while loading";
1541 return;
1542 }
1543
1544 is_loading_ = true;
1545 // Clear the pointer so that we can assign it only when there is an unknown
1546 // plugin on a page.
1547 first_default_plugin_.reset();
1548
1549 Send(new ViewHostMsg_DidStartLoading(routing_id_));
1550}
1551
1552void RenderView::didStopLoading() {
1553 if (!is_loading_) {
1554 DLOG(WARNING) << "DidStopLoading called while not loading";
1555 return;
1556 }
1557
1558 is_loading_ = false;
1559
1560 // NOTE: For now we're doing the safest thing, and sending out notification
1561 // when done loading. This currently isn't an issue as the favicon is only
1562 // displayed when done loading. Ideally we would send notification when
1563 // finished parsing the head, but webkit doesn't support that yet.
1564 // The feed discovery code would also benefit from access to the head.
[email protected]26aa0482009-09-30 16:55:271565 GURL favicon_url(webview()->mainFrame()->favIconURL());
[email protected]48c9cf2d2009-09-16 16:47:521566 if (!favicon_url.is_empty())
1567 Send(new ViewHostMsg_UpdateFavIconURL(routing_id_, page_id_, favicon_url));
1568
[email protected]26aa0482009-09-30 16:55:271569 AddGURLSearchProvider(webview()->mainFrame()->openSearchDescriptionURL(),
[email protected]48c9cf2d2009-09-16 16:47:521570 true); // autodetected
1571
1572 Send(new ViewHostMsg_DidStopLoading(routing_id_));
1573
1574 MessageLoop::current()->PostDelayedTask(FROM_HERE,
1575 method_factory_.NewRunnableMethod(&RenderView::CapturePageInfo, page_id_,
1576 false),
1577 kDelayForCaptureMs);
[email protected]48c9cf2d2009-09-16 16:47:521578}
1579
[email protected]04fc9482009-09-18 22:13:031580bool RenderView::isSelectTrailingWhitespaceEnabled() {
1581#if defined(OS_WIN)
1582 return true;
1583#else
1584 return false;
1585#endif
1586}
1587
1588void RenderView::setInputMethodEnabled(bool enabled) {
1589 // Save the updated IME status and mark the input focus has been updated.
1590 // The IME status is to be sent to a browser process next time when
1591 // the input caret is rendered.
1592 if (!ime_control_busy_) {
1593 ime_control_updated_ = true;
1594 ime_control_new_state_ = enabled;
1595 }
1596}
1597
1598void RenderView::didChangeSelection(bool is_empty_selection) {
1599#if defined(OS_LINUX)
1600 if (!handling_input_event_)
1601 return;
1602 // TODO(estade): investigate incremental updates to the selection so that we
1603 // don't send the entire selection over IPC every time.
1604 if (!is_empty_selection) {
1605 // Sometimes we get repeated didChangeSelection calls from webkit when
1606 // the selection hasn't actually changed. We don't want to report these
1607 // because it will cause us to continually claim the X clipboard.
1608 const std::string& this_selection =
[email protected]26aa0482009-09-30 16:55:271609 webview()->focusedFrame()->selectionAsText().utf8();
[email protected]04fc9482009-09-18 22:13:031610 if (this_selection == last_selection_)
1611 return;
1612
1613 Send(new ViewHostMsg_SelectionChanged(routing_id_,
1614 this_selection));
1615 last_selection_ = this_selection;
1616 } else {
1617 last_selection_.clear();
1618 }
1619#endif
1620}
1621
1622void RenderView::didExecuteCommand(const WebString& command_name) {
[email protected]afe3a1672009-11-17 19:04:121623 const std::string& name = UTF16ToUTF8(command_name);
1624 if (StartsWithASCII(name, "Move", true) ||
1625 StartsWithASCII(name, "Insert", true) ||
1626 StartsWithASCII(name, "Delete", true))
[email protected]04fc9482009-09-18 22:13:031627 return;
1628 UserMetricsRecordAction(name);
1629}
1630
[email protected]b2528b72009-09-24 06:57:101631bool RenderView::handleCurrentKeyboardEvent() {
1632 if (edit_commands_.empty())
1633 return false;
1634
[email protected]26aa0482009-09-30 16:55:271635 WebFrame* frame = webview()->focusedFrame();
[email protected]b2528b72009-09-24 06:57:101636 if (!frame)
1637 return false;
1638
1639 EditCommands::iterator it = edit_commands_.begin();
1640 EditCommands::iterator end = edit_commands_.end();
1641
[email protected]507b33ea2009-09-29 03:56:511642 bool did_execute_command = false;
[email protected]b2528b72009-09-24 06:57:101643 for (; it != end; ++it) {
[email protected]e6e15012009-09-30 14:59:331644 // In gtk and cocoa, it's possible to bind multiple edit commands to one
1645 // key (but it's the exception). Once one edit command is not executed, it
1646 // seems safest to not execute the rest.
[email protected]b2528b72009-09-24 06:57:101647 if (!frame->executeCommand(WebString::fromUTF8(it->name),
1648 WebString::fromUTF8(it->value)))
1649 break;
[email protected]507b33ea2009-09-29 03:56:511650 did_execute_command = true;
[email protected]b2528b72009-09-24 06:57:101651 }
1652
[email protected]507b33ea2009-09-29 03:56:511653 return did_execute_command;
[email protected]b2528b72009-09-24 06:57:101654}
1655
[email protected]2a3a7762009-10-19 19:17:321656void RenderView::spellCheck(const WebString& text,
1657 int& misspelled_offset,
1658 int& misspelled_length) {
[email protected]1dbafaf72009-09-23 19:43:561659 EnsureDocumentTag();
[email protected]85c55dc2009-11-06 03:05:461660
[email protected]85c55dc2009-11-06 03:05:461661 string16 word(text);
[email protected]cb6037d2009-11-16 22:55:171662 RenderThread* thread = RenderThread::current();
1663 // Will be NULL during unit tests.
1664 if (thread) {
[email protected]c27324b2009-11-19 22:44:291665 thread->spellchecker()->SpellCheckWord(
[email protected]cb6037d2009-11-16 22:55:171666 word.c_str(), word.size(), document_tag_,
1667 &misspelled_offset, &misspelled_length, NULL);
1668 }
[email protected]1dbafaf72009-09-23 19:43:561669}
1670
1671WebString RenderView::autoCorrectWord(const WebKit::WebString& word) {
[email protected]2a3a7762009-10-19 19:17:321672 string16 autocorrect_word;
[email protected]1dbafaf72009-09-23 19:43:561673 const CommandLine& command_line = *CommandLine::ForCurrentProcess();
[email protected]b86c8c12009-10-05 22:01:261674 if (command_line.HasSwitch(switches::kExperimentalSpellcheckerFeatures)) {
[email protected]1dbafaf72009-09-23 19:43:561675 EnsureDocumentTag();
[email protected]cb6037d2009-11-16 22:55:171676 RenderThread* thread = RenderThread::current();
1677 // Will be NULL during unit tests.
1678 if (thread) {
1679 autocorrect_word =
[email protected]c27324b2009-11-19 22:44:291680 thread->spellchecker()->GetAutoCorrectionWord(
[email protected]cb6037d2009-11-16 22:55:171681 word, document_tag_);
1682 }
[email protected]1dbafaf72009-09-23 19:43:561683 }
[email protected]2a3a7762009-10-19 19:17:321684 return autocorrect_word;
[email protected]1dbafaf72009-09-23 19:43:561685}
1686
[email protected]c49085c72009-10-02 16:28:561687void RenderView::showSpellingUI(bool show) {
1688 Send(new ViewHostMsg_ShowSpellingPanel(routing_id_, show));
1689}
1690
[email protected]8922e1f2009-10-03 05:01:261691bool RenderView::isShowingSpellingUI() {
1692 return spelling_panel_visible_;
1693}
1694
[email protected]1dbafaf72009-09-23 19:43:561695void RenderView::updateSpellingUIWithMisspelledWord(const WebString& word) {
[email protected]2a3a7762009-10-19 19:17:321696 Send(new ViewHostMsg_UpdateSpellingPanelWithMisspelledWord(routing_id_,
1697 word));
[email protected]1dbafaf72009-09-23 19:43:561698}
1699
[email protected]a1128322009-10-06 18:38:461700bool RenderView::runFileChooser(
[email protected]01178b52010-01-15 06:59:351701 const WebKit::WebFileChooserParams& params,
[email protected]a1128322009-10-06 18:38:461702 WebKit::WebFileChooserCompletion* chooser_completion) {
1703 if (file_chooser_completion_) {
1704 // TODO(brettw): bug 1235154: This should be a synchronous message to deal
1705 // with the fact that web pages can programatically trigger this. With the
1706 // asnychronous messages, we can get an additional call when one is pending,
1707 // which this test is for. For now, we just ignore the additional file
1708 // chooser request. WebKit doesn't do anything to expect the callback, so
1709 // we can just ignore calling it.
1710 return false;
1711 }
1712 file_chooser_completion_ = chooser_completion;
1713 Send(new ViewHostMsg_RunFileChooser(
[email protected]01178b52010-01-15 06:59:351714 routing_id_, params.multiSelect, params.title,
1715 webkit_glue::WebStringToFilePath(params.initialValue)));
[email protected]a1128322009-10-06 18:38:461716 return true;
1717}
1718
[email protected]48c9cf2d2009-09-16 16:47:521719void RenderView::runModalAlertDialog(
1720 WebFrame* frame, const WebString& message) {
1721 RunJavaScriptMessage(MessageBoxFlags::kIsJavascriptAlert,
1722 UTF16ToWideHack(message),
1723 std::wstring(),
1724 frame->url(),
1725 NULL);
1726}
1727
1728bool RenderView::runModalConfirmDialog(
1729 WebFrame* frame, const WebString& message) {
1730 return RunJavaScriptMessage(MessageBoxFlags::kIsJavascriptConfirm,
1731 UTF16ToWideHack(message),
1732 std::wstring(),
1733 frame->url(),
1734 NULL);
1735}
1736
1737bool RenderView::runModalPromptDialog(
1738 WebFrame* frame, const WebString& message, const WebString& default_value,
1739 WebString* actual_value) {
1740 std::wstring result;
1741 bool ok = RunJavaScriptMessage(MessageBoxFlags::kIsJavascriptPrompt,
1742 UTF16ToWideHack(message),
1743 UTF16ToWideHack(default_value),
1744 frame->url(),
1745 &result);
1746 if (ok)
1747 actual_value->assign(WideToUTF16Hack(result));
1748 return ok;
1749}
1750
1751bool RenderView::runModalBeforeUnloadDialog(
1752 WebFrame* frame, const WebString& message) {
1753 bool success = false;
1754 // This is an ignored return value, but is included so we can accept the same
1755 // response as RunJavaScriptMessage.
1756 std::wstring ignored_result;
[email protected]12636df2009-09-28 22:32:211757 SendAndRunNestedMessageLoop(new ViewHostMsg_RunBeforeUnloadConfirm(
[email protected]48c9cf2d2009-09-16 16:47:521758 routing_id_, frame->url(), UTF16ToWideHack(message), &success,
[email protected]12636df2009-09-28 22:32:211759 &ignored_result));
[email protected]48c9cf2d2009-09-16 16:47:521760 return success;
1761}
1762
[email protected]79e37442009-10-09 18:17:441763void RenderView::showContextMenu(
1764 WebFrame* frame, const WebContextMenuData& data) {
[email protected]c27324b2009-11-19 22:44:291765 ContextMenuParams params = ContextMenuParams(data);
1766 if (!params.misspelled_word.empty() && RenderThread::current()) {
1767 int misspelled_offset, misspelled_length;
[email protected]c76a36a2010-01-26 22:44:041768 bool spelled_right = RenderThread::current()->spellchecker()->
1769 SpellCheckWord(
1770 params.misspelled_word.c_str(), params.misspelled_word.size(),
1771 document_tag_,
1772 &misspelled_offset, &misspelled_length,
1773 &params.dictionary_suggestions);
1774 if (spelled_right)
[email protected]c27324b2009-11-19 22:44:291775 params.misspelled_word.clear();
1776 }
1777
1778 Send(new ViewHostMsg_ContextMenu(routing_id_, params));
[email protected]79e37442009-10-09 18:17:441779}
1780
[email protected]48c9cf2d2009-09-16 16:47:521781void RenderView::setStatusText(const WebString& text) {
1782}
1783
[email protected]163f8242009-10-30 20:19:551784void RenderView::UpdateTargetURL(const GURL& url, const GURL& fallback_url) {
1785 GURL latest_url = url.spec().empty() ? fallback_url : url;
[email protected]48c9cf2d2009-09-16 16:47:521786 if (latest_url == target_url_)
1787 return;
[email protected]163f8242009-10-30 20:19:551788
[email protected]48c9cf2d2009-09-16 16:47:521789 // Tell the browser to display a destination link.
1790 if (target_url_status_ == TARGET_INFLIGHT ||
1791 target_url_status_ == TARGET_PENDING) {
1792 // If we have a request in-flight, save the URL to be sent when we
1793 // receive an ACK to the in-flight request. We can happily overwrite
1794 // any existing pending sends.
1795 pending_target_url_ = latest_url;
1796 target_url_status_ = TARGET_PENDING;
1797 } else {
1798 Send(new ViewHostMsg_UpdateTargetURL(routing_id_, page_id_, latest_url));
1799 target_url_ = latest_url;
1800 target_url_status_ = TARGET_INFLIGHT;
1801 }
1802}
1803
[email protected]882daa92009-11-05 16:31:311804void RenderView::StartNavStateSyncTimerIfNecessary() {
1805 int delay;
1806 if (send_content_state_immediately_)
1807 delay = 0;
1808 else if (is_hidden())
1809 delay = kDelaySecondsForContentStateSyncHidden;
1810 else
1811 delay = kDelaySecondsForContentStateSync;
1812
1813 if (nav_state_sync_timer_.IsRunning()) {
1814 // The timer is already running. If the delay of the timer maches the amount
1815 // we want to delay by, then return. Otherwise stop the timer so that it
1816 // gets started with the right delay.
1817 if (nav_state_sync_timer_.GetCurrentDelay().InSeconds() == delay)
1818 return;
1819 nav_state_sync_timer_.Stop();
1820 }
1821
1822 nav_state_sync_timer_.Start(
1823 TimeDelta::FromSeconds(delay), this, &RenderView::SyncNavigationState);
1824}
1825
[email protected]163f8242009-10-30 20:19:551826void RenderView::setMouseOverURL(const WebURL& url) {
1827 mouse_over_url_ = GURL(url);
1828 UpdateTargetURL(mouse_over_url_, focus_url_);
1829}
1830
1831void RenderView::setKeyboardFocusURL(const WebURL& url) {
1832 focus_url_ = GURL(url);
1833 UpdateTargetURL(focus_url_, mouse_over_url_);
1834}
1835
[email protected]48c9cf2d2009-09-16 16:47:521836void RenderView::setToolTipText(const WebString& text, WebTextDirection hint) {
1837 Send(new ViewHostMsg_SetTooltipText(routing_id_, UTF16ToWideHack(text),
1838 hint));
1839}
1840
1841void RenderView::startDragging(const WebPoint& from, const WebDragData& data,
1842 WebDragOperationsMask allowed_ops) {
1843 Send(new ViewHostMsg_StartDragging(routing_id_,
1844 WebDropData(data),
1845 allowed_ops));
1846}
1847
[email protected]28b92df2009-09-25 17:35:451848bool RenderView::acceptsLoadDrops() {
1849 return renderer_preferences_.can_accept_load_drops;
1850}
1851
[email protected]48c9cf2d2009-09-16 16:47:521852void RenderView::focusNext() {
1853 Send(new ViewHostMsg_TakeFocus(routing_id_, false));
1854}
1855
1856void RenderView::focusPrevious() {
1857 Send(new ViewHostMsg_TakeFocus(routing_id_, true));
1858}
1859
1860void RenderView::navigateBackForwardSoon(int offset) {
1861 history_back_list_count_ += offset;
1862 history_forward_list_count_ -= offset;
1863
1864 Send(new ViewHostMsg_GoToEntryAtOffset(routing_id_, offset));
1865}
1866
1867int RenderView::historyBackListCount() {
1868 return history_back_list_count_;
1869}
1870
1871int RenderView::historyForwardListCount() {
1872 return history_forward_list_count_;
1873}
1874
1875void RenderView::didAddHistoryItem() {
1876 // We don't want to update the history length for the start page
1877 // navigation.
[email protected]26aa0482009-09-30 16:55:271878 WebFrame* main_frame = webview()->mainFrame();
[email protected]48c9cf2d2009-09-16 16:47:521879 DCHECK(main_frame != NULL);
1880
1881 WebDataSource* ds = main_frame->dataSource();
1882 DCHECK(ds != NULL);
1883
1884 NavigationState* navigation_state = NavigationState::FromDataSource(ds);
1885 DCHECK(navigation_state);
1886 if (navigation_state->transition_type() == PageTransition::START_PAGE)
1887 return;
1888
1889 history_back_list_count_++;
1890 history_forward_list_count_ = 0;
1891}
1892
[email protected]8922e1f2009-10-03 05:01:261893void RenderView::didUpdateInspectorSettings() {
1894 Send(new ViewHostMsg_UpdateInspectorSettings(
1895 routing_id_, webview()->inspectorSettings().utf8()));
1896}
1897
[email protected]acca2a1f2009-10-16 03:53:391898void RenderView::queryAutofillSuggestions(const WebNode& node,
1899 const WebString& name,
1900 const WebString& value) {
1901 static int query_counter = 0;
1902 autofill_query_id_ = query_counter++;
1903 autofill_query_node_ = node;
1904 Send(new ViewHostMsg_QueryFormFieldAutofill(
1905 routing_id_, autofill_query_id_, name, value));
1906}
1907
1908void RenderView::removeAutofillSuggestions(const WebString& name,
1909 const WebString& value) {
1910 Send(new ViewHostMsg_RemoveAutofillEntry(routing_id_, name, value));
1911}
1912
[email protected]79dbc662009-09-04 05:42:511913// WebKit::WebWidgetClient ----------------------------------------------------
1914
initial.commit09911bf2008-07-26 23:55:291915// We are supposed to get a single call to Show for a newly created RenderView
1916// that was created via RenderView::CreateWebView. So, we wait until this
1917// point to dispatch the ShowView message.
1918//
1919// This method provides us with the information about how to display the newly
1920// created RenderView (i.e., as a constrained popup or as a new tab).
1921//
[email protected]4873c7d2009-07-16 06:36:281922void RenderView::show(WebNavigationPolicy policy) {
initial.commit09911bf2008-07-26 23:55:291923 DCHECK(!did_show_) << "received extraneous Show call";
1924 DCHECK(opener_id_ != MSG_ROUTING_NONE);
1925
1926 if (did_show_)
1927 return;
1928 did_show_ = true;
1929
[email protected]28295ec2009-10-16 05:34:331930 // Force new windows to a popup if they were not opened with a user gesture.
1931 if (!opened_by_user_gesture_) {
1932 // We exempt background tabs for compat with older versions of Chrome.
1933 // TODO(darin): This seems bogus. These should have a user gesture, so
1934 // we probably don't need this check.
1935 if (policy != WebKit::WebNavigationPolicyNewBackgroundTab)
1936 policy = WebKit::WebNavigationPolicyNewPopup;
1937 }
1938
initial.commit09911bf2008-07-26 23:55:291939 // NOTE: initial_pos_ may still have its default values at this point, but
1940 // that's okay. It'll be ignored if disposition is not NEW_POPUP, or the
1941 // browser process will impose a default position otherwise.
[email protected]4873c7d2009-07-16 06:36:281942 Send(new ViewHostMsg_ShowView(opener_id_, routing_id_,
1943 NavigationPolicyToDisposition(policy), initial_pos_,
[email protected]7e7414ae2010-01-26 20:19:291944 opened_by_user_gesture_));
[email protected]2533ce12009-05-09 00:02:241945 SetPendingWindowRect(initial_pos_);
initial.commit09911bf2008-07-26 23:55:291946}
1947
[email protected]4873c7d2009-07-16 06:36:281948void RenderView::closeWidgetSoon() {
[email protected]2c4410d2009-05-06 23:46:221949 if (!popup_notification_visible_)
[email protected]4873c7d2009-07-16 06:36:281950 RenderWidget::closeWidgetSoon();
[email protected]634a6f92008-12-01 21:39:311951}
1952
[email protected]4873c7d2009-07-16 06:36:281953void RenderView::runModal() {
initial.commit09911bf2008-07-26 23:55:291954 DCHECK(did_show_) << "should already have shown the view";
1955
[email protected]12636df2009-09-28 22:32:211956 SendAndRunNestedMessageLoop(new ViewHostMsg_RunModal(routing_id_));
initial.commit09911bf2008-07-26 23:55:291957}
1958
[email protected]3d9689372009-09-10 04:29:171959// WebKit::WebFrameClient -----------------------------------------------------
1960
1961WebPlugin* RenderView::createPlugin(
1962 WebFrame* frame, const WebPluginParams& params) {
1963 return new webkit_glue::WebPluginImpl(frame, params, AsWeakPtr());
1964}
1965
1966WebWorker* RenderView::createWorker(WebFrame* frame, WebWorkerClient* client) {
1967 return new WebWorkerProxy(client, RenderThread::current(), routing_id_);
1968}
1969
[email protected]9c00f002009-11-05 22:37:421970WebSharedWorker* RenderView::createSharedWorker(
1971 WebFrame* frame, const WebURL& url, const WebString& name,
[email protected]30447b62009-11-13 01:13:371972 unsigned long long document_id) {
[email protected]9c00f002009-11-05 22:37:421973
[email protected]30447b62009-11-13 01:13:371974 int route_id = MSG_ROUTING_NONE;
1975 bool url_mismatch = false;
1976 Send(new ViewHostMsg_LookupSharedWorker(
[email protected]0791d3a2010-01-28 01:28:491977 url, name, document_id, routing_id_, &route_id, &url_mismatch));
[email protected]30447b62009-11-13 01:13:371978 if (url_mismatch) {
1979 return NULL;
1980 } else {
1981 return new WebSharedWorkerProxy(RenderThread::current(),
[email protected]0791d3a2010-01-28 01:28:491982 document_id,
[email protected]30447b62009-11-13 01:13:371983 route_id,
1984 routing_id_);
1985 }
[email protected]9c00f002009-11-05 22:37:421986}
1987
[email protected]3d9689372009-09-10 04:29:171988WebMediaPlayer* RenderView::createMediaPlayer(
1989 WebFrame* frame, WebMediaPlayerClient* client) {
1990 scoped_refptr<media::FilterFactoryCollection> factory =
1991 new media::FilterFactoryCollection();
1992 // Add in any custom filter factories first.
1993 const CommandLine* cmd_line = CommandLine::ForCurrentProcess();
1994 if (!cmd_line->HasSwitch(switches::kDisableAudio)) {
1995 // Add the chrome specific audio renderer.
1996 factory->AddFactory(
1997 AudioRendererImpl::CreateFactory(audio_message_filter()));
1998 }
1999
[email protected]80f584d92010-01-21 03:59:042000 WebApplicationCacheHostImpl* appcache_host =
2001 WebApplicationCacheHostImpl::FromFrame(frame);
2002
[email protected]3d9689372009-09-10 04:29:172003 // TODO(hclam): obtain the following parameters from |client|.
2004 webkit_glue::MediaResourceLoaderBridgeFactory* bridge_factory =
2005 new webkit_glue::MediaResourceLoaderBridgeFactory(
[email protected]810a52ef2010-01-08 01:22:152006 GURL(), // referrer
2007 "null", // frame origin
2008 "null", // main_frame_origin
[email protected]3d9689372009-09-10 04:29:172009 base::GetCurrentProcId(),
[email protected]80f584d92010-01-21 03:59:042010 appcache_host ? appcache_host->host_id() : appcache::kNoHostId,
[email protected]3d9689372009-09-10 04:29:172011 routing_id());
2012
[email protected]0436b9a2009-10-23 00:23:052013 // A simple data source that keeps all data in memory.
2014 media::FilterFactory* simple_data_source_factory =
2015 webkit_glue::SimpleDataSource::CreateFactory(MessageLoop::current(),
2016 bridge_factory);
2017 // A sophisticated data source that does memory caching.
2018 media::FilterFactory* buffered_data_source_factory =
2019 webkit_glue::BufferedDataSource::CreateFactory(MessageLoop::current(),
2020 bridge_factory);
2021 if (cmd_line->HasSwitch(switches::kSimpleDataSource)) {
2022 factory->AddFactory(simple_data_source_factory);
2023 factory->AddFactory(buffered_data_source_factory);
[email protected]3d9689372009-09-10 04:29:172024 } else {
[email protected]0436b9a2009-10-23 00:23:052025 factory->AddFactory(buffered_data_source_factory);
2026 factory->AddFactory(simple_data_source_factory);
[email protected]3d9689372009-09-10 04:29:172027 }
2028 return new webkit_glue::WebMediaPlayerImpl(client, factory);
2029}
2030
2031void RenderView::willClose(WebFrame* frame) {
2032 if (!frame->parent()) {
2033 const GURL& url = frame->url();
2034 if (url.SchemeIs("http") || url.SchemeIs("https"))
2035 DumpLoadHistograms();
2036 }
[email protected]fa7b6b542009-11-03 05:02:302037
2038 WebDataSource* ds = frame->dataSource();
2039 NavigationState* navigation_state = NavigationState::FromDataSource(ds);
2040 navigation_state->user_script_idle_scheduler()->Cancel();
[email protected]3d9689372009-09-10 04:29:172041}
2042
[email protected]684e4a42010-01-30 06:44:112043bool RenderView::allowPlugins(WebFrame* frame, bool enabled_per_settings) {
[email protected]2d30a7a2010-02-04 01:57:502044 return AllowContentType(CONTENT_SETTINGS_TYPE_PLUGINS, enabled_per_settings);
[email protected]684e4a42010-01-30 06:44:112045}
2046
2047bool RenderView::allowImages(WebFrame* frame, bool enabled_per_settings) {
[email protected]2d30a7a2010-02-04 01:57:502048 return AllowContentType(CONTENT_SETTINGS_TYPE_IMAGES, enabled_per_settings);
[email protected]684e4a42010-01-30 06:44:112049}
2050
[email protected]3d9689372009-09-10 04:29:172051void RenderView::loadURLExternally(
2052 WebFrame* frame, const WebURLRequest& request,
2053 WebNavigationPolicy policy) {
[email protected]efce17b2009-09-11 18:04:592054 GURL referrer(request.httpHeaderField(WebString::fromUTF8("Referer")));
2055 if (policy == WebKit::WebNavigationPolicyDownload) {
2056 Send(new ViewHostMsg_DownloadUrl(routing_id_, request.url(), referrer));
2057 } else {
2058 OpenURL(request.url(), referrer, policy);
2059 }
[email protected]3d9689372009-09-10 04:29:172060}
2061
2062WebNavigationPolicy RenderView::decidePolicyForNavigation(
2063 WebFrame* frame, const WebURLRequest& request, WebNavigationType type,
[email protected]65b95cd2009-10-09 05:10:222064 const WebNode&, WebNavigationPolicy default_policy, bool is_redirect) {
[email protected]3d9689372009-09-10 04:29:172065 // Webkit is asking whether to navigate to a new URL.
2066 // This is fine normally, except if we're showing UI from one security
2067 // context and they're trying to navigate to a different context.
2068 const GURL& url = request.url();
2069
2070 // If the browser is interested, then give it a chance to look at top level
2071 // navigations
2072 if (renderer_preferences_.browser_handles_top_level_requests &&
2073 // Only send once.
2074 last_top_level_navigation_page_id_ != page_id_ &&
2075 // Not interested in reloads.
2076 type != WebKit::WebNavigationTypeReload &&
2077 type != WebKit::WebNavigationTypeFormSubmitted &&
2078 // Must be a top level frame.
2079 frame->parent() == NULL) {
2080 // Skip if navigation is on the same page (using '#').
2081 GURL frame_origin = GURL(frame->url()).GetOrigin();
2082 if (url.GetOrigin() != frame_origin || url.ref().empty()) {
2083 last_top_level_navigation_page_id_ = page_id_;
[email protected]b36a9f92009-10-19 17:34:572084 GURL referrer(request.httpHeaderField(WebString::fromUTF8("Referer")));
2085 OpenURL(url, referrer, default_policy);
[email protected]3d9689372009-09-10 04:29:172086 return WebKit::WebNavigationPolicyIgnore; // Suppress the load here.
2087 }
2088 }
2089
2090 // A content initiated navigation may have originated from a link-click,
2091 // script, drag-n-drop operation, etc.
2092 bool is_content_initiated =
2093 NavigationState::FromDataSource(frame->provisionalDataSource())->
2094 is_content_initiated();
2095
2096 // We only care about navigations that are within the current tab (as opposed
2097 // to, for example, opening a new window).
2098 // But we sometimes navigate to about:blank to clear a tab, and we want to
2099 // still allow that.
2100 if (default_policy == WebKit::WebNavigationPolicyCurrentTab &&
2101 is_content_initiated && frame->parent() == NULL &&
2102 !url.SchemeIs(chrome::kAboutScheme)) {
2103 // When we received such unsolicited navigations, we sometimes want to
2104 // punt them up to the browser to handle.
2105 if (BindingsPolicy::is_dom_ui_enabled(enabled_bindings_) ||
2106 BindingsPolicy::is_extension_enabled(enabled_bindings_) ||
2107 frame->isViewSourceModeEnabled() ||
2108 url.SchemeIs(chrome::kViewSourceScheme) ||
2109 url.SchemeIs(chrome::kPrintScheme)) {
2110 OpenURL(url, GURL(), default_policy);
2111 return WebKit::WebNavigationPolicyIgnore; // Suppress the load here.
2112 }
2113 }
2114
2115 // Detect when a page is "forking" a new tab that can be safely rendered in
2116 // its own process. This is done by sites like Gmail that try to open links
2117 // in new windows without script connections back to the original page. We
2118 // treat such cases as browser navigations (in which we will create a new
2119 // renderer for a cross-site navigation), rather than WebKit navigations.
2120 //
2121 // We use the following heuristic to decide whether to fork a new page in its
2122 // own process:
2123 // The parent page must open a new tab to about:blank, set the new tab's
2124 // window.opener to null, and then redirect the tab to a cross-site URL using
2125 // JavaScript.
[email protected]007a848b2009-10-26 15:55:462126 //
2127 // TODO(creis): Deprecate this logic once we can rely on rel=noreferrer
2128 // (see below).
[email protected]3d9689372009-09-10 04:29:172129 bool is_fork =
2130 // Must start from a tab showing about:blank, which is later redirected.
[email protected]e0d481582009-09-15 21:06:252131 GURL(frame->url()) == GURL(chrome::kAboutBlankURL) &&
[email protected]3d9689372009-09-10 04:29:172132 // Must be the first real navigation of the tab.
[email protected]48c9cf2d2009-09-16 16:47:522133 historyBackListCount() < 1 &&
2134 historyForwardListCount() < 1 &&
[email protected]3d9689372009-09-10 04:29:172135 // The parent page must have set the child's window.opener to null before
2136 // redirecting to the desired URL.
2137 frame->opener() == NULL &&
2138 // Must be a top-level frame.
2139 frame->parent() == NULL &&
2140 // Must not have issued the request from this page.
2141 is_content_initiated &&
2142 // Must be targeted at the current tab.
2143 default_policy == WebKit::WebNavigationPolicyCurrentTab &&
2144 // Must be a JavaScript navigation, which appears as "other".
2145 type == WebKit::WebNavigationTypeOther;
[email protected]007a848b2009-10-26 15:55:462146
2147 // Recognize if this navigation is from a link with rel=noreferrer and
2148 // target=_blank attributes, in which case the opener will be suppressed. If
2149 // so, it is safe to load cross-site pages in a separate process, so we
2150 // should let the browser handle it.
2151 bool is_noreferrer_and_blank_target =
2152 // Frame should be top level and not yet navigated.
2153 frame->parent() == NULL &&
2154 frame->url().isEmpty() &&
2155 historyBackListCount() < 1 &&
2156 historyForwardListCount() < 1 &&
2157 // Links with rel=noreferrer will have no Referer field, and their
2158 // resulting frame will have its window.opener suppressed.
2159 // TODO(creis): should add a request.httpReferrer() method to help avoid
2160 // typos on the unusual spelling of Referer.
2161 request.httpHeaderField(WebString::fromUTF8("Referer")).isNull() &&
2162 opener_suppressed_ &&
2163 frame->opener() == NULL &&
2164 // Links with target=_blank will have no name.
2165 frame->name().isNull() &&
2166 // Another frame (with a non-empty creator) should have initiated the
2167 // request, targeted at this frame.
2168 !creator_url_.is_empty() &&
2169 is_content_initiated &&
2170 default_policy == WebKit::WebNavigationPolicyCurrentTab &&
2171 type == WebKit::WebNavigationTypeOther;
2172
2173 if (is_fork || is_noreferrer_and_blank_target) {
[email protected]3d9689372009-09-10 04:29:172174 // Open the URL via the browser, not via WebKit.
2175 OpenURL(url, GURL(), default_policy);
2176 return WebKit::WebNavigationPolicyIgnore;
2177 }
2178
2179 return default_policy;
2180}
2181
[email protected]6069da8c2009-10-20 20:33:492182bool RenderView::canHandleRequest(
2183 WebFrame* frame, const WebURLRequest& request) {
2184 // We allow WebKit to think that everything can be handled even though
2185 // browser-side we limit what we load.
[email protected]7b7a7dc2009-10-19 02:23:342186 return true;
2187}
2188
[email protected]6069da8c2009-10-20 20:33:492189WebURLError RenderView::cannotHandleRequestError(
2190 WebFrame* frame, const WebURLRequest& request) {
2191 NOTREACHED(); // Since we said we can handle all requests.
2192 return WebURLError();
2193}
2194
2195WebURLError RenderView::cancelledError(
2196 WebFrame* frame, const WebURLRequest& request) {
2197 WebURLError error;
2198 error.domain = WebString::fromUTF8(net::kErrorDomain);
2199 error.reason = net::ERR_ABORTED;
2200 error.unreachableURL = request.url();
2201 return error;
[email protected]7b7a7dc2009-10-19 02:23:342202}
2203
2204void RenderView::unableToImplementPolicyWithError(
[email protected]6069da8c2009-10-20 20:33:492205 WebFrame*, const WebURLError&) {
2206 NOTREACHED(); // Since we said we can handle all requests.
[email protected]7b7a7dc2009-10-19 02:23:342207}
2208
[email protected]979c28b2009-11-07 01:30:482209void RenderView::willSubmitForm(WebFrame* frame, const WebFormElement& form) {
[email protected]3d9689372009-09-10 04:29:172210 NavigationState* navigation_state =
2211 NavigationState::FromDataSource(frame->provisionalDataSource());
2212
2213 if (navigation_state->transition_type() == PageTransition::LINK)
2214 navigation_state->set_transition_type(PageTransition::FORM_SUBMIT);
2215
2216 // Save these to be processed when the ensuing navigation is committed.
[email protected]ce0e250d2009-10-23 21:00:352217 WebSearchableFormData web_searchable_form_data(form);
2218 navigation_state->set_searchable_form_url(web_searchable_form_data.url());
2219 navigation_state->set_searchable_form_encoding(
[email protected]b7910b3a2010-01-13 18:33:212220 web_searchable_form_data.encoding().utf8());
[email protected]3d9689372009-09-10 04:29:172221 navigation_state->set_password_form_data(
2222 PasswordFormDomManager::CreatePasswordForm(form));
2223
[email protected]979c28b2009-11-07 01:30:482224 if (form.autoComplete()) {
[email protected]c54d269e2009-10-21 18:07:382225 scoped_ptr<FormFieldValues> form_values(FormFieldValues::Create(form));
2226 if (form_values.get())
[email protected]51bd36612009-10-20 22:49:472227 Send(new ViewHostMsg_FormFieldValuesSubmitted(routing_id_,
[email protected]c54d269e2009-10-21 18:07:382228 *form_values));
[email protected]3d9689372009-09-10 04:29:172229 }
2230}
2231
2232void RenderView::willPerformClientRedirect(
2233 WebFrame* frame, const WebURL& from, const WebURL& to, double interval,
2234 double fire_time) {
2235 // Ignore
2236}
2237
2238void RenderView::didCancelClientRedirect(WebFrame* frame) {
2239 // Ignore
2240}
2241
2242void RenderView::didCompleteClientRedirect(
2243 WebFrame* frame, const WebURL& from) {
2244 if (!frame->parent())
2245 completed_client_redirect_src_ = from;
2246}
2247
2248void RenderView::didCreateDataSource(WebFrame* frame, WebDataSource* ds) {
2249 // The rest of RenderView assumes that a WebDataSource will always have a
2250 // non-null NavigationState.
[email protected]a7ccc4d2010-01-27 08:14:482251 bool content_initiated = !pending_navigation_state_.get();
2252 NavigationState* state = content_initiated ?
2253 NavigationState::CreateContentInitiated() :
2254 pending_navigation_state_.release();
[email protected]4c1b6f0b2010-02-07 16:38:182255 if (content_initiated) {
2256 switch (ds->request().cachePolicy()) {
2257 case WebURLRequest::UseProtocolCachePolicy: // normal load.
2258 state->set_load_type(NavigationState::LINK_LOAD_NORMAL);
2259 break;
2260 case WebURLRequest::ReloadIgnoringCacheData: // reload.
2261 state->set_load_type(NavigationState::LINK_LOAD_RELOAD);
2262 break;
2263 case WebURLRequest::ReturnCacheDataElseLoad: // allow stale data.
2264 state->set_load_type(NavigationState::LINK_LOAD_CACHE_STALE_OK);
2265 break;
2266 case WebURLRequest::ReturnCacheDataDontLoad: // Don't re-post.
2267 state->set_load_type(NavigationState::LINK_LOAD_CACHE_ONLY);
2268 break;
2269 }
2270 }
[email protected]fa7b6b542009-11-03 05:02:302271
2272 state->set_user_script_idle_scheduler(
2273 new UserScriptIdleScheduler(this, frame));
2274 ds->setExtraData(state);
[email protected]3d9689372009-09-10 04:29:172275}
2276
2277void RenderView::didStartProvisionalLoad(WebFrame* frame) {
2278 WebDataSource* ds = frame->provisionalDataSource();
2279 NavigationState* navigation_state = NavigationState::FromDataSource(ds);
2280
2281 navigation_state->set_start_load_time(Time::Now());
2282
2283 // Update the request time if WebKit has better knowledge of it.
2284 if (navigation_state->request_time().is_null()) {
2285 double event_time = ds->triggeringEventTime();
2286 if (event_time != 0.0)
2287 navigation_state->set_request_time(Time::FromDoubleT(event_time));
2288 }
2289
2290 bool is_top_most = !frame->parent();
2291 if (is_top_most) {
2292 navigation_gesture_ = frame->isProcessingUserGesture() ?
2293 NavigationGestureUnknown : NavigationGestureAuto;
2294
2295 // Make sure redirect tracking state is clear for the new load.
2296 completed_client_redirect_src_ = GURL();
2297 } else if (frame->parent()->isLoading()) {
2298 // Take note of AUTO_SUBFRAME loads here, so that we can know how to
[email protected]4fb66842009-12-04 21:41:002299 // load an error page. See didFailProvisionalLoad.
[email protected]3d9689372009-09-10 04:29:172300 navigation_state->set_transition_type(PageTransition::AUTO_SUBFRAME);
2301 }
2302
2303 Send(new ViewHostMsg_DidStartProvisionalLoadForFrame(
2304 routing_id_, is_top_most, ds->request().url()));
2305}
2306
2307void RenderView::didReceiveServerRedirectForProvisionalLoad(WebFrame* frame) {
2308 if (frame->parent())
2309 return;
2310 // Received a redirect on the main frame.
2311 WebDataSource* data_source = frame->provisionalDataSource();
2312 if (!data_source) {
2313 // Should only be invoked when we have a data source.
2314 NOTREACHED();
2315 return;
2316 }
2317 std::vector<GURL> redirects;
2318 GetRedirectChain(data_source, &redirects);
2319 if (redirects.size() >= 2) {
[email protected]40bd6582009-12-04 23:49:512320 Send(new ViewHostMsg_DidRedirectProvisionalLoad(routing_id_, page_id_,
2321 redirects[redirects.size() - 2], redirects.back()));
[email protected]3d9689372009-09-10 04:29:172322 }
2323}
2324
[email protected]40bd6582009-12-04 23:49:512325void RenderView::didFailProvisionalLoad(WebFrame* frame,
2326 const WebURLError& error) {
[email protected]3d9689372009-09-10 04:29:172327 // Notify the browser that we failed a provisional load with an error.
2328 //
2329 // Note: It is important this notification occur before DidStopLoading so the
2330 // SSL manager can react to the provisional load failure before being
2331 // notified the load stopped.
2332 //
2333 WebDataSource* ds = frame->provisionalDataSource();
2334 DCHECK(ds);
2335
2336 const WebURLRequest& failed_request = ds->request();
2337
2338 bool show_repost_interstitial =
2339 (error.reason == net::ERR_CACHE_MISS &&
2340 EqualsASCII(failed_request.httpMethod(), "POST"));
2341 Send(new ViewHostMsg_DidFailProvisionalLoadWithError(
2342 routing_id_, !frame->parent(), error.reason, error.unreachableURL,
2343 show_repost_interstitial));
2344
2345 // Don't display an error page if this is simply a cancelled load. Aside
2346 // from being dumb, WebCore doesn't expect it and it will cause a crash.
2347 if (error.reason == net::ERR_ABORTED)
2348 return;
2349
2350 // Make sure we never show errors in view source mode.
2351 frame->enableViewSourceMode(false);
2352
2353 NavigationState* navigation_state = NavigationState::FromDataSource(ds);
2354
2355 // If this is a failed back/forward/reload navigation, then we need to do a
2356 // 'replace' load. This is necessary to avoid messing up session history.
2357 // Otherwise, we do a normal load, which simulates a 'go' navigation as far
2358 // as session history is concerned.
2359 //
2360 // AUTO_SUBFRAME loads should always be treated as loads that do not advance
2361 // the page id.
2362 //
2363 bool replace =
2364 navigation_state->pending_page_id() != -1 ||
2365 navigation_state->transition_type() == PageTransition::AUTO_SUBFRAME;
2366
2367 // If we failed on a browser initiated request, then make sure that our error
2368 // page load is regarded as the same browser initiated request.
2369 if (!navigation_state->is_content_initiated()) {
2370 pending_navigation_state_.reset(NavigationState::CreateBrowserInitiated(
2371 navigation_state->pending_page_id(),
2372 navigation_state->transition_type(),
2373 navigation_state->request_time()));
2374 }
2375
2376 // Provide the user with a more helpful error page?
2377 if (MaybeLoadAlternateErrorPage(frame, error, replace))
2378 return;
2379
2380 // Fallback to a local error page.
2381 LoadNavigationErrorPage(frame, failed_request, error, std::string(),
2382 replace);
2383}
2384
2385void RenderView::didReceiveDocumentData(
2386 WebFrame* frame, const char* data, size_t data_len,
2387 bool& prevent_default) {
2388 NavigationState* navigation_state =
2389 NavigationState::FromDataSource(frame->dataSource());
2390 if (!navigation_state->postpone_loading_data())
2391 return;
2392
2393 // We're going to call commitDocumentData ourselves...
2394 prevent_default = true;
2395
2396 // Continue buffering the response data for the original 404 page. If it
2397 // grows too large, then we'll just let it through.
2398 navigation_state->append_postponed_data(data, data_len);
2399 if (navigation_state->postponed_data().size() >= 512) {
2400 navigation_state->set_postpone_loading_data(false);
2401 frame->commitDocumentData(navigation_state->postponed_data().data(),
2402 navigation_state->postponed_data().size());
2403 navigation_state->clear_postponed_data();
2404 }
2405}
2406
[email protected]40bd6582009-12-04 23:49:512407void RenderView::didCommitProvisionalLoad(WebFrame* frame,
2408 bool is_new_navigation) {
[email protected]3d9689372009-09-10 04:29:172409 NavigationState* navigation_state =
2410 NavigationState::FromDataSource(frame->dataSource());
2411
2412 navigation_state->set_commit_load_time(Time::Now());
2413 if (is_new_navigation) {
2414 // When we perform a new navigation, we need to update the previous session
2415 // history entry with state for the page we are leaving.
2416 UpdateSessionHistory(frame);
2417
2418 // We bump our Page ID to correspond with the new session history entry.
2419 page_id_ = next_page_id_++;
2420
2421 MessageLoop::current()->PostDelayedTask(FROM_HERE,
2422 method_factory_.NewRunnableMethod(&RenderView::CapturePageInfo,
2423 page_id_, true),
2424 kDelayForForcedCaptureMs);
2425 } else {
2426 // Inspect the navigation_state on this frame to see if the navigation
2427 // corresponds to a session history navigation... Note: |frame| may or
2428 // may not be the toplevel frame, but for the case of capturing session
2429 // history, the first committed frame suffices. We keep track of whether
2430 // we've seen this commit before so that only capture session history once
2431 // per navigation.
2432 //
2433 // Note that we need to check if the page ID changed. In the case of a
2434 // reload, the page ID doesn't change, and UpdateSessionHistory gets the
2435 // previous URL and the current page ID, which would be wrong.
2436 if (navigation_state->pending_page_id() != -1 &&
2437 navigation_state->pending_page_id() != page_id_ &&
2438 !navigation_state->request_committed()) {
2439 // This is a successful session history navigation!
2440 UpdateSessionHistory(frame);
2441 page_id_ = navigation_state->pending_page_id();
2442 }
2443 }
2444
2445 // Remember that we've already processed this request, so we don't update
2446 // the session history again. We do this regardless of whether this is
2447 // a session history navigation, because if we attempted a session history
2448 // navigation without valid HistoryItem state, WebCore will think it is a
2449 // new navigation.
2450 navigation_state->set_request_committed(true);
2451
2452 UpdateURL(frame);
2453
2454 // If this committed load was initiated by a client redirect, we're
2455 // at the last stop now, so clear it.
2456 completed_client_redirect_src_ = GURL();
2457
2458 // Check whether we have new encoding name.
[email protected]26aa0482009-09-30 16:55:272459 UpdateEncoding(frame, frame->view()->pageEncoding().utf8());
[email protected]3d9689372009-09-10 04:29:172460}
2461
2462void RenderView::didClearWindowObject(WebFrame* frame) {
2463 if (BindingsPolicy::is_dom_automation_enabled(enabled_bindings_))
2464 BindDOMAutomationController(frame);
2465 if (BindingsPolicy::is_dom_ui_enabled(enabled_bindings_)) {
2466 dom_ui_bindings_.set_message_sender(this);
2467 dom_ui_bindings_.set_routing_id(routing_id_);
2468 dom_ui_bindings_.BindToJavascript(frame, L"chrome");
2469 }
2470 if (BindingsPolicy::is_external_host_enabled(enabled_bindings_)) {
2471 external_host_bindings_.set_message_sender(this);
2472 external_host_bindings_.set_routing_id(routing_id_);
2473 external_host_bindings_.BindToJavascript(frame, L"externalHost");
2474 }
2475}
2476
2477void RenderView::didCreateDocumentElement(WebFrame* frame) {
2478 if (RenderThread::current()) { // Will be NULL during unit tests.
2479 RenderThread::current()->user_script_slave()->InjectScripts(
2480 frame, UserScript::DOCUMENT_START);
2481 }
[email protected]078b34612009-09-19 19:31:512482 if (view_type_ == ViewType::EXTENSION_TOOLSTRIP ||
2483 view_type_ == ViewType::EXTENSION_MOLE) {
2484 InjectToolstripCSS();
2485 ExtensionProcessBindings::SetViewType(webview(), view_type_);
2486 }
[email protected]3d9689372009-09-10 04:29:172487
2488 // Notify the browser about non-blank documents loading in the top frame.
2489 GURL url = frame->url();
[email protected]e0d481582009-09-15 21:06:252490 if (url.is_valid() && url.spec() != chrome::kAboutBlankURL) {
[email protected]26aa0482009-09-30 16:55:272491 if (frame == webview()->mainFrame())
[email protected]3d9689372009-09-10 04:29:172492 Send(new ViewHostMsg_DocumentAvailableInMainFrame(routing_id_));
2493 }
2494}
2495
2496void RenderView::didReceiveTitle(WebFrame* frame, const WebString& title) {
2497 UpdateTitle(frame, title);
2498
2499 // Also check whether we have new encoding name.
[email protected]26aa0482009-09-30 16:55:272500 UpdateEncoding(frame, frame->view()->pageEncoding().utf8());
[email protected]3d9689372009-09-10 04:29:172501}
2502
2503void RenderView::didFinishDocumentLoad(WebFrame* frame) {
2504 WebDataSource* ds = frame->dataSource();
2505 NavigationState* navigation_state = NavigationState::FromDataSource(ds);
2506 DCHECK(navigation_state);
2507 navigation_state->set_finish_document_load_time(Time::Now());
2508
2509 Send(new ViewHostMsg_DocumentLoadedInFrame(routing_id_));
2510
2511 // The document has now been fully loaded. Scan for password forms to be
2512 // sent up to the browser.
2513 SendPasswordForms(frame);
2514
2515 // Check whether we have new encoding name.
[email protected]26aa0482009-09-30 16:55:272516 UpdateEncoding(frame, frame->view()->pageEncoding().utf8());
[email protected]3d9689372009-09-10 04:29:172517
2518 if (RenderThread::current()) { // Will be NULL during unit tests.
2519 RenderThread::current()->user_script_slave()->InjectScripts(
2520 frame, UserScript::DOCUMENT_END);
2521 }
[email protected]fa7b6b542009-11-03 05:02:302522
2523 navigation_state->user_script_idle_scheduler()->DidFinishDocumentLoad();
2524}
2525
2526void RenderView::OnUserScriptIdleTriggered(WebFrame* frame) {
2527 if (RenderThread::current()) { // Will be NULL during unit tests.
2528 RenderThread::current()->user_script_slave()->InjectScripts(
2529 frame, UserScript::DOCUMENT_IDLE);
2530 }
2531
2532 WebFrame* main_frame = webview()->mainFrame();
2533 if (frame == main_frame) {
2534 while (!pending_code_execution_queue_.empty()) {
[email protected]61f5a7b2009-12-22 22:21:202535 linked_ptr<ViewMsg_ExecuteCode_Params>& params =
[email protected]fa7b6b542009-11-03 05:02:302536 pending_code_execution_queue_.front();
[email protected]61f5a7b2009-12-22 22:21:202537 ExecuteCodeImpl(main_frame, *params);
[email protected]fa7b6b542009-11-03 05:02:302538 pending_code_execution_queue_.pop();
2539 }
2540 }
[email protected]3d9689372009-09-10 04:29:172541}
2542
2543void RenderView::didHandleOnloadEvents(WebFrame* frame) {
2544 // Ignore
2545}
2546
2547void RenderView::didFailLoad(WebFrame* frame, const WebURLError& error) {
2548 // Ignore
2549}
2550
2551void RenderView::didFinishLoad(WebFrame* frame) {
2552 WebDataSource* ds = frame->dataSource();
2553 NavigationState* navigation_state = NavigationState::FromDataSource(ds);
2554 DCHECK(navigation_state);
2555 navigation_state->set_finish_load_time(Time::Now());
[email protected]fa7b6b542009-11-03 05:02:302556 navigation_state->user_script_idle_scheduler()->DidFinishLoad();
[email protected]3d9689372009-09-10 04:29:172557}
2558
2559void RenderView::didChangeLocationWithinPage(
2560 WebFrame* frame, bool is_new_navigation) {
2561 // If this was a reference fragment navigation that we initiated, then we
2562 // could end up having a non-null pending navigation state. We just need to
2563 // update the ExtraData on the datasource so that others who read the
2564 // ExtraData will get the new NavigationState. Similarly, if we did not
2565 // initiate this navigation, then we need to take care to reset any pre-
2566 // existing navigation state to a content-initiated navigation state.
2567 // DidCreateDataSource conveniently takes care of this for us.
2568 didCreateDataSource(frame, frame->dataSource());
2569
2570 didCommitProvisionalLoad(frame, is_new_navigation);
2571
[email protected]26aa0482009-09-30 16:55:272572 UpdateTitle(frame, frame->view()->mainFrame()->dataSource()->pageTitle());
[email protected]b6ad7ba2010-02-08 18:44:552573
2574 NavigationState* navigation_state = NavigationState::FromDataSource(
2575 frame->dataSource());
2576 navigation_state->user_script_idle_scheduler()->DidChangeLocationWithinPage();
[email protected]3d9689372009-09-10 04:29:172577}
2578
[email protected]476b6f82009-09-10 21:00:592579void RenderView::didUpdateCurrentHistoryItem(WebFrame* frame) {
[email protected]882daa92009-11-05 16:31:312580 StartNavStateSyncTimerIfNecessary();
[email protected]476b6f82009-09-10 21:00:592581}
2582
[email protected]3d9689372009-09-10 04:29:172583void RenderView::assignIdentifierToRequest(
2584 WebFrame* frame, unsigned identifier, const WebURLRequest& request) {
2585 // Ignore
2586}
2587
2588void RenderView::willSendRequest(
2589 WebFrame* frame, unsigned identifier, WebURLRequest& request,
2590 const WebURLResponse& redirect_response) {
[email protected]5e369672009-11-03 23:48:302591 WebFrame* top_frame = frame->top();
2592 if (!top_frame)
2593 top_frame = frame;
2594 WebDataSource* data_source = top_frame->provisionalDataSource();
2595 if (!data_source)
2596 data_source = top_frame->dataSource();
2597 if (data_source) {
2598 NavigationState* state = NavigationState::FromDataSource(data_source);
2599 if (state && state->is_cache_policy_override_set())
2600 request.setCachePolicy(state->cache_policy_override());
2601 }
[email protected]3d9689372009-09-10 04:29:172602 request.setRequestorID(routing_id_);
2603}
2604
2605void RenderView::didReceiveResponse(
2606 WebFrame* frame, unsigned identifier, const WebURLResponse& response) {
[email protected]3d9689372009-09-10 04:29:172607 // Only do this for responses that correspond to a provisional data source
2608 // of the top-most frame. If we have a provisional data source, then we
2609 // can't have any sub-resources yet, so we know that this response must
2610 // correspond to a frame load.
2611 if (!frame->provisionalDataSource() || frame->parent())
2612 return;
2613
[email protected]0de80162010-02-03 04:52:352614 // A new page is about to be loaded. Clear "block" flags.
2615 ClearBlockedContentSettings();
[email protected]3d9689372009-09-10 04:29:172616 // If we are in view source mode, then just let the user see the source of
2617 // the server's 404 error page.
2618 if (frame->isViewSourceModeEnabled())
2619 return;
2620
[email protected]f48013be2010-01-14 22:07:452621 // Record that this was a page loaded over SPDY.
2622 if (response.wasFetchedViaSPDY()) {
2623 NavigationState* navigation_state =
2624 NavigationState::FromDataSource(frame->provisionalDataSource());
2625 navigation_state->set_was_fetched_via_spdy(true);
2626 }
2627
2628 // Consider loading an alternate error page for 404 responses.
2629 if (response.httpStatusCode() != 404)
2630 return;
2631
[email protected]3d9689372009-09-10 04:29:172632 // Can we even load an alternate error page for this URL?
2633 if (!GetAlternateErrorPageURL(response.url(), HTTP_404).is_valid())
2634 return;
2635
2636 NavigationState* navigation_state =
2637 NavigationState::FromDataSource(frame->provisionalDataSource());
2638 navigation_state->set_postpone_loading_data(true);
2639 navigation_state->clear_postponed_data();
2640}
2641
2642void RenderView::didFinishResourceLoad(
2643 WebFrame* frame, unsigned identifier) {
2644 NavigationState* navigation_state =
2645 NavigationState::FromDataSource(frame->dataSource());
2646 if (!navigation_state->postpone_loading_data())
2647 return;
2648
2649 // The server returned a 404 and the content was < 512 bytes (which we
2650 // suppressed). Go ahead and fetch the alternate page content.
2651
2652 const GURL& frame_url = frame->url();
2653
2654 const GURL& error_page_url = GetAlternateErrorPageURL(frame_url, HTTP_404);
2655 DCHECK(error_page_url.is_valid());
2656
2657 WebURLError original_error;
2658 original_error.unreachableURL = frame_url;
2659
2660 navigation_state->set_alt_error_page_fetcher(
2661 new AltErrorPageResourceFetcher(
2662 error_page_url, frame, original_error,
2663 NewCallback(this, &RenderView::AltErrorPageFinished)));
2664}
2665
2666void RenderView::didFailResourceLoad(
2667 WebFrame* frame, unsigned identifier, const WebURLError& error) {
2668 // Ignore
2669}
2670
2671void RenderView::didLoadResourceFromMemoryCache(
2672 WebFrame* frame, const WebURLRequest& request,
2673 const WebURLResponse& response) {
2674 // Let the browser know we loaded a resource from the memory cache. This
2675 // message is needed to display the correct SSL indicators.
2676 Send(new ViewHostMsg_DidLoadResourceFromMemoryCache(
2677 routing_id_,
2678 request.url(),
[email protected]91733b62009-09-18 06:21:092679 frame->securityOrigin().toString().utf8(),
2680 frame->top()->securityOrigin().toString().utf8(),
[email protected]3d9689372009-09-10 04:29:172681 response.securityInfo()));
2682}
2683
[email protected]6069da8c2009-10-20 20:33:492684void RenderView::didDisplayInsecureContent(WebFrame* frame) {
[email protected]e3d60e5d2009-09-25 21:08:292685 Send(new ViewHostMsg_DidDisplayInsecureContent(routing_id_));
2686}
2687
2688void RenderView::didRunInsecureContent(
2689 WebFrame* frame, const WebSecurityOrigin& origin) {
2690 Send(new ViewHostMsg_DidRunInsecureContent(
2691 routing_id_,
2692 origin.toString().utf8()));
2693}
2694
[email protected]7ea093ba2009-11-03 05:54:592695bool RenderView::allowScript(WebFrame* frame, bool enabled_per_settings) {
[email protected]684e4a42010-01-30 06:44:112696 if (enabled_per_settings) {
[email protected]2d30a7a2010-02-04 01:57:502697 return AllowContentType(CONTENT_SETTINGS_TYPE_JAVASCRIPT,
[email protected]0de80162010-02-03 04:52:352698 enabled_per_settings);
[email protected]684e4a42010-01-30 06:44:112699 }
[email protected]7ea093ba2009-11-03 05:54:592700
2701 WebSecurityOrigin origin = frame->securityOrigin();
2702 if (origin.isEmpty())
2703 return false; // Uninitialized document?
2704
2705 if (EqualsASCII(origin.protocol(), chrome::kChromeUIScheme))
2706 return true; // Browser UI elements should still work.
2707
2708 // If the scheme is ftp: or file:, an empty file name indicates a directory
2709 // listing, which requires JavaScript to function properly.
2710 GURL frame_url = frame->url();
2711 const char* kDirProtocols[] = { "ftp", "file" };
2712 for (size_t i = 0; i < arraysize(kDirProtocols); ++i) {
2713 if (EqualsASCII(origin.protocol(), kDirProtocols[i])) {
2714 return frame_url.SchemeIs(kDirProtocols[i]) &&
2715 frame_url.ExtractFileName().empty();
2716 }
2717 }
2718
2719 return false; // Other protocols fall through here.
2720}
2721
[email protected]3d9689372009-09-10 04:29:172722void RenderView::didExhaustMemoryAvailableForScript(WebFrame* frame) {
2723 Send(new ViewHostMsg_JSOutOfMemory(routing_id_));
2724}
2725
[email protected]0c882b282009-10-07 17:01:282726void RenderView::didCreateScriptContext(WebFrame* frame) {
2727 EventBindings::HandleContextCreated(frame, false);
2728}
2729
2730void RenderView::didDestroyScriptContext(WebFrame* frame) {
2731 EventBindings::HandleContextDestroyed(frame);
2732}
2733
2734void RenderView::didCreateIsolatedScriptContext(WebFrame* frame) {
2735 EventBindings::HandleContextCreated(frame, true);
2736}
2737
[email protected]3d9689372009-09-10 04:29:172738void RenderView::didChangeContentsSize(WebFrame* frame, const WebSize& size) {
[email protected]d8a179c2010-01-31 00:58:142739 CheckPreferredSize();
2740}
2741
2742void RenderView::CheckPreferredSize() {
[email protected]3d9689372009-09-10 04:29:172743 // We don't always want to send the change messages over IPC, only if we've
[email protected]ab32b16c2009-10-16 14:57:252744 // be put in that mode by getting a |ViewMsg_EnablePreferredSizeChangedMode|
[email protected]3d9689372009-09-10 04:29:172745 // message.
[email protected]ab32b16c2009-10-16 14:57:252746 if (send_preferred_size_changes_) {
[email protected]3d9689372009-09-10 04:29:172747 // WebCore likes to tell us things have changed even when they haven't, so
[email protected]ab32b16c2009-10-16 14:57:252748 // cache the width and height and only send the IPC message when we're sure
2749 // they're different.
[email protected]26aa0482009-09-30 16:55:272750 int width = webview()->mainFrame()->contentsPreferredWidth();
[email protected]440a52a2009-11-18 07:23:392751 int height = webview()->mainFrame()->documentElementScrollHeight();
[email protected]c27324b2009-11-19 22:44:292752
[email protected]ab32b16c2009-10-16 14:57:252753 if (width != preferred_size_.width() ||
[email protected]440a52a2009-11-18 07:23:392754 height != preferred_size_.height()) {
[email protected]ab32b16c2009-10-16 14:57:252755 preferred_size_.set_width(width);
[email protected]440a52a2009-11-18 07:23:392756 preferred_size_.set_height(height);
[email protected]ab32b16c2009-10-16 14:57:252757
[email protected]ab32b16c2009-10-16 14:57:252758 Send(new ViewHostMsg_DidContentsPreferredSizeChange(routing_id_,
2759 preferred_size_));
[email protected]3d9689372009-09-10 04:29:172760 }
2761 }
2762}
2763
[email protected]143dcd592009-11-06 21:33:492764void RenderView::didChangeScrollOffset(WebFrame* frame) {
2765 StartNavStateSyncTimerIfNecessary();
2766}
2767
[email protected]8922e1f2009-10-03 05:01:262768void RenderView::reportFindInPageMatchCount(int request_id, int count,
2769 bool final_update) {
2770 // If we have a message that has been queued up, then we should just replace
2771 // it. The ACK from the browser will make sure it gets sent when the browser
2772 // wants it.
2773 if (queued_find_reply_message_.get()) {
2774 IPC::Message* msg = new ViewHostMsg_Find_Reply(
2775 routing_id_,
2776 request_id,
2777 count,
2778 gfx::Rect(),
2779 -1, // Don't update active match ordinal.
2780 final_update);
2781 queued_find_reply_message_.reset(msg);
2782 } else {
2783 // Send the search result over to the browser process.
2784 Send(new ViewHostMsg_Find_Reply(
2785 routing_id_,
2786 request_id,
2787 count,
2788 gfx::Rect(),
2789 -1, // // Don't update active match ordinal.
2790 final_update));
2791 }
2792}
2793
2794void RenderView::reportFindInPageSelection(int request_id,
2795 int active_match_ordinal,
2796 const WebRect& selection_rect) {
2797 // Send the search result over to the browser process.
2798 Send(new ViewHostMsg_Find_Reply(routing_id_,
2799 request_id,
2800 -1,
2801 selection_rect,
2802 active_match_ordinal,
2803 false));
2804}
2805
[email protected]79dbc662009-09-04 05:42:512806// webkit_glue::WebPluginPageDelegate -----------------------------------------
2807
[email protected]f103ab72009-09-02 17:10:592808webkit_glue::WebPluginDelegate* RenderView::CreatePluginDelegate(
2809 const GURL& url,
2810 const std::string& mime_type,
[email protected]f103ab72009-09-02 17:10:592811 std::string* actual_mime_type) {
2812 if (!PluginChannelHost::IsListening())
2813 return NULL;
2814
2815 GURL policy_url;
[email protected]26aa0482009-09-30 16:55:272816 WebFrame* main_frame = webview()->mainFrame();
[email protected]f103ab72009-09-02 17:10:592817 if (main_frame)
2818 policy_url = main_frame->url();
2819
2820 FilePath path;
[email protected]610c0892009-09-08 19:46:182821 render_thread_->Send(new ViewHostMsg_GetPluginPath(
2822 url, policy_url, mime_type, &path, actual_mime_type));
[email protected]f103ab72009-09-02 17:10:592823 if (path.value().empty())
2824 return NULL;
2825
2826 const std::string* mime_type_to_use;
2827 if (!actual_mime_type->empty())
2828 mime_type_to_use = actual_mime_type;
2829 else
2830 mime_type_to_use = &mime_type;
2831
[email protected]d2139662009-12-10 03:21:142832 bool use_pepper_host = false;
2833 bool in_process_plugin = RenderProcess::current()->in_process_plugins();
2834 // Check for trusted Pepper plugins.
[email protected]26e8d5e2009-10-13 02:47:162835 const char kPepperPrefix[] = "pepper-";
2836 if (StartsWithASCII(*mime_type_to_use, kPepperPrefix, true)) {
[email protected]d2139662009-12-10 03:21:142837 if (CommandLine::ForCurrentProcess()->
2838 HasSwitch(switches::kInternalPepper)) {
2839 in_process_plugin = true;
2840 use_pepper_host = true;
2841 } else {
2842 // In process Pepper plugins must be explicitly enabled.
2843 return NULL;
2844 }
[email protected]26e8d5e2009-10-13 02:47:162845 }
[email protected]d2139662009-12-10 03:21:142846 // Check for Native Client modules.
[email protected]d032f492009-09-29 00:33:462847 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kInternalNaCl)) {
2848 if (mime_type == "application/x-nacl-srpc") {
2849 in_process_plugin = true;
[email protected]d2139662009-12-10 03:21:142850 use_pepper_host = true;
[email protected]d032f492009-09-29 00:33:462851 }
2852 }
2853 if (in_process_plugin) {
[email protected]d2139662009-12-10 03:21:142854 if (use_pepper_host) {
2855 return WebPluginDelegatePepper::Create(
[email protected]7477ea6f2009-12-22 23:28:152856 path,
2857 *mime_type_to_use,
[email protected]6876dff2010-01-15 19:38:092858 AsWeakPtr());
[email protected]d2139662009-12-10 03:21:142859 } else {
[email protected]6876dff2010-01-15 19:38:092860#if defined(OS_WIN) // In-proc plugins aren't supported on Linux or Mac.
[email protected]d2139662009-12-10 03:21:142861 return WebPluginDelegateImpl::Create(
2862 path, *mime_type_to_use, gfx::NativeViewFromId(host_window_));
[email protected]6876dff2010-01-15 19:38:092863#else
[email protected]596b2c42010-01-14 20:40:432864 NOTIMPLEMENTED();
2865 return NULL;
[email protected]7b6616f2010-01-14 18:07:552866#endif
[email protected]6876dff2010-01-15 19:38:092867 }
[email protected]f103ab72009-09-02 17:10:592868 }
2869
[email protected]610c0892009-09-08 19:46:182870 return new WebPluginDelegateProxy(*mime_type_to_use, AsWeakPtr());
[email protected]f103ab72009-09-02 17:10:592871}
2872
2873void RenderView::CreatedPluginWindow(gfx::PluginWindowHandle window) {
2874#if defined(OS_LINUX)
2875 RenderThread::current()->Send(new ViewHostMsg_CreatePluginContainer(
2876 routing_id(), window));
2877#endif
2878}
2879
2880void RenderView::WillDestroyPluginWindow(gfx::PluginWindowHandle window) {
2881#if defined(OS_LINUX)
2882 RenderThread::current()->Send(new ViewHostMsg_DestroyPluginContainer(
2883 routing_id(), window));
2884#endif
2885 CleanupWindowInPluginMoves(window);
2886}
2887
2888void RenderView::DidMovePlugin(const webkit_glue::WebPluginGeometry& move) {
2889 SchedulePluginMove(move);
2890}
2891
2892void RenderView::DidStartLoadingForPlugin() {
2893 // TODO(darin): Make is_loading_ be a counter!
[email protected]48c9cf2d2009-09-16 16:47:522894 didStartLoading();
[email protected]f103ab72009-09-02 17:10:592895}
2896
2897void RenderView::DidStopLoadingForPlugin() {
2898 // TODO(darin): Make is_loading_ be a counter!
[email protected]48c9cf2d2009-09-16 16:47:522899 didStopLoading();
[email protected]f103ab72009-09-02 17:10:592900}
2901
[email protected]7e0831b2010-02-01 08:45:152902void RenderView::PageTranslated(int page_id,
2903 const std::string& original_lang,
2904 const std::string& target_lang) {
2905 Send(new ViewHostMsg_PageTranslated(routing_id_, page_id_,
2906 original_lang, target_lang));
2907}
2908
[email protected]f103ab72009-09-02 17:10:592909void RenderView::ShowModalHTMLDialogForPlugin(
2910 const GURL& url,
2911 const gfx::Size& size,
2912 const std::string& json_arguments,
2913 std::string* json_retval) {
[email protected]12636df2009-09-28 22:32:212914 SendAndRunNestedMessageLoop(new ViewHostMsg_ShowModalHTMLDialog(
[email protected]f103ab72009-09-02 17:10:592915 routing_id_, url, size.width(), size.height(), json_arguments,
[email protected]12636df2009-09-28 22:32:212916 json_retval));
[email protected]f103ab72009-09-02 17:10:592917}
2918
initial.commit09911bf2008-07-26 23:55:292919void RenderView::SyncNavigationState() {
2920 if (!webview())
2921 return;
2922
[email protected]26aa0482009-09-30 16:55:272923 const WebHistoryItem& item = webview()->mainFrame()->currentHistoryItem();
[email protected]ca948a22009-06-25 19:36:172924 if (item.isNull())
initial.commit09911bf2008-07-26 23:55:292925 return;
[email protected]ca948a22009-06-25 19:36:172926
2927 Send(new ViewHostMsg_UpdateState(
2928 routing_id_, page_id_, webkit_glue::HistoryItemToString(item)));
initial.commit09911bf2008-07-26 23:55:292929}
2930
[email protected]b0950a72009-09-29 23:16:172931bool RenderView::DownloadImage(int id, const GURL& image_url, int image_size) {
2932 // Make sure webview was not shut down.
2933 if (!webview())
2934 return false;
2935 // Create an image resource fetcher and assign it with a call back object.
2936 image_fetchers_.insert(new ImageResourceFetcher(
[email protected]26aa0482009-09-30 16:55:272937 image_url, webview()->mainFrame(), id, image_size,
[email protected]b0950a72009-09-29 23:16:172938 NewCallback(this, &RenderView::DidDownloadImage)));
2939 return true;
2940}
2941
2942void RenderView::DidDownloadImage(ImageResourceFetcher* fetcher,
initial.commit09911bf2008-07-26 23:55:292943 const SkBitmap& image) {
[email protected]b0950a72009-09-29 23:16:172944 // Notify requester of image download status.
[email protected]51bd36612009-10-20 22:49:472945 Send(new ViewHostMsg_DidDownloadFavIcon(routing_id_,
2946 fetcher->id(),
2947 fetcher->image_url(),
2948 image.isNull(),
2949 image));
[email protected]b0950a72009-09-29 23:16:172950 // Dispose of the image fetcher.
2951 DCHECK(image_fetchers_.find(fetcher) != image_fetchers_.end());
2952 image_fetchers_.erase(fetcher);
2953 // We're in the callback from the ImageResourceFetcher, best to delay
2954 // deletion.
2955 MessageLoop::current()->DeleteSoon(FROM_HERE, fetcher);
initial.commit09911bf2008-07-26 23:55:292956}
2957
[email protected]bf5c2ff392009-07-08 16:24:332958void RenderView::OnDownloadFavIcon(int id,
2959 const GURL& image_url,
2960 int image_size) {
[email protected]f11ca0732009-04-11 00:09:342961 bool data_image_failed = false;
2962 if (image_url.SchemeIs("data")) {
2963 SkBitmap data_image = ImageFromDataUrl(image_url);
2964 data_image_failed = data_image.empty();
2965 if (!data_image_failed) {
[email protected]bf5c2ff392009-07-08 16:24:332966 Send(new ViewHostMsg_DidDownloadFavIcon(routing_id_, id, image_url, false,
2967 data_image));
[email protected]f11ca0732009-04-11 00:09:342968 }
2969 }
2970
[email protected]bf5c2ff392009-07-08 16:24:332971 if (data_image_failed ||
[email protected]b0950a72009-09-29 23:16:172972 !DownloadImage(id, image_url, image_size)) {
[email protected]bf5c2ff392009-07-08 16:24:332973 Send(new ViewHostMsg_DidDownloadFavIcon(routing_id_, id, image_url, true,
2974 SkBitmap()));
2975 }
initial.commit09911bf2008-07-26 23:55:292976}
2977
[email protected]f11ca0732009-04-11 00:09:342978SkBitmap RenderView::ImageFromDataUrl(const GURL& url) const {
2979 std::string mime_type, char_set, data;
2980 if (net::DataURL::Parse(url, &mime_type, &char_set, &data) && !data.empty()) {
2981 // Decode the favicon using WebKit's image decoder.
2982 webkit_glue::ImageDecoder decoder(gfx::Size(kFavIconSize, kFavIconSize));
2983 const unsigned char* src_data =
2984 reinterpret_cast<const unsigned char*>(&data[0]);
2985
2986 return decoder.Decode(src_data, data.size());
2987 }
2988 return SkBitmap();
2989}
2990
initial.commit09911bf2008-07-26 23:55:292991void RenderView::OnGetApplicationInfo(int page_id) {
2992 webkit_glue::WebApplicationInfo app_info;
2993 if (page_id == page_id_)
2994 webkit_glue::GetApplicationInfo(webview(), &app_info);
2995
2996 // Prune out any data URLs in the set of icons. The browser process expects
2997 // any icon with a data URL to have originated from a favicon. We don't want
2998 // to decode arbitrary data URLs in the browser process. See
2999 // http://b/issue?id=1162972
3000 for (size_t i = 0; i < app_info.icons.size(); ++i) {
[email protected]6de74452009-02-25 18:04:593001 if (app_info.icons[i].url.SchemeIs(chrome::kDataScheme)) {
initial.commit09911bf2008-07-26 23:55:293002 app_info.icons.erase(app_info.icons.begin() + i);
3003 --i;
3004 }
3005 }
3006
3007 Send(new ViewHostMsg_DidGetApplicationInfo(routing_id_, page_id, app_info));
3008}
3009
[email protected]7ccddb8c2009-08-04 17:36:553010GURL RenderView::GetAlternateErrorPageURL(const GURL& failed_url,
initial.commit09911bf2008-07-26 23:55:293011 ErrorPageType error_type) {
[email protected]7ccddb8c2009-08-04 17:36:553012 if (failed_url.SchemeIsSecure()) {
initial.commit09911bf2008-07-26 23:55:293013 // If the URL that failed was secure, then the embedding web page was not
3014 // expecting a network attacker to be able to manipulate its contents. As
3015 // we fetch alternate error pages over HTTP, we would be allowing a network
3016 // attacker to manipulate the contents of the response if we tried to use
3017 // the link doctor here.
[email protected]810a52ef2010-01-08 01:22:153018 return GURL();
initial.commit09911bf2008-07-26 23:55:293019 }
3020
3021 // Grab the base URL from the browser process.
3022 if (!alternate_error_page_url_.is_valid())
[email protected]810a52ef2010-01-08 01:22:153023 return GURL();
initial.commit09911bf2008-07-26 23:55:293024
3025 // Strip query params from the failed URL.
3026 GURL::Replacements remove_params;
3027 remove_params.ClearUsername();
3028 remove_params.ClearPassword();
3029 remove_params.ClearQuery();
3030 remove_params.ClearRef();
[email protected]7ccddb8c2009-08-04 17:36:553031 const GURL url_to_send = failed_url.ReplaceComponents(remove_params);
initial.commit09911bf2008-07-26 23:55:293032
3033 // Construct the query params to send to link doctor.
3034 std::string params(alternate_error_page_url_.query());
3035 params.append("&url=");
[email protected]0d2e6a62010-01-15 20:09:193036 params.append(EscapeQueryParamValue(url_to_send.spec(), true));
initial.commit09911bf2008-07-26 23:55:293037 params.append("&sourceid=chrome");
3038 params.append("&error=");
3039 switch (error_type) {
3040 case DNS_ERROR:
3041 params.append("dnserror");
3042 break;
3043
3044 case HTTP_404:
3045 params.append("http404");
3046 break;
3047
[email protected]5df266ac2008-10-15 19:50:133048 case CONNECTION_ERROR:
[email protected]e1f934b2009-01-26 20:41:333049 params.append("connectionfailure");
[email protected]5df266ac2008-10-15 19:50:133050 break;
3051
initial.commit09911bf2008-07-26 23:55:293052 default:
3053 NOTREACHED() << "unknown ErrorPageType";
3054 }
3055
3056 // OK, build the final url to return.
3057 GURL::Replacements link_doctor_params;
3058 link_doctor_params.SetQueryStr(params);
3059 GURL url = alternate_error_page_url_.ReplaceComponents(link_doctor_params);
3060 return url;
3061}
3062
[email protected]6069da8c2009-10-20 20:33:493063void RenderView::OnFind(int request_id, const string16& search_text,
3064 const WebFindOptions& options) {
[email protected]26aa0482009-09-30 16:55:273065 WebFrame* main_frame = webview()->mainFrame();
[email protected]b4bb2502009-10-01 22:35:273066 WebFrame* frame_after_main = main_frame->traverseNext(true);
[email protected]26aa0482009-09-30 16:55:273067 WebFrame* focused_frame = webview()->focusedFrame();
initial.commit09911bf2008-07-26 23:55:293068 WebFrame* search_frame = focused_frame; // start searching focused frame.
3069
3070 bool multi_frame = (frame_after_main != main_frame);
3071
3072 // If we have multiple frames, we don't want to wrap the search within the
3073 // frame, so we check here if we only have main_frame in the chain.
3074 bool wrap_within_frame = !multi_frame;
3075
[email protected]b3f2b912009-04-09 16:18:523076 WebRect selection_rect;
initial.commit09911bf2008-07-26 23:55:293077 bool result = false;
3078
[email protected]7830da3e2009-11-06 16:27:263079 // If something is selected when we start searching it means we cannot just
3080 // increment the current match ordinal; we need to re-generate it.
3081 WebRange current_selection = focused_frame->selectionRange();
3082
initial.commit09911bf2008-07-26 23:55:293083 do {
[email protected]dd7daa82009-08-10 05:46:453084 result = search_frame->find(
[email protected]7ea066a2009-04-06 20:21:593085 request_id, search_text, options, wrap_within_frame, &selection_rect);
initial.commit09911bf2008-07-26 23:55:293086
3087 if (!result) {
3088 // don't leave text selected as you move to the next frame.
[email protected]a100d76bb2009-08-14 17:50:223089 search_frame->executeCommand(WebString::fromUTF8("Unselect"));
initial.commit09911bf2008-07-26 23:55:293090
3091 // Find the next frame, but skip the invisible ones.
3092 do {
3093 // What is the next frame to search? (we might be going backwards). Note
3094 // that we specify wrap=true so that search_frame never becomes NULL.
[email protected]7ea066a2009-04-06 20:21:593095 search_frame = options.forward ?
[email protected]b4bb2502009-10-01 22:35:273096 search_frame->traverseNext(true) :
3097 search_frame->traversePrevious(true);
[email protected]dd7daa82009-08-10 05:46:453098 } while (!search_frame->hasVisibleContent() &&
3099 search_frame != focused_frame);
initial.commit09911bf2008-07-26 23:55:293100
[email protected]884db412008-11-24 23:46:503101 // Make sure selection doesn't affect the search operation in new frame.
[email protected]a100d76bb2009-08-14 17:50:223102 search_frame->executeCommand(WebString::fromUTF8("Unselect"));
initial.commit09911bf2008-07-26 23:55:293103
3104 // If we have multiple frames and we have wrapped back around to the
3105 // focused frame, we need to search it once more allowing wrap within
3106 // the frame, otherwise it will report 'no match' if the focused frame has
3107 // reported matches, but no frames after the focused_frame contain a
3108 // match for the search word(s).
3109 if (multi_frame && search_frame == focused_frame) {
[email protected]dd7daa82009-08-10 05:46:453110 result = search_frame->find(
[email protected]7ea066a2009-04-06 20:21:593111 request_id, search_text, options, true, // Force wrapping.
3112 &selection_rect);
initial.commit09911bf2008-07-26 23:55:293113 }
3114 }
3115
[email protected]26aa0482009-09-30 16:55:273116 webview()->setFocusedFrame(search_frame);
initial.commit09911bf2008-07-26 23:55:293117 } while (!result && search_frame != focused_frame);
3118
[email protected]7830da3e2009-11-06 16:27:263119 if (options.findNext && current_selection.isNull()) {
[email protected]4f3dc372009-02-24 00:10:293120 // Force the main_frame to report the actual count.
[email protected]dd7daa82009-08-10 05:46:453121 main_frame->increaseMatchCount(0, request_id);
[email protected]4f3dc372009-02-24 00:10:293122 } else {
3123 // If nothing is found, set result to "0 of 0", otherwise, set it to
3124 // "-1 of 1" to indicate that we found at least one item, but we don't know
3125 // yet what is active.
3126 int ordinal = result ? -1 : 0; // -1 here means, we might know more later.
3127 int match_count = result ? 1 : 0; // 1 here means possibly more coming.
initial.commit09911bf2008-07-26 23:55:293128
[email protected]4f3dc372009-02-24 00:10:293129 // If we find no matches then this will be our last status update.
3130 // Otherwise the scoping effort will send more results.
3131 bool final_status_update = !result;
initial.commit09911bf2008-07-26 23:55:293132
[email protected]4f3dc372009-02-24 00:10:293133 // Send the search result over to the browser process.
[email protected]4f999132009-03-31 18:08:403134 Send(new ViewHostMsg_Find_Reply(routing_id_,
[email protected]7ea066a2009-04-06 20:21:593135 request_id,
[email protected]4f3dc372009-02-24 00:10:293136 match_count,
3137 selection_rect,
3138 ordinal,
3139 final_status_update));
initial.commit09911bf2008-07-26 23:55:293140
initial.commit09911bf2008-07-26 23:55:293141 // Scoping effort begins, starting with the mainframe.
3142 search_frame = main_frame;
3143
[email protected]dd7daa82009-08-10 05:46:453144 main_frame->resetMatchCount();
initial.commit09911bf2008-07-26 23:55:293145
3146 do {
3147 // Cancel all old scoping requests before starting a new one.
[email protected]dd7daa82009-08-10 05:46:453148 search_frame->cancelPendingScopingEffort();
initial.commit09911bf2008-07-26 23:55:293149
3150 // We don't start another scoping effort unless at least one match has
3151 // been found.
3152 if (result) {
3153 // Start new scoping request. If the scoping function determines that it
3154 // needs to scope, it will defer until later.
[email protected]dd7daa82009-08-10 05:46:453155 search_frame->scopeStringMatches(request_id,
[email protected]7ea066a2009-04-06 20:21:593156 search_text,
3157 options,
initial.commit09911bf2008-07-26 23:55:293158 true); // reset the tickmarks
3159 }
3160
3161 // Iterate to the next frame. The frame will not necessarily scope, for
3162 // example if it is not visible.
[email protected]b4bb2502009-10-01 22:35:273163 search_frame = search_frame->traverseNext(true);
initial.commit09911bf2008-07-26 23:55:293164 } while (search_frame != main_frame);
3165 }
3166}
3167
[email protected]8c4cdd42010-01-12 21:31:133168std::string RenderView::DetectLanguage() {
3169 if (!webview() || is_loading_)
3170 return kUnknownLanguageCode;
3171
[email protected]8c4cdd42010-01-12 21:31:133172 WebFrame* main_frame = webview()->mainFrame();
3173 std::wstring contents;
3174 CaptureText(main_frame, &contents);
[email protected]8dc5a2052010-01-19 21:32:423175 return DetermineTextLanguage(contents);
[email protected]8c4cdd42010-01-12 21:31:133176}
3177
3178// static
3179std::string RenderView::DetermineTextLanguage(const std::wstring& text) {
3180 std::string language = kUnknownLanguageCode;
[email protected]8c4cdd42010-01-12 21:31:133181 int num_languages = 0;
3182 bool is_reliable = false;
[email protected]8dc5a2052010-01-19 21:32:423183 string16 input = WideToUTF16(text);
[email protected]8c4cdd42010-01-12 21:31:133184 Language cld_language =
[email protected]8dc5a2052010-01-19 21:32:423185 DetectLanguageOfUnicodeText(NULL, input.c_str(), true, &is_reliable,
[email protected]8c4cdd42010-01-12 21:31:133186 &num_languages, NULL);
3187 if (cld_language != NUM_LANGUAGES && cld_language != UNKNOWN_LANGUAGE &&
3188 cld_language != TG_UNKNOWN_LANGUAGE) {
[email protected]a7ccc4d2010-01-27 08:14:483189 // We should not use LanguageCode_ISO_639_1 because it does not cover all
3190 // the languages CLD can detect. As a result, it'll return the invalid
[email protected]8d022a92010-02-04 02:49:263191 // language code for tradtional Chinese among others.
3192 // |LanguageCodeWithDialect| will go through ISO 639-1, ISO-639-2 and
3193 // 'other' tables to do the 'right' thing. In addition, it'll return zh-CN
3194 // for Simplified Chinese.
3195 language = LanguageCodeWithDialects(cld_language);
[email protected]8c4cdd42010-01-12 21:31:133196 }
[email protected]8c4cdd42010-01-12 21:31:133197 return language;
[email protected]7893a982010-01-07 23:25:523198}
3199
[email protected]2d30a7a2010-02-04 01:57:503200bool RenderView::AllowContentType(ContentSettingsType settings_type,
[email protected]0de80162010-02-03 04:52:353201 bool enabled_per_settings) {
3202 if (!enabled_per_settings)
3203 return false;
3204 // CONTENT_SETTING_ASK is only valid for cookies.
[email protected]4c1b6f0b2010-02-07 16:38:183205 if (current_content_settings_.settings[settings_type] ==
3206 CONTENT_SETTING_BLOCK) {
[email protected]2d30a7a2010-02-04 01:57:503207 if (!content_blocked_[settings_type]) {
3208 content_blocked_[settings_type] = true;
3209 Send(new ViewHostMsg_ContentBlocked(routing_id_, settings_type));
3210 }
[email protected]0de80162010-02-03 04:52:353211 return false;
3212 }
3213 return true;
3214}
3215
3216void RenderView::ClearBlockedContentSettings() {
3217 DCHECK_EQ(static_cast<size_t>(CONTENT_SETTINGS_NUM_TYPES),
3218 arraysize(content_blocked_));
3219 for (int i = 0; i < CONTENT_SETTINGS_NUM_TYPES; ++i)
3220 content_blocked_[i] = false;
3221}
3222
initial.commit09911bf2008-07-26 23:55:293223void RenderView::DnsPrefetch(const std::vector<std::string>& host_names) {
3224 Send(new ViewHostMsg_DnsPrefetch(host_names));
3225}
3226
[email protected]40bd6582009-12-04 23:49:513227void RenderView::OnZoom(PageZoom::Function function) {
3228 if (!webview()) // Not sure if this can happen, but no harm in being safe.
3229 return;
3230
3231 int zoom_level = webview()->zoomLevel();
3232 int new_zoom_level = webview()->setZoomLevel(false,
3233 (function == PageZoom::RESET) ? 0 : (zoom_level + function));
3234
3235 // Tell the browser which host got zoomed so it can update the saved values.
3236 // Pages like the safe browsing interstitial can have empty hosts; don't
3237 // record those.
3238 std::string host(GURL(webview()->mainFrame()->url()).host());
3239 if (!host.empty())
3240 Send(new ViewHostMsg_DidZoomHost(host, new_zoom_level));
3241}
3242
[email protected]f85f0702010-01-30 09:31:013243void RenderView::OnSetContentSettingsForLoadingHost(
3244 std::string host,
3245 const ContentSettings& content_settings) {
3246 host_content_settings_[host] = content_settings;
3247}
3248
[email protected]40bd6582009-12-04 23:49:513249void RenderView::OnSetZoomLevelForLoadingHost(std::string host,
3250 int zoom_level) {
3251 host_zoom_levels_[host] = zoom_level;
initial.commit09911bf2008-07-26 23:55:293252}
3253
[email protected]41fc0322009-09-04 22:23:403254void RenderView::OnSetPageEncoding(const std::string& encoding_name) {
[email protected]26aa0482009-09-30 16:55:273255 webview()->setPageEncoding(WebString::fromUTF8(encoding_name));
initial.commit09911bf2008-07-26 23:55:293256}
3257
[email protected]a697f4c2009-09-14 22:30:183258void RenderView::OnResetPageEncodingToDefault() {
[email protected]26aa0482009-09-30 16:55:273259 WebString no_encoding;
3260 webview()->setPageEncoding(no_encoding);
[email protected]a697f4c2009-09-14 22:30:183261}
3262
[email protected]20ad2692009-11-20 18:27:203263bool RenderView::GetAllChildFrames(
3264 WebFrame* parent_frame,
3265 std::vector<WebFrame*>* frames_vector) const {
3266 if (!parent_frame)
3267 return false;
3268 for (WebFrame* child_frame = parent_frame->firstChild(); child_frame;
3269 child_frame = child_frame->nextSibling()) {
3270 frames_vector->push_back(child_frame);
3271 GetAllChildFrames(child_frame, frames_vector);
3272 }
3273 return true;
3274}
3275
[email protected]dd7daa82009-08-10 05:46:453276WebFrame* RenderView::GetChildFrame(const std::wstring& xpath) const {
3277 if (xpath.empty())
[email protected]26aa0482009-09-30 16:55:273278 return webview()->mainFrame();
[email protected]dd7daa82009-08-10 05:46:453279
3280 // xpath string can represent a frame deep down the tree (across multiple
3281 // frame DOMs).
3282 // Example, /html/body/table/tbody/tr/td/iframe\n/frameset/frame[0]
3283 // should break into 2 xpaths
3284 // /html/body/table/tbody/tr/td/iframe & /frameset/frame[0]
3285
[email protected]26aa0482009-09-30 16:55:273286 WebFrame* frame = webview()->mainFrame();
[email protected]dd7daa82009-08-10 05:46:453287
3288 std::wstring xpath_remaining = xpath;
3289 while (!xpath_remaining.empty()) {
3290 std::wstring::size_type delim_pos = xpath_remaining.find_first_of(L'\n');
3291 std::wstring xpath_child;
3292 if (delim_pos != std::wstring::npos) {
3293 xpath_child = xpath_remaining.substr(0, delim_pos);
3294 xpath_remaining.erase(0, delim_pos + 1);
3295 } else {
3296 xpath_remaining.swap(xpath_child);
3297 }
3298 frame = frame->findChildByExpression(WideToUTF16Hack(xpath_child));
initial.commit09911bf2008-07-26 23:55:293299 }
3300
[email protected]dd7daa82009-08-10 05:46:453301 return frame;
initial.commit09911bf2008-07-26 23:55:293302}
3303
[email protected]f29acf52008-11-03 20:08:333304void RenderView::EvaluateScript(const std::wstring& frame_xpath,
3305 const std::wstring& script) {
initial.commit09911bf2008-07-26 23:55:293306 WebFrame* web_frame = GetChildFrame(frame_xpath);
3307 if (!web_frame)
3308 return;
3309
[email protected]dd7daa82009-08-10 05:46:453310 web_frame->executeScript(WebScriptSource(WideToUTF16Hack(script)));
initial.commit09911bf2008-07-26 23:55:293311}
3312
[email protected]1810e132009-03-24 23:35:483313void RenderView::InsertCSS(const std::wstring& frame_xpath,
[email protected]ffaef0c2009-09-15 17:08:083314 const std::string& css,
3315 const std::string& id) {
[email protected]1810e132009-03-24 23:35:483316 WebFrame* web_frame = GetChildFrame(frame_xpath);
3317 if (!web_frame)
3318 return;
3319
[email protected]ffaef0c2009-09-15 17:08:083320 web_frame->insertStyleText(WebString::fromUTF8(css), WebString::fromUTF8(id));
[email protected]1810e132009-03-24 23:35:483321}
3322
initial.commit09911bf2008-07-26 23:55:293323void RenderView::OnScriptEvalRequest(const std::wstring& frame_xpath,
3324 const std::wstring& jscript) {
[email protected]f29acf52008-11-03 20:08:333325 EvaluateScript(frame_xpath, jscript);
initial.commit09911bf2008-07-26 23:55:293326}
3327
[email protected]1810e132009-03-24 23:35:483328void RenderView::OnCSSInsertRequest(const std::wstring& frame_xpath,
[email protected]ffaef0c2009-09-15 17:08:083329 const std::string& css,
3330 const std::string& id) {
3331 InsertCSS(frame_xpath, css, id);
[email protected]ae461542009-06-19 19:03:413332
3333 // Notify RenderViewHost that css has been inserted into the frame.
3334 Send(new ViewHostMsg_OnCSSInserted(routing_id_));
[email protected]1810e132009-03-24 23:35:483335}
3336
[email protected]7ea066a2009-04-06 20:21:593337void RenderView::OnAddMessageToConsole(
3338 const string16& frame_xpath,
3339 const string16& message,
3340 const WebConsoleMessage::Level& level) {
3341 WebFrame* web_frame = GetChildFrame(UTF16ToWideHack(frame_xpath));
[email protected]0dea3ea2009-03-31 23:30:593342 if (web_frame)
[email protected]dd7daa82009-08-10 05:46:453343 web_frame->addMessageToConsole(WebConsoleMessage(level, message));
initial.commit09911bf2008-07-26 23:55:293344}
3345
[email protected]81e63782009-02-27 19:35:093346void RenderView::OnAllowBindings(int enabled_bindings_flags) {
3347 enabled_bindings_ |= enabled_bindings_flags;
initial.commit09911bf2008-07-26 23:55:293348}
3349
3350void RenderView::OnSetDOMUIProperty(const std::string& name,
3351 const std::string& value) {
[email protected]81e63782009-02-27 19:35:093352 DCHECK(BindingsPolicy::is_dom_ui_enabled(enabled_bindings_));
initial.commit09911bf2008-07-26 23:55:293353 dom_ui_bindings_.SetProperty(name, value);
3354}
3355
3356void RenderView::OnReservePageIDRange(int size_of_range) {
3357 next_page_id_ += size_of_range + 1;
3358}
3359
[email protected]e80c73b2009-04-07 23:24:583360void RenderView::OnDragSourceEndedOrMoved(const gfx::Point& client_point,
3361 const gfx::Point& screen_point,
[email protected]1d9f4132009-09-08 17:29:253362 bool ended,
3363 WebDragOperation op) {
[email protected]5f9ae6c2009-07-08 02:38:033364 if (ended) {
[email protected]26aa0482009-09-30 16:55:273365 webview()->dragSourceEndedAt(client_point, screen_point, op);
[email protected]5f9ae6c2009-07-08 02:38:033366 }
initial.commit09911bf2008-07-26 23:55:293367}
3368
3369void RenderView::OnDragSourceSystemDragEnded() {
[email protected]26aa0482009-09-30 16:55:273370 webview()->dragSourceSystemDragEnded();
initial.commit09911bf2008-07-26 23:55:293371}
3372
initial.commit09911bf2008-07-26 23:55:293373void RenderView::OnFormFill(const FormData& form) {
3374 webkit_glue::FillForm(this->webview(), form);
3375}
3376
3377void RenderView::OnFillPasswordForm(
[email protected]daa8c58e2009-06-15 17:21:103378 const webkit_glue::PasswordFormDomManager::FillData& form_data) {
initial.commit09911bf2008-07-26 23:55:293379 webkit_glue::FillPasswordForm(this->webview(), form_data);
3380}
3381
3382void RenderView::OnDragTargetDragEnter(const WebDropData& drop_data,
[email protected]e80c73b2009-04-07 23:24:583383 const gfx::Point& client_point,
[email protected]1d9f4132009-09-08 17:29:253384 const gfx::Point& screen_point,
3385 WebDragOperationsMask ops) {
[email protected]26aa0482009-09-30 16:55:273386 WebDragOperation operation = webview()->dragTargetDragEnter(
[email protected]e80c73b2009-04-07 23:24:583387 drop_data.ToDragData(),
3388 drop_data.identity,
3389 client_point,
[email protected]1d9f4132009-09-08 17:29:253390 screen_point,
3391 ops);
initial.commit09911bf2008-07-26 23:55:293392
[email protected]1d9f4132009-09-08 17:29:253393 Send(new ViewHostMsg_UpdateDragCursor(routing_id_, operation));
initial.commit09911bf2008-07-26 23:55:293394}
3395
[email protected]e80c73b2009-04-07 23:24:583396void RenderView::OnDragTargetDragOver(const gfx::Point& client_point,
[email protected]1d9f4132009-09-08 17:29:253397 const gfx::Point& screen_point,
3398 WebDragOperationsMask ops) {
[email protected]26aa0482009-09-30 16:55:273399 WebDragOperation operation = webview()->dragTargetDragOver(
[email protected]1d9f4132009-09-08 17:29:253400 client_point,
3401 screen_point,
3402 ops);
initial.commit09911bf2008-07-26 23:55:293403
[email protected]1d9f4132009-09-08 17:29:253404 Send(new ViewHostMsg_UpdateDragCursor(routing_id_, operation));
initial.commit09911bf2008-07-26 23:55:293405}
3406
3407void RenderView::OnDragTargetDragLeave() {
[email protected]26aa0482009-09-30 16:55:273408 webview()->dragTargetDragLeave();
initial.commit09911bf2008-07-26 23:55:293409}
3410
[email protected]e80c73b2009-04-07 23:24:583411void RenderView::OnDragTargetDrop(const gfx::Point& client_point,
3412 const gfx::Point& screen_point) {
[email protected]26aa0482009-09-30 16:55:273413 webview()->dragTargetDrop(client_point, screen_point);
initial.commit09911bf2008-07-26 23:55:293414}
3415
3416void RenderView::OnUpdateWebPreferences(const WebPreferences& prefs) {
[email protected]2fab253a2009-08-17 23:00:593417 webkit_preferences_ = prefs;
3418 webkit_preferences_.Apply(webview());
initial.commit09911bf2008-07-26 23:55:293419}
3420
3421void RenderView::OnSetAltErrorPageURL(const GURL& url) {
3422 alternate_error_page_url_ = url;
3423}
3424
[email protected]a0c7153e2009-12-09 14:36:333425void RenderView::OnCustomContextMenuAction(unsigned action) {
3426 webview()->performCustomContextMenuAction(action);
3427}
3428
[email protected]d4a00a72010-01-29 01:44:423429void RenderView::OnTranslatePage(int page_id,
3430 const std::string& source_lang,
3431 const std::string& target_lang) {
3432 if (page_id != page_id_)
3433 return; // Not the page we expected, nothing to do.
3434
3435 WebFrame* main_frame = webview()->mainFrame();
3436 if (!main_frame)
3437 return;
[email protected]7e0831b2010-02-01 08:45:153438 page_translator_->Translate(page_id, main_frame, source_lang, target_lang);
[email protected]d4a00a72010-01-29 01:44:423439}
3440
[email protected]0bedb8a2010-01-14 19:36:323441void RenderView::OnTranslateTextResponse(
3442 int work_id, int error_id, const std::vector<string16>& text_chunks) {
[email protected]d4a00a72010-01-29 01:44:423443 text_translator_.OnTranslationResponse(work_id, error_id, text_chunks);
[email protected]0bedb8a2010-01-14 19:36:323444}
3445
initial.commit09911bf2008-07-26 23:55:293446void RenderView::OnInstallMissingPlugin() {
3447 // This could happen when the first default plugin is deleted.
[email protected]f103ab72009-09-02 17:10:593448 if (first_default_plugin_)
3449 first_default_plugin_->InstallMissingPlugin();
initial.commit09911bf2008-07-26 23:55:293450}
3451
[email protected]b62d1a8c2009-01-13 23:54:573452void RenderView::OnFileChooserResponse(
[email protected]561abe62009-04-06 18:08:343453 const std::vector<FilePath>& file_names) {
[email protected]8029f5672009-03-20 22:33:363454 // This could happen if we navigated to a different page before the user
3455 // closed the chooser.
[email protected]a1128322009-10-06 18:38:463456 if (!file_chooser_completion_)
[email protected]8029f5672009-03-20 22:33:363457 return;
3458
[email protected]6069da8c2009-10-20 20:33:493459 WebVector<WebString> ws_file_names(file_names.size());
[email protected]a1128322009-10-06 18:38:463460 for (size_t i = 0; i < file_names.size(); ++i) {
3461 ws_file_names[i] = webkit_glue::FilePathToWebString(file_names[i]);
3462 }
3463
3464 file_chooser_completion_->didChooseFile(ws_file_names);
3465 // Reset the chooser pointer
3466 file_chooser_completion_ = NULL;
initial.commit09911bf2008-07-26 23:55:293467}
3468
3469void RenderView::OnEnableViewSourceMode() {
3470 if (!webview())
3471 return;
[email protected]26aa0482009-09-30 16:55:273472 WebFrame* main_frame = webview()->mainFrame();
initial.commit09911bf2008-07-26 23:55:293473 if (!main_frame)
3474 return;
3475
[email protected]dd7daa82009-08-10 05:46:453476 main_frame->enableViewSourceMode(true);
initial.commit09911bf2008-07-26 23:55:293477}
3478
[email protected]ab32b16c2009-10-16 14:57:253479void RenderView::OnEnablePreferredSizeChangedMode() {
3480 send_preferred_size_changes_ = true;
[email protected]d8a179c2010-01-31 00:58:143481 if (CommandLine::ForCurrentProcess()->GetSwitchValueASCII(
3482 switches::kProcessType) == switches::kExtensionProcess) {
3483 preferred_size_change_timer_.Start(TimeDelta::FromMilliseconds(10), this,
3484 &RenderView::CheckPreferredSize);
3485 }
[email protected]0666aef2009-05-13 19:48:083486}
3487
[email protected]80d96fa2009-06-10 22:34:513488void RenderView::OnSetRendererPrefs(const RendererPreferences& renderer_prefs) {
3489 renderer_preferences_ = renderer_prefs;
[email protected]6e282c92009-07-24 01:19:373490 UpdateFontRenderingFromRendererPrefs();
[email protected]033970a2009-10-14 16:45:053491#if defined(OS_LINUX) && !defined(TOOLKIT_VIEWS)
[email protected]1c83eb42009-09-11 21:08:413492 WebColorName name = WebKit::WebColorWebkitFocusRingColor;
3493 WebKit::setNamedColors(&name, &renderer_prefs.focus_ring_color, 1);
[email protected]39cd64ed2010-02-05 02:18:463494 WebKit::setCaretBlinkInterval(renderer_prefs.caret_blink_interval);
[email protected]93623c5d2009-12-10 21:40:323495
[email protected]644d77e2010-01-27 01:03:103496 if (webview()) {
[email protected]93623c5d2009-12-10 21:40:323497 webview()->setScrollbarColors(
3498 renderer_prefs.thumb_inactive_color,
3499 renderer_prefs.thumb_active_color,
3500 renderer_prefs.track_color);
[email protected]644d77e2010-01-27 01:03:103501 webview()->setSelectionColors(
3502 renderer_prefs.active_selection_bg_color,
3503 renderer_prefs.active_selection_fg_color,
3504 renderer_prefs.inactive_selection_bg_color,
3505 renderer_prefs.inactive_selection_fg_color);
3506 }
[email protected]7a74e102009-09-03 00:16:563507#endif
[email protected]80d96fa2009-06-10 22:34:513508}
3509
[email protected]952cb702009-10-07 05:50:283510void RenderView::OnMediaPlayerActionAt(const gfx::Point& location,
3511 const WebMediaPlayerAction& action) {
3512 if (webview())
3513 webview()->performMediaPlayerAction(action, location);
[email protected]581b87eb2009-07-23 23:06:563514}
3515
[email protected]7b291f92009-08-14 05:43:533516void RenderView::OnNotifyRendererViewType(ViewType::Type type) {
[email protected]078b34612009-09-19 19:31:513517 // When this is first set, the bindings aren't fully loaded. We only need
3518 // to call through this API after the page has already been loaded. It's
3519 // also called in didCreateDocumentElement to bootstrap.
3520 if (view_type_ != ViewType::INVALID) {
3521 if (type == ViewType::EXTENSION_MOLE ||
3522 type == ViewType::EXTENSION_TOOLSTRIP) {
3523 ExtensionProcessBindings::SetViewType(webview(), type);
3524 }
3525 }
[email protected]7b291f92009-08-14 05:43:533526 view_type_ = type;
3527}
3528
3529void RenderView::OnUpdateBrowserWindowId(int window_id) {
3530 browser_window_id_ = window_id;
3531}
3532
initial.commit09911bf2008-07-26 23:55:293533void RenderView::OnUpdateBackForwardListCount(int back_list_count,
3534 int forward_list_count) {
3535 history_back_list_count_ = back_list_count;
3536 history_forward_list_count_ = forward_list_count;
3537}
3538
[email protected]266eb6f2008-09-30 23:56:503539void RenderView::OnGetAccessibilityInfo(
[email protected]6a983b42009-03-20 20:12:253540 const webkit_glue::WebAccessibility::InParams& in_params,
3541 webkit_glue::WebAccessibility::OutParams* out_params) {
[email protected]6c8afae52009-01-22 02:24:573542#if defined(OS_WIN)
[email protected]c7287a92009-11-04 20:06:153543 if (!accessibility_.get()) {
3544 // TODO(dglazkov): Once implemented for all ports, remove lazy
3545 // instantiation of accessibility_.
3546 accessibility_.reset(WebAccessibilityCache::create());
3547 accessibility_->initialize(webview());
[email protected]6a983b42009-03-20 20:12:253548 }
[email protected]266eb6f2008-09-30 23:56:503549
[email protected]c7287a92009-11-04 20:06:153550 webkit_glue::WebAccessibility::GetAccObjInfo(accessibility_.get(),
3551 in_params,
3552 out_params);
3553
[email protected]6c8afae52009-01-22 02:24:573554#else // defined(OS_WIN)
3555 // TODO(port): accessibility not yet implemented
3556 NOTIMPLEMENTED();
3557#endif
[email protected]266eb6f2008-09-30 23:56:503558}
3559
[email protected]6a983b42009-03-20 20:12:253560void RenderView::OnClearAccessibilityInfo(int acc_obj_id, bool clear_all) {
[email protected]6c8afae52009-01-22 02:24:573561#if defined(OS_WIN)
[email protected]c7287a92009-11-04 20:06:153562 if (!accessibility_.get()) {
[email protected]266eb6f2008-09-30 23:56:503563 // If accessibility is not activated, ignore clearing message.
3564 return;
3565 }
[email protected]e846d0d2009-05-20 00:53:063566
[email protected]c7287a92009-11-04 20:06:153567 if (clear_all) {
3568 accessibility_->clear();
[email protected]266eb6f2008-09-30 23:56:503569 return;
[email protected]c7287a92009-11-04 20:06:153570 }
3571
3572 accessibility_->remove(acc_obj_id);
[email protected]e846d0d2009-05-20 00:53:063573
[email protected]6c8afae52009-01-22 02:24:573574#else // defined(OS_WIN)
3575 // TODO(port): accessibility not yet implemented
3576 NOTIMPLEMENTED();
3577#endif
[email protected]266eb6f2008-09-30 23:56:503578}
3579
initial.commit09911bf2008-07-26 23:55:293580void RenderView::OnGetAllSavableResourceLinksForCurrentPage(
3581 const GURL& page_url) {
3582 // Prepare list to storage all savable resource links.
3583 std::vector<GURL> resources_list;
3584 std::vector<GURL> referrers_list;
3585 std::vector<GURL> frames_list;
3586 webkit_glue::SavableResourcesResult result(&resources_list,
3587 &referrers_list,
3588 &frames_list);
3589
[email protected]dbeb3952009-10-13 18:01:183590 if (!webkit_glue::GetAllSavableResourceLinksForCurrentPage(
3591 webview(),
3592 page_url,
3593 &result,
3594 chrome::kSavableSchemes)) {
initial.commit09911bf2008-07-26 23:55:293595 // If something is wrong when collecting all savable resource links,
3596 // send empty list to embedder(browser) to tell it failed.
3597 referrers_list.clear();
3598 resources_list.clear();
3599 frames_list.clear();
3600 }
3601
3602 // Send result of all savable resource links to embedder.
3603 Send(new ViewHostMsg_SendCurrentPageAllSavableResourceLinks(routing_id_,
3604 resources_list,
3605 referrers_list,
3606 frames_list));
3607}
3608
3609void RenderView::OnGetSerializedHtmlDataForCurrentPageWithLocalLinks(
[email protected]f6b48532009-02-12 01:56:323610 const std::vector<GURL>& links,
[email protected]fde6714d12009-02-18 22:39:313611 const std::vector<FilePath>& local_paths,
3612 const FilePath& local_directory_name) {
[email protected]d9ec5c0f2009-12-23 11:55:073613
3614 // Convert std::vector of GURLs to WebVector<WebURL>
3615 WebVector<WebURL> weburl_links(links);
3616
3617 // Convert std::vector of std::strings to WebVector<WebString>
3618 WebVector<WebString> webstring_paths(local_paths.size());
3619 for (size_t i = 0; i < local_paths.size(); i++)
3620 webstring_paths[i] = webkit_glue::FilePathToWebString(local_paths[i]);
3621
3622 WebPageSerializer::serialize(webview()->mainFrame(),
3623 true, this, weburl_links, webstring_paths,
3624 webkit_glue::FilePathToWebString(
3625 local_directory_name));
initial.commit09911bf2008-07-26 23:55:293626}
3627
[email protected]d9ec5c0f2009-12-23 11:55:073628void RenderView::didSerializeDataForFrame(const WebURL& frame_url,
3629 const WebCString& data,
3630 WebPageSerializerClient::PageSerializationStatus status) {
3631 Send(new ViewHostMsg_SendSerializedHtmlData(
3632 routing_id_,
3633 frame_url,
3634 data.data(),
3635 static_cast<int32>(status)));
initial.commit09911bf2008-07-26 23:55:293636}
3637
[email protected]04b4a6c2008-08-02 00:44:473638void RenderView::OnMsgShouldClose() {
[email protected]26aa0482009-09-30 16:55:273639 bool should_close = webview()->dispatchBeforeUnloadEvent();
[email protected]04b4a6c2008-08-02 00:44:473640 Send(new ViewHostMsg_ShouldClose_ACK(routing_id_, should_close));
initial.commit09911bf2008-07-26 23:55:293641}
3642
[email protected]eb6b87a2009-07-24 15:57:393643void RenderView::OnClosePage(const ViewMsg_ClosePage_Params& params) {
initial.commit09911bf2008-07-26 23:55:293644 // TODO(creis): We'd rather use webview()->Close() here, but that currently
3645 // sets the WebView's delegate_ to NULL, preventing any JavaScript dialogs
3646 // in the onunload handler from appearing. For now, we're bypassing that and
3647 // calling the FrameLoader's CloseURL method directly. This should be
3648 // revisited to avoid having two ways to close a page. Having a single way
3649 // to close that can run onunload is also useful for fixing
3650 // http://b/issue?id=753080.
[email protected]26aa0482009-09-30 16:55:273651 WebFrame* main_frame = webview()->mainFrame();
[email protected]7a9b51f2009-06-29 21:28:293652 if (main_frame) {
[email protected]dd7daa82009-08-10 05:46:453653 const GURL& url = main_frame->url();
[email protected]3d9689372009-09-10 04:29:173654 // TODO(davemoore) this code should be removed once willClose() gets
[email protected]7a9b51f2009-06-29 21:28:293655 // called when a page is destroyed. DumpLoadHistograms() is safe to call
3656 // multiple times for the same frame, but it will simplify things.
[email protected]dd7daa82009-08-10 05:46:453657 if (url.SchemeIs(chrome::kHttpScheme) ||
3658 url.SchemeIs(chrome::kHttpsScheme))
[email protected]7a9b51f2009-06-29 21:28:293659 DumpLoadHistograms();
[email protected]7a9b51f2009-06-29 21:28:293660 }
[email protected]26aa0482009-09-30 16:55:273661 webview()->dispatchUnloadEvent();
initial.commit09911bf2008-07-26 23:55:293662
[email protected]eb6b87a2009-07-24 15:57:393663 // Just echo back the params in the ACK.
3664 Send(new ViewHostMsg_ClosePage_ACK(routing_id_, params));
initial.commit09911bf2008-07-26 23:55:293665}
3666
3667void RenderView::OnThemeChanged() {
[email protected]6c8afae52009-01-22 02:24:573668#if defined(OS_WIN)
initial.commit09911bf2008-07-26 23:55:293669 gfx::NativeTheme::instance()->CloseHandles();
3670 gfx::Rect view_rect(0, 0, size_.width(), size_.height());
[email protected]4873c7d2009-07-16 06:36:283671 didInvalidateRect(view_rect);
[email protected]6c8afae52009-01-22 02:24:573672#else // defined(OS_WIN)
3673 // TODO(port): we don't support theming on non-Windows platforms yet
3674 NOTIMPLEMENTED();
3675#endif
initial.commit09911bf2008-07-26 23:55:293676}
3677
[email protected]28790922009-03-09 19:48:373678void RenderView::OnMessageFromExternalHost(const std::string& message,
3679 const std::string& origin,
3680 const std::string& target) {
[email protected]3ac14a052008-08-15 21:22:153681 if (message.empty())
3682 return;
3683
[email protected]28790922009-03-09 19:48:373684 external_host_bindings_.ForwardMessageFromExternalHost(message, origin,
3685 target);
[email protected]3ac14a052008-08-15 21:22:153686}
3687
[email protected]0aa55312008-10-17 21:53:083688void RenderView::OnDisassociateFromPopupCount() {
3689 if (decrement_shared_popup_at_destruction_)
3690 shared_popup_counter_->data--;
3691 shared_popup_counter_ = new SharedRenderViewCounter(0);
3692 decrement_shared_popup_at_destruction_ = false;
3693}
3694
[email protected]15d79e12009-08-02 19:23:453695bool RenderView::MaybeLoadAlternateErrorPage(WebFrame* frame,
3696 const WebURLError& error,
3697 bool replace) {
3698 // We only show alternate error pages in the main frame. They are
3699 // intended to assist the user when navigating, so there is not much
3700 // value in showing them for failed subframes. Ideally, we would be
3701 // able to use the TYPED transition type for this, but that flag is
3702 // not preserved across page reloads.
[email protected]dd7daa82009-08-10 05:46:453703 if (frame->parent())
[email protected]15d79e12009-08-02 19:23:453704 return false;
3705
3706 // Use the alternate error page service if this is a DNS failure or
[email protected]c53976d52009-08-07 18:58:373707 // connection failure.
[email protected]15d79e12009-08-02 19:23:453708 int ec = error.reason;
3709 if (ec != net::ERR_NAME_NOT_RESOLVED &&
3710 ec != net::ERR_CONNECTION_FAILED &&
3711 ec != net::ERR_CONNECTION_REFUSED &&
3712 ec != net::ERR_ADDRESS_UNREACHABLE &&
[email protected]c53976d52009-08-07 18:58:373713 ec != net::ERR_CONNECTION_TIMED_OUT)
[email protected]15d79e12009-08-02 19:23:453714 return false;
3715
3716 const GURL& error_page_url = GetAlternateErrorPageURL(error.unreachableURL,
[email protected]7ccddb8c2009-08-04 17:36:553717 ec == net::ERR_NAME_NOT_RESOLVED ? DNS_ERROR : CONNECTION_ERROR);
[email protected]15d79e12009-08-02 19:23:453718 if (!error_page_url.is_valid())
3719 return false;
3720
3721 // Load an empty page first so there is an immediate response to the error,
3722 // and then kick off a request for the alternate error page.
[email protected]dd7daa82009-08-10 05:46:453723 frame->loadHTMLString(std::string(),
[email protected]15d79e12009-08-02 19:23:453724 GURL(kUnreachableWebDataURL),
3725 error.unreachableURL,
3726 replace);
3727
3728 // Now, create a fetcher for the error page and associate it with the data
3729 // source we just created via the LoadHTMLString call. That way if another
3730 // navigation occurs, the fetcher will get destroyed.
3731 NavigationState* navigation_state =
[email protected]dd7daa82009-08-10 05:46:453732 NavigationState::FromDataSource(frame->provisionalDataSource());
[email protected]15d79e12009-08-02 19:23:453733 navigation_state->set_alt_error_page_fetcher(
3734 new AltErrorPageResourceFetcher(
3735 error_page_url, frame, error,
3736 NewCallback(this, &RenderView::AltErrorPageFinished)));
3737 return true;
3738}
3739
initial.commit09911bf2008-07-26 23:55:293740std::string RenderView::GetAltHTMLForTemplate(
3741 const DictionaryValue& error_strings, int template_resource_id) const {
[email protected]8a16266e2009-09-10 21:08:393742 const base::StringPiece template_html(
initial.commit09911bf2008-07-26 23:55:293743 ResourceBundle::GetSharedInstance().GetRawDataResource(
3744 template_resource_id));
3745
3746 if (template_html.empty()) {
3747 NOTREACHED() << "unable to load template. ID: " << template_resource_id;
3748 return "";
3749 }
[email protected]7cd22a52009-07-14 00:40:253750
initial.commit09911bf2008-07-26 23:55:293751 // "t" is the id of the templates root node.
[email protected]7cd22a52009-07-14 00:40:253752 return jstemplate_builder::GetTemplatesHtml(
initial.commit09911bf2008-07-26 23:55:293753 template_html, &error_strings, "t");
3754}
[email protected]0e79b9e2009-02-13 04:20:483755
[email protected]15d79e12009-08-02 19:23:453756void RenderView::AltErrorPageFinished(WebFrame* frame,
3757 const WebURLError& original_error,
3758 const std::string& html) {
3759 // Here, we replace the blank page we loaded previously.
[email protected]7ccddb8c2009-08-04 17:36:553760
3761 // If we failed to download the alternate error page, fall back to the
3762 // original error page if present. Otherwise, LoadNavigationErrorPage
3763 // will simply display a default error page.
3764 const std::string* html_to_load = &html;
3765 if (html.empty()) {
3766 NavigationState* navigation_state =
[email protected]dd7daa82009-08-10 05:46:453767 NavigationState::FromDataSource(frame->dataSource());
[email protected]7ccddb8c2009-08-04 17:36:553768 html_to_load = &navigation_state->postponed_data();
3769 }
3770 LoadNavigationErrorPage(
3771 frame, WebURLRequest(), original_error, *html_to_load, true);
[email protected]15d79e12009-08-02 19:23:453772}
3773
[email protected]30f75e62009-02-25 22:01:003774void RenderView::OnMoveOrResizeStarted() {
3775 if (webview())
[email protected]4605325d2010-02-08 23:46:043776 webview()->hideSuggestionsPopup();
[email protected]30f75e62009-02-25 22:01:003777}
3778
[email protected]30f75e62009-02-25 22:01:003779void RenderView::OnResize(const gfx::Size& new_size,
3780 const gfx::Rect& resizer_rect) {
3781 if (webview())
[email protected]4605325d2010-02-08 23:46:043782 webview()->hideSuggestionsPopup();
[email protected]30f75e62009-02-25 22:01:003783 RenderWidget::OnResize(new_size, resizer_rect);
3784}
[email protected]0aa477bd2009-03-23 22:21:433785
[email protected]05d478752009-04-08 23:38:163786void RenderView::OnClearFocusedNode() {
3787 if (webview())
[email protected]26aa0482009-09-30 16:55:273788 webview()->clearFocusedNode();
[email protected]05d478752009-04-08 23:38:163789}
3790
[email protected]699ab0d2009-04-23 23:19:143791void RenderView::OnSetBackground(const SkBitmap& background) {
3792 if (webview())
[email protected]b4bb2502009-10-01 22:35:273793 webview()->setIsTransparent(!background.empty());
[email protected]699ab0d2009-04-23 23:19:143794
3795 SetBackground(background);
3796}
3797
[email protected]8c66c5a2009-07-22 17:26:343798void RenderView::OnSetActive(bool active) {
3799 if (webview())
[email protected]b4bb2502009-10-01 22:35:273800 webview()->setIsActive(active);
[email protected]d8fd6fa2010-02-01 15:54:263801
3802#if defined(OS_MACOSX)
3803 std::set<WebPluginDelegateProxy*>::iterator plugin_it;
3804 for (plugin_it = plugin_delegates_.begin();
3805 plugin_it != plugin_delegates_.end(); ++plugin_it) {
3806 (*plugin_it)->SetWindowFocus(active);
3807 }
3808#endif
[email protected]8c66c5a2009-07-22 17:26:343809}
3810
[email protected]6ce7abc52010-02-02 18:40:143811#if defined(OS_MACOSX)
3812void RenderView::OnSetWindowVisibility(bool visible) {
3813 // Inform plugins that their container has changed visibility.
3814 std::set<WebPluginDelegateProxy*>::iterator plugin_it;
3815 for (plugin_it = plugin_delegates_.begin();
3816 plugin_it != plugin_delegates_.end(); ++plugin_it) {
3817 (*plugin_it)->SetContainerVisibility(visible);
3818 }
3819}
[email protected]1e6e3c992010-02-08 15:52:133820
3821void RenderView::OnWindowFrameChanged(gfx::Rect window_frame,
3822 gfx::Rect view_frame) {
3823 // Inform plugins that their window's frame has changed.
3824 std::set<WebPluginDelegateProxy*>::iterator plugin_it;
3825 for (plugin_it = plugin_delegates_.begin();
3826 plugin_it != plugin_delegates_.end(); ++plugin_it) {
3827 (*plugin_it)->WindowFrameChanged(window_frame, view_frame);
3828 }
3829}
[email protected]6ce7abc52010-02-02 18:40:143830#endif // OS_MACOSX
3831
[email protected]309d7a282009-03-24 09:18:273832void RenderView::SendExtensionRequest(const std::string& name,
[email protected]e4dad9fb2009-10-06 18:15:583833 const ListValue& args,
[email protected]c6619182009-05-12 14:59:323834 int request_id,
[email protected]2f25d7b92009-06-10 00:06:473835 bool has_callback) {
[email protected]c6619182009-05-12 14:59:323836 Send(new ViewHostMsg_ExtensionRequest(routing_id_, name, args, request_id,
[email protected]2f25d7b92009-06-10 00:06:473837 has_callback));
[email protected]309d7a282009-03-24 09:18:273838}
3839
[email protected]c6619182009-05-12 14:59:323840void RenderView::OnExtensionResponse(int request_id,
3841 bool success,
3842 const std::string& response,
3843 const std::string& error) {
[email protected]0f6053962009-07-09 19:26:353844 ExtensionProcessBindings::HandleResponse(
3845 request_id, success, response, error);
[email protected]309d7a282009-03-24 09:18:273846}
[email protected]c20210e62009-04-03 21:39:263847
[email protected]078b34612009-09-19 19:31:513848void RenderView::InjectToolstripCSS() {
3849 if (view_type_ != ViewType::EXTENSION_TOOLSTRIP)
3850 return;
3851
3852 static const base::StringPiece toolstrip_css(
3853 ResourceBundle::GetSharedInstance().GetRawDataResource(
3854 IDR_EXTENSION_TOOLSTRIP_CSS));
3855 std::string css = toolstrip_css.as_string();
3856 InsertCSS(L"", css, "ToolstripDefaultCSS");
3857}
3858
[email protected]7120f132009-07-20 21:05:373859void RenderView::OnExtensionMessageInvoke(const std::string& function_name,
3860 const ListValue& args) {
3861 RendererExtensionBindings::Invoke(function_name, args, this);
3862}
3863
[email protected]e7e4f3c2009-04-21 15:24:083864// Dump all load time histograms.
[email protected]c20210e62009-04-03 21:39:263865//
[email protected]7a9b51f2009-06-29 21:28:293866// There are 13 histograms measuring various times.
[email protected]c20210e62009-04-03 21:39:263867// The time points we keep are
3868// request: time document was requested by user
3869// start: time load of document started
[email protected]a2f6bc112009-06-27 16:27:253870// commit: time load of document started
[email protected]7a9b51f2009-06-29 21:28:293871// finish_document: main document loaded, before onload()
[email protected]c20210e62009-04-03 21:39:263872// finish: after onload() and all resources are loaded
[email protected]7a9b51f2009-06-29 21:28:293873// first_paint: first paint performed
3874// first_paint_after_load: first paint performed after load is finished
3875// begin: request if it was user requested, start otherwise
3876//
[email protected]c20210e62009-04-03 21:39:263877// The times that we histogram are
[email protected]a2f6bc112009-06-27 16:27:253878// request->start,
[email protected]7a9b51f2009-06-29 21:28:293879// start->commit,
3880// commit->finish_document,
3881// finish_document->finish,
3882// begin->commit,
3883// begin->finishDoc,
3884// begin->finish,
3885// begin->first_paint,
3886// begin->first_paint_after_load
3887// commit->finishDoc,
3888// commit->first_paint,
3889// commit->first_paint_after_load,
3890// finish->first_paint_after_load,
[email protected]c20210e62009-04-03 21:39:263891//
[email protected]e7e4f3c2009-04-21 15:24:083892// It's possible for the request time not to be set, if a client
3893// redirect had been done (the user never requested the page)
3894// Also, it's possible to load a page without ever laying it out
[email protected]7a9b51f2009-06-29 21:28:293895// so first_paint and first_paint_after_load can be 0.
[email protected]c20210e62009-04-03 21:39:263896void RenderView::DumpLoadHistograms() const {
[email protected]26aa0482009-09-30 16:55:273897 WebFrame* main_frame = webview()->mainFrame();
[email protected]ed3fb032009-06-16 19:50:563898 NavigationState* navigation_state =
[email protected]dd7daa82009-08-10 05:46:453899 NavigationState::FromDataSource(main_frame->dataSource());
[email protected]7a9b51f2009-06-29 21:28:293900 Time finish = navigation_state->finish_load_time();
[email protected]ed3fb032009-06-16 19:50:563901
[email protected]7a9b51f2009-06-29 21:28:293902 // If we've already dumped or we haven't finished loading, do nothing.
3903 if (navigation_state->load_histograms_recorded() || finish.is_null())
3904 return;
[email protected]ed3fb032009-06-16 19:50:563905
[email protected]f8999642009-10-27 21:39:423906 LogNavigationState(navigation_state, main_frame->dataSource());
3907
[email protected]a7ccc4d2010-01-27 08:14:483908 NavigationState::LoadType load_type = navigation_state->load_type();
3909 UMA_HISTOGRAM_ENUMERATION("Renderer4.LoadType", load_type,
[email protected]4c1b6f0b2010-02-07 16:38:183910 NavigationState::kLoadTypeMax);
[email protected]a7ccc4d2010-01-27 08:14:483911
[email protected]7a9b51f2009-06-29 21:28:293912 Time request = navigation_state->request_time();
3913 Time start = navigation_state->start_load_time();
3914 Time commit = navigation_state->commit_load_time();
3915 Time finish_doc = navigation_state->finish_document_load_time();
3916 Time first_paint = navigation_state->first_paint_time();
3917 Time first_paint_after_load =
3918 navigation_state->first_paint_after_load_time();
[email protected]c20210e62009-04-03 21:39:263919
[email protected]7a9b51f2009-06-29 21:28:293920 Time begin;
3921 // Client side redirects will have no request time.
3922 if (request.is_null()) {
3923 begin = start;
3924 } else {
3925 begin = request;
3926 UMA_HISTOGRAM_MEDIUM_TIMES("Renderer4.RequestToStart", start - request);
[email protected]e7e4f3c2009-04-21 15:24:083927 }
[email protected]7a9b51f2009-06-29 21:28:293928 UMA_HISTOGRAM_MEDIUM_TIMES("Renderer4.StartToCommit", commit - start);
3929 UMA_HISTOGRAM_MEDIUM_TIMES(
3930 "Renderer4.CommitToFinishDoc", finish_doc - commit);
3931 UMA_HISTOGRAM_MEDIUM_TIMES(
3932 "Renderer4.FinishDocToFinish", finish - finish_doc);
3933
3934 UMA_HISTOGRAM_MEDIUM_TIMES("Renderer4.BeginToCommit", commit - begin);
[email protected]a7ccc4d2010-01-27 08:14:483935
3936 static const TimeDelta kBeginToFinishDocMin(TimeDelta::FromMilliseconds(10));
3937 static const TimeDelta kBeginToFinishDocMax(TimeDelta::FromMinutes(10));
3938 static const size_t kBeginToFinishDocBucketCount(100);
[email protected]a7ccc4d2010-01-27 08:14:483939 TimeDelta begin_to_finish_doc = finish_doc - begin;
3940 UMA_HISTOGRAM_MEDIUM_TIMES("Renderer4.BeginToFinishDoc", begin_to_finish_doc);
[email protected]4c1b6f0b2010-02-07 16:38:183941
3942 static const TimeDelta kBeginToFinishMin(TimeDelta::FromMilliseconds(10));
3943 static const TimeDelta kBeginToFinishMax(TimeDelta::FromMinutes(10));
3944 static const size_t kBeginToFinishBucketCount(100);
3945 TimeDelta begin_to_finish = finish_doc - begin;
3946 UMA_HISTOGRAM_CUSTOM_TIMES("Renderer4.BeginToFinish", begin_to_finish,
3947 kBeginToFinishMin, kBeginToFinishMax, kBeginToFinishBucketCount);
3948
[email protected]a7ccc4d2010-01-27 08:14:483949 switch (load_type) {
3950 case NavigationState::UNDEFINED_LOAD:
3951 UMA_HISTOGRAM_CUSTOM_TIMES("Renderer4.BeginToFinishDoc_UndefLoad",
3952 begin_to_finish_doc, kBeginToFinishDocMin, kBeginToFinishDocMax,
3953 kBeginToFinishDocBucketCount);
[email protected]4c1b6f0b2010-02-07 16:38:183954 UMA_HISTOGRAM_CUSTOM_TIMES("Renderer4.BeginToFinish_UndefLoad",
3955 begin_to_finish, kBeginToFinishMin, kBeginToFinishMax,
3956 kBeginToFinishBucketCount);
[email protected]a7ccc4d2010-01-27 08:14:483957 break;
3958 case NavigationState::RELOAD:
3959 UMA_HISTOGRAM_CUSTOM_TIMES("Renderer4.BeginToFinishDoc_Reload",
3960 begin_to_finish_doc, kBeginToFinishDocMin, kBeginToFinishDocMax,
3961 kBeginToFinishDocBucketCount);
[email protected]4c1b6f0b2010-02-07 16:38:183962 UMA_HISTOGRAM_CUSTOM_TIMES("Renderer4.BeginToFinish_Reload",
3963 begin_to_finish, kBeginToFinishMin, kBeginToFinishMax,
3964 kBeginToFinishBucketCount);
[email protected]a7ccc4d2010-01-27 08:14:483965 break;
3966 case NavigationState::HISTORY_LOAD:
3967 UMA_HISTOGRAM_CUSTOM_TIMES("Renderer4.BeginToFinishDoc_HistoryLoad",
3968 begin_to_finish_doc, kBeginToFinishDocMin, kBeginToFinishDocMax,
3969 kBeginToFinishDocBucketCount);
[email protected]4c1b6f0b2010-02-07 16:38:183970 UMA_HISTOGRAM_CUSTOM_TIMES("Renderer4.BeginToFinish_HistoryLoad",
3971 begin_to_finish, kBeginToFinishMin, kBeginToFinishMax,
3972 kBeginToFinishBucketCount);
[email protected]a7ccc4d2010-01-27 08:14:483973 break;
3974 case NavigationState::NORMAL_LOAD:
3975 UMA_HISTOGRAM_CUSTOM_TIMES("Renderer4.BeginToFinishDoc_NormalLoad",
3976 begin_to_finish_doc, kBeginToFinishDocMin, kBeginToFinishDocMax,
3977 kBeginToFinishDocBucketCount);
[email protected]4c1b6f0b2010-02-07 16:38:183978 UMA_HISTOGRAM_CUSTOM_TIMES("Renderer4.BeginToFinish_NormalLoad",
3979 begin_to_finish, kBeginToFinishMin, kBeginToFinishMax,
3980 kBeginToFinishBucketCount);
[email protected]a7ccc4d2010-01-27 08:14:483981 break;
[email protected]4c1b6f0b2010-02-07 16:38:183982 case NavigationState::LINK_LOAD_NORMAL:
3983 UMA_HISTOGRAM_CUSTOM_TIMES("Renderer4.BeginToFinishDoc_LinkLoadNormal",
[email protected]a7ccc4d2010-01-27 08:14:483984 begin_to_finish_doc, kBeginToFinishDocMin, kBeginToFinishDocMax,
3985 kBeginToFinishDocBucketCount);
[email protected]4c1b6f0b2010-02-07 16:38:183986 UMA_HISTOGRAM_CUSTOM_TIMES("Renderer4.BeginToFinish_LinkLoadNormal",
3987 begin_to_finish, kBeginToFinishMin, kBeginToFinishMax,
3988 kBeginToFinishBucketCount);
3989 break;
3990 case NavigationState::LINK_LOAD_RELOAD:
3991 UMA_HISTOGRAM_CUSTOM_TIMES("Renderer4.BeginToFinishDoc_LinkLoadReload",
3992 begin_to_finish_doc, kBeginToFinishDocMin, kBeginToFinishDocMax,
3993 kBeginToFinishDocBucketCount);
3994 UMA_HISTOGRAM_CUSTOM_TIMES("Renderer4.BeginToFinish_LinkLoadReload",
3995 begin_to_finish, kBeginToFinishMin, kBeginToFinishMax,
3996 kBeginToFinishBucketCount);
3997 break;
3998 case NavigationState::LINK_LOAD_CACHE_STALE_OK:
3999 UMA_HISTOGRAM_CUSTOM_TIMES("Renderer4.BeginToFinishDoc_LinkLoadStaleOk",
4000 begin_to_finish_doc, kBeginToFinishDocMin, kBeginToFinishDocMax,
4001 kBeginToFinishDocBucketCount);
4002 UMA_HISTOGRAM_CUSTOM_TIMES("Renderer4.BeginToFinish_LinkLoadStaleOk",
4003 begin_to_finish, kBeginToFinishMin, kBeginToFinishMax,
4004 kBeginToFinishBucketCount);
4005 break;
4006 case NavigationState::LINK_LOAD_CACHE_ONLY:
4007 UMA_HISTOGRAM_CUSTOM_TIMES("Renderer4.BeginToFinishDoc_LinkLoadCacheOnly",
4008 begin_to_finish_doc, kBeginToFinishDocMin, kBeginToFinishDocMax,
4009 kBeginToFinishDocBucketCount);
4010 UMA_HISTOGRAM_CUSTOM_TIMES("Renderer4.BeginToFinish_LinkLoadCacheOnly",
4011 begin_to_finish, kBeginToFinishMin, kBeginToFinishMax,
4012 kBeginToFinishBucketCount);
[email protected]a7ccc4d2010-01-27 08:14:484013 break;
4014 default:
4015 break;
4016 }
4017
4018 static bool use_dns_histogram(FieldTrialList::Find("DnsImpact") &&
4019 !FieldTrialList::Find("DnsImpact")->group_name().empty());
4020 if (use_dns_histogram) {
4021 switch (load_type) {
4022 case NavigationState::NORMAL_LOAD:
4023 UMA_HISTOGRAM_CUSTOM_TIMES(FieldTrial::MakeName(
4024 "Renderer4.BeginToFinishDoc_NormalLoad", "DnsImpact"),
4025 begin_to_finish_doc, kBeginToFinishDocMin, kBeginToFinishDocMax,
4026 kBeginToFinishDocBucketCount);
[email protected]a7ccc4d2010-01-27 08:14:484027 UMA_HISTOGRAM_CUSTOM_TIMES(FieldTrial::MakeName(
[email protected]4c1b6f0b2010-02-07 16:38:184028 "Renderer4.BeginToFinish_NormalLoad", "DnsImpact"),
4029 begin_to_finish, kBeginToFinishMin, kBeginToFinishMax,
4030 kBeginToFinishBucketCount);
4031 break;
4032 case NavigationState::LINK_LOAD_NORMAL:
4033 UMA_HISTOGRAM_CUSTOM_TIMES(FieldTrial::MakeName(
4034 "Renderer4.BeginToFinishDoc_LinkLoadNormal", "DnsImpact"),
[email protected]a7ccc4d2010-01-27 08:14:484035 begin_to_finish_doc, kBeginToFinishDocMin, kBeginToFinishDocMax,
4036 kBeginToFinishDocBucketCount);
[email protected]4c1b6f0b2010-02-07 16:38:184037 UMA_HISTOGRAM_CUSTOM_TIMES(FieldTrial::MakeName(
4038 "Renderer4.BeginToFinish_LinkLoadNormal", "DnsImpact"),
4039 begin_to_finish, kBeginToFinishMin, kBeginToFinishMax,
4040 kBeginToFinishBucketCount);
4041 break;
4042 case NavigationState::LINK_LOAD_RELOAD:
4043 UMA_HISTOGRAM_CUSTOM_TIMES(FieldTrial::MakeName(
4044 "Renderer4.BeginToFinishDoc_LinkLoadReload", "DnsImpact"),
4045 begin_to_finish_doc, kBeginToFinishDocMin, kBeginToFinishDocMax,
4046 kBeginToFinishDocBucketCount);
4047 UMA_HISTOGRAM_CUSTOM_TIMES(FieldTrial::MakeName(
4048 "Renderer4.BeginToFinish_LinkLoadReload", "DnsImpact"),
4049 begin_to_finish, kBeginToFinishMin, kBeginToFinishMax,
4050 kBeginToFinishBucketCount);
4051 break;
4052 case NavigationState::LINK_LOAD_CACHE_STALE_OK:
4053 UMA_HISTOGRAM_CUSTOM_TIMES(FieldTrial::MakeName(
4054 "Renderer4.BeginToFinishDoc_LinkLoadStaleOk", "DnsImpact"),
4055 begin_to_finish_doc, kBeginToFinishDocMin, kBeginToFinishDocMax,
4056 kBeginToFinishDocBucketCount);
4057 UMA_HISTOGRAM_CUSTOM_TIMES(FieldTrial::MakeName(
4058 "Renderer4.BeginToFinish_LinkLoadStaleOk", "DnsImpact"),
4059 begin_to_finish, kBeginToFinishMin, kBeginToFinishMax,
4060 kBeginToFinishBucketCount);
[email protected]a7ccc4d2010-01-27 08:14:484061 break;
4062 default:
4063 break;
4064 }
4065 }
4066
4067 static bool use_sdch_histogram(FieldTrialList::Find("GlobalSdch") &&
4068 !FieldTrialList::Find("GlobalSdch")->group_name().empty());
4069 if (use_sdch_histogram) {
4070 switch (load_type) {
4071 case NavigationState::NORMAL_LOAD:
4072 UMA_HISTOGRAM_CUSTOM_TIMES(FieldTrial::MakeName(
4073 "Renderer4.BeginToFinishDoc_NormalLoad", "GlobalSdch"),
4074 begin_to_finish_doc, kBeginToFinishDocMin, kBeginToFinishDocMax,
4075 kBeginToFinishDocBucketCount);
4076 break;
[email protected]4c1b6f0b2010-02-07 16:38:184077 case NavigationState::LINK_LOAD_NORMAL:
[email protected]a7ccc4d2010-01-27 08:14:484078 UMA_HISTOGRAM_CUSTOM_TIMES(FieldTrial::MakeName(
[email protected]4c1b6f0b2010-02-07 16:38:184079 "Renderer4.BeginToFinishDoc_LinkLoadNormal", "GlobalSdch"),
4080 begin_to_finish_doc, kBeginToFinishDocMin, kBeginToFinishDocMax,
4081 kBeginToFinishDocBucketCount);
4082 break;
4083 case NavigationState::LINK_LOAD_RELOAD:
4084 UMA_HISTOGRAM_CUSTOM_TIMES(FieldTrial::MakeName(
4085 "Renderer4.BeginToFinishDoc_LinkLoadReload", "GlobalSdch"),
4086 begin_to_finish_doc, kBeginToFinishDocMin, kBeginToFinishDocMax,
4087 kBeginToFinishDocBucketCount);
4088 break;
4089 case NavigationState::LINK_LOAD_CACHE_STALE_OK:
4090 UMA_HISTOGRAM_CUSTOM_TIMES(FieldTrial::MakeName(
4091 "Renderer4.BeginToFinishDoc_LinkLoadCacheStaleOk", "GlobalSdch"),
4092 begin_to_finish_doc, kBeginToFinishDocMin, kBeginToFinishDocMax,
4093 kBeginToFinishDocBucketCount);
4094 break;
4095 case NavigationState::LINK_LOAD_CACHE_ONLY:
4096 UMA_HISTOGRAM_CUSTOM_TIMES(FieldTrial::MakeName(
4097 "Renderer4.BeginToFinishDoc_LinkLoadCacheOnly", "GlobalSdch"),
[email protected]a7ccc4d2010-01-27 08:14:484098 begin_to_finish_doc, kBeginToFinishDocMin, kBeginToFinishDocMax,
4099 kBeginToFinishDocBucketCount);
4100 break;
4101 default:
4102 break;
4103 }
4104 }
4105
4106 static bool use_socket_late_binding_histogram =
4107 FieldTrialList::Find("SocketLateBinding") &&
4108 !FieldTrialList::Find("SocketLateBinding")->group_name().empty();
4109 if (use_socket_late_binding_histogram) {
4110 switch (load_type) {
4111 case NavigationState::NORMAL_LOAD:
4112 UMA_HISTOGRAM_CUSTOM_TIMES(FieldTrial::MakeName(
4113 "Renderer4.BeginToFinishDoc_NormalLoad", "SocketLateBinding"),
4114 begin_to_finish_doc, kBeginToFinishDocMin, kBeginToFinishDocMax,
4115 kBeginToFinishDocBucketCount);
4116 break;
[email protected]4c1b6f0b2010-02-07 16:38:184117 case NavigationState::LINK_LOAD_NORMAL:
[email protected]a7ccc4d2010-01-27 08:14:484118 UMA_HISTOGRAM_CUSTOM_TIMES(FieldTrial::MakeName(
[email protected]4c1b6f0b2010-02-07 16:38:184119 "Renderer4.BeginToFinishDoc_LinkLoadNormal", "SocketLateBinding"),
4120 begin_to_finish_doc, kBeginToFinishDocMin, kBeginToFinishDocMax,
4121 kBeginToFinishDocBucketCount);
4122 break;
4123 case NavigationState::LINK_LOAD_RELOAD:
4124 UMA_HISTOGRAM_CUSTOM_TIMES(FieldTrial::MakeName(
4125 "Renderer4.BeginToFinishDoc_LinkLoadReload", "SocketLateBinding"),
[email protected]a7ccc4d2010-01-27 08:14:484126 begin_to_finish_doc, kBeginToFinishDocMin, kBeginToFinishDocMax,
4127 kBeginToFinishDocBucketCount);
4128 break;
4129 default:
4130 break;
4131 }
4132 }
4133
4134 static bool use_cache_histogram1(FieldTrialList::Find("CacheSize") &&
4135 !FieldTrialList::Find("CacheSize")->group_name().empty());
[email protected]4c1b6f0b2010-02-07 16:38:184136 if (use_cache_histogram1 && NavigationState::LINK_LOAD_NORMAL <= load_type &&
4137 NavigationState::LINK_LOAD_CACHE_ONLY >= load_type)
[email protected]a7ccc4d2010-01-27 08:14:484138 UMA_HISTOGRAM_CUSTOM_TIMES(FieldTrial::MakeName(
4139 "Renderer4.BeginToFinishDoc_LinkLoad", "CacheSize"),
4140 begin_to_finish_doc, kBeginToFinishDocMin, kBeginToFinishDocMax,
4141 kBeginToFinishDocBucketCount);
[email protected]e695fbd62009-06-30 16:31:544142
[email protected]0a32257a2009-07-09 18:10:414143 UMA_HISTOGRAM_CUSTOM_TIMES("Renderer4.StartToFinish",
4144 finish - start, kBeginToFinishMin,
4145 kBeginToFinishMax, kBeginToFinishBucketCount);
4146 if (!request.is_null())
4147 UMA_HISTOGRAM_CUSTOM_TIMES("Renderer4.RequestToFinish",
4148 finish - request, kBeginToFinishMin,
4149 kBeginToFinishMax, kBeginToFinishBucketCount);
[email protected]e695fbd62009-06-30 16:31:544150
[email protected]7a9b51f2009-06-29 21:28:294151 UMA_HISTOGRAM_MEDIUM_TIMES("Renderer4.CommitToFinish", finish - commit);
4152
4153 if (!first_paint.is_null()) {
4154 UMA_HISTOGRAM_MEDIUM_TIMES(
4155 "Renderer4.BeginToFirstPaint", first_paint - begin);
4156 UMA_HISTOGRAM_MEDIUM_TIMES(
4157 "Renderer4.CommitToFirstPaint", first_paint - commit);
[email protected]c20210e62009-04-03 21:39:264158 }
[email protected]7a9b51f2009-06-29 21:28:294159
4160 if (!first_paint_after_load.is_null()) {
4161 UMA_HISTOGRAM_MEDIUM_TIMES(
4162 "Renderer4.BeginToFirstPaintAfterLoad", first_paint_after_load - begin);
4163 UMA_HISTOGRAM_MEDIUM_TIMES(
4164 "Renderer4.CommitToFirstPaintAfterLoad",
4165 first_paint_after_load - commit);
4166 UMA_HISTOGRAM_MEDIUM_TIMES(
4167 "Renderer4.FinishToFirstPaintAfterLoad",
4168 first_paint_after_load - finish);
4169 }
4170
4171 navigation_state->set_load_histograms_recorded(true);
[email protected]1f4fc8e8c2010-01-02 00:46:414172
4173 // Since there are currently no guarantees that renderer histograms will be
4174 // sent to the browser, we initiate a PostTask here to be sure that we send
4175 // the histograms we generated. Without this call, pages that don't have an
4176 // on-close-handler might generate data that is lost when the renderer is
4177 // shutdown abruptly (perchance because the user closed the tab).
[email protected]a7ccc4d2010-01-27 08:14:484178 // TODO(jar) BUG=33233: This needs to be moved to a PostDelayedTask, and it
4179 // should post when the onload is complete, so that it doesn't interfere with
4180 // the next load.
[email protected]1f4fc8e8c2010-01-02 00:46:414181 if (RenderThread::current()) {
4182 RenderThread::current()->SendHistograms(
4183 HistogramSynchronizer::kReservedSequenceNumber);
4184 }
[email protected]c20210e62009-04-03 21:39:264185}
[email protected]e846d0d2009-05-20 00:53:064186
[email protected]f8999642009-10-27 21:39:424187void RenderView::LogNavigationState(const NavigationState* state,
4188 const WebDataSource* ds) const {
4189 // Because this function gets called on every page load,
4190 // take extra care to optimize it away if logging is turned off.
4191 if (logging::LOG_INFO < logging::GetMinLogLevel())
4192 return;
4193
4194 DCHECK(state);
4195 DCHECK(ds);
4196 GURL url(ds->request().url());
4197 Time start = state->start_load_time();
4198 Time finish = state->finish_load_time();
4199 // TODO(mbelshe): should we log more stats?
4200 LOG(INFO) << "PLT: "
4201 << (finish - start).InMilliseconds()
4202 << "ms "
4203 << url.spec();
4204}
4205
[email protected]cc0445f2009-10-13 16:09:084206void RenderView::focusAccessibilityObject(
4207 const WebAccessibilityObject& acc_obj) {
[email protected]e846d0d2009-05-20 00:53:064208#if defined(OS_WIN)
[email protected]c7287a92009-11-04 20:06:154209 // TODO(dglazkov): Current logic implies that focus change can only be made
4210 // after at least one call to RenderView::OnGetAccessibilityInfo, which is
4211 // where accessibility is initialized. We should determine whether that's
4212 // right.
4213 if (!accessibility_.get())
4214 return;
[email protected]e846d0d2009-05-20 00:53:064215
4216 // Retrieve the accessibility object id of the AccessibilityObject.
[email protected]c7287a92009-11-04 20:06:154217 int acc_obj_id = accessibility_->addOrGetId(acc_obj);
[email protected]e846d0d2009-05-20 00:53:064218
4219 // If id is valid, alert the browser side that an accessibility focus change
4220 // occurred.
4221 if (acc_obj_id >= 0)
4222 Send(new ViewHostMsg_AccessibilityFocusChange(routing_id_, acc_obj_id));
4223
4224#else // defined(OS_WIN)
4225 // TODO(port): accessibility not yet implemented
4226 NOTIMPLEMENTED();
4227#endif
4228}
[email protected]daa8c58e2009-06-15 17:21:104229
4230void RenderView::SendPasswordForms(WebFrame* frame) {
[email protected]979c28b2009-11-07 01:30:484231 WebVector<WebFormElement> forms;
[email protected]dd7daa82009-08-10 05:46:454232 frame->forms(forms);
[email protected]daa8c58e2009-06-15 17:21:104233
4234 std::vector<PasswordForm> password_forms;
4235 for (size_t i = 0; i < forms.size(); ++i) {
[email protected]979c28b2009-11-07 01:30:484236 const WebFormElement& form = forms[i];
[email protected]daa8c58e2009-06-15 17:21:104237
4238 // Respect autocomplete=off.
[email protected]979c28b2009-11-07 01:30:484239 if (form.autoComplete()) {
[email protected]daa8c58e2009-06-15 17:21:104240 scoped_ptr<PasswordForm> password_form(
4241 PasswordFormDomManager::CreatePasswordForm(form));
4242 if (password_form.get())
4243 password_forms.push_back(*password_form);
4244 }
4245 }
4246
4247 if (!password_forms.empty())
4248 Send(new ViewHostMsg_PasswordFormsSeen(routing_id_, password_forms));
4249}
[email protected]0fda7272009-06-26 15:49:334250
4251void RenderView::Print(WebFrame* frame, bool script_initiated) {
4252 DCHECK(frame);
4253 if (print_helper_.get() == NULL) {
4254 print_helper_.reset(new PrintWebViewHelper(this));
4255 }
4256 print_helper_->Print(frame, script_initiated);
4257}
[email protected]446705872009-09-10 07:22:484258
4259void RenderView::OnSetEditCommandsForNextKeyEvent(
4260 const EditCommands& edit_commands) {
4261 edit_commands_ = edit_commands;
4262}
4263
[email protected]61f5a7b2009-12-22 22:21:204264void RenderView::OnExecuteCode(const ViewMsg_ExecuteCode_Params& params) {
[email protected]26aa0482009-09-30 16:55:274265 WebFrame* main_frame = webview() ? webview()->mainFrame() : NULL;
[email protected]912256b32009-09-18 09:47:354266 if (!main_frame) {
[email protected]61f5a7b2009-12-22 22:21:204267 Send(new ViewMsg_ExecuteCodeFinished(routing_id_, params.request_id,
4268 false));
[email protected]912256b32009-09-18 09:47:354269 return;
4270 }
4271
[email protected]fa7b6b542009-11-03 05:02:304272 WebDataSource* ds = main_frame->dataSource();
4273 NavigationState* navigation_state = NavigationState::FromDataSource(ds);
4274 if (!navigation_state->user_script_idle_scheduler()->has_run()) {
[email protected]61f5a7b2009-12-22 22:21:204275 pending_code_execution_queue_.push(
4276 linked_ptr<ViewMsg_ExecuteCode_Params>(
4277 new ViewMsg_ExecuteCode_Params(params)));
[email protected]fa7b6b542009-11-03 05:02:304278 return;
4279 }
4280
[email protected]61f5a7b2009-12-22 22:21:204281 ExecuteCodeImpl(main_frame, params);
[email protected]fa7b6b542009-11-03 05:02:304282}
4283
4284void RenderView::ExecuteCodeImpl(WebFrame* frame,
[email protected]61f5a7b2009-12-22 22:21:204285 const ViewMsg_ExecuteCode_Params& params) {
[email protected]d146b832009-12-23 02:45:484286 // Don't execute scripts in gallery pages.
4287 GURL frame_url = GURL(frame->url());
4288 if (frame_url.host() == GURL(extension_urls::kGalleryBrowsePrefix).host()) {
4289 Send(new ViewMsg_ExecuteCodeFinished(routing_id_, params.request_id, true));
4290 return;
4291 }
4292
[email protected]20ad2692009-11-20 18:27:204293 std::vector<WebFrame*> frame_vector;
4294 frame_vector.push_back(frame);
[email protected]61f5a7b2009-12-22 22:21:204295 if (params.all_frames)
[email protected]20ad2692009-11-20 18:27:204296 GetAllChildFrames(frame, &frame_vector);
4297
4298 for (std::vector<WebFrame*>::iterator frame_it = frame_vector.begin();
4299 frame_it != frame_vector.end(); ++frame_it) {
4300 WebFrame* frame = *frame_it;
[email protected]61f5a7b2009-12-22 22:21:204301 if (params.is_javascript) {
4302 if (!UrlMatchesPermissions(frame->url(), params.host_permissions))
4303 continue;
4304
[email protected]20ad2692009-11-20 18:27:204305 std::vector<WebScriptSource> sources;
4306 sources.push_back(
[email protected]61f5a7b2009-12-22 22:21:204307 WebScriptSource(WebString::fromUTF8(params.code)));
4308 UserScriptSlave::InsertInitExtensionCode(&sources, params.extension_id);
[email protected]20ad2692009-11-20 18:27:204309 frame->executeScriptInIsolatedWorld(
[email protected]61f5a7b2009-12-22 22:21:204310 UserScriptSlave::GetIsolatedWorldId(params.extension_id),
[email protected]20ad2692009-11-20 18:27:204311 &sources.front(), sources.size(), EXTENSION_GROUP_CONTENT_SCRIPTS);
4312 } else {
[email protected]61f5a7b2009-12-22 22:21:204313 frame->insertStyleText(WebString::fromUTF8(params.code), WebString());
[email protected]20ad2692009-11-20 18:27:204314 }
[email protected]912256b32009-09-18 09:47:354315 }
4316
[email protected]61f5a7b2009-12-22 22:21:204317 Send(new ViewMsg_ExecuteCodeFinished(routing_id_, params.request_id, true));
[email protected]912256b32009-09-18 09:47:354318}
4319
[email protected]60c42a8c72009-10-09 04:08:594320void RenderView::Close() {
4321 // We need to grab a pointer to the doomed WebView before we destroy it.
4322 WebView* doomed = webview();
4323 RenderWidget::Close();
4324 Singleton<ViewMap>::get()->erase(doomed);
4325}
4326
[email protected]446705872009-09-10 07:22:484327void RenderView::DidHandleKeyEvent() {
4328 edit_commands_.clear();
4329}
4330
[email protected]941e4552010-02-01 21:23:434331#if defined(OS_MACOSX)
4332void RenderView::OnWasHidden() {
4333 RenderWidget::OnWasHidden();
4334
4335 // Inform plugins that their container is no longer visible.
4336 std::set<WebPluginDelegateProxy*>::iterator plugin_it;
4337 for (plugin_it = plugin_delegates_.begin();
4338 plugin_it != plugin_delegates_.end(); ++plugin_it) {
4339 (*plugin_it)->SetContainerVisibility(false);
4340 }
4341}
4342
4343void RenderView::OnWasRestored(bool needs_repainting) {
4344 RenderWidget::OnWasRestored(needs_repainting);
4345
4346 // Inform plugins that their container is now visible.
4347 std::set<WebPluginDelegateProxy*>::iterator plugin_it;
4348 for (plugin_it = plugin_delegates_.begin();
4349 plugin_it != plugin_delegates_.end(); ++plugin_it) {
4350 (*plugin_it)->SetContainerVisibility(true);
4351 }
4352}
[email protected]1e6e3c992010-02-08 15:52:134353
4354void RenderView::OnSetFocus(bool enable) {
4355 RenderWidget::OnSetFocus(enable);
4356
4357 // RenderWidget's call to setFocus can cause the underlying webview's
4358 // activation state to change just like a call to setIsActive.
4359 if (enable && webview() && webview()->isActive()) {
4360 std::set<WebPluginDelegateProxy*>::iterator plugin_it;
4361 for (plugin_it = plugin_delegates_.begin();
4362 plugin_it != plugin_delegates_.end(); ++plugin_it) {
4363 (*plugin_it)->SetWindowFocus(true);
4364 }
4365 }
4366}
[email protected]941e4552010-02-01 21:23:434367#endif // OS_MACOSX
4368
[email protected]83dde542009-09-11 20:59:554369void RenderView::EnsureDocumentTag() {
4370 // TODO(darin): There's actually no reason for this to be here. We should
4371 // have the browser side manage the document tag.
4372#if defined(OS_MACOSX)
4373 if (!has_document_tag_) {
4374 // Make the call to get the tag.
4375 Send(new ViewHostMsg_GetDocumentTag(routing_id_, &document_tag_));
4376 has_document_tag_ = true;
4377 }
4378#endif
4379}
[email protected]12636df2009-09-28 22:32:214380
4381bool RenderView::SendAndRunNestedMessageLoop(IPC::SyncMessage* message) {
[email protected]8beff0762009-09-29 02:18:304382 PluginChannelHost::Broadcast(
4383 new PluginMsg_SignalModalDialogEvent(host_window_));
[email protected]12636df2009-09-28 22:32:214384
4385 message->EnableMessagePumping(); // Runs a nested message loop.
4386 bool rv = Send(message);
4387
[email protected]8beff0762009-09-29 02:18:304388 PluginChannelHost::Broadcast(
4389 new PluginMsg_ResetModalDialogEvent(host_window_));
[email protected]12636df2009-09-28 22:32:214390
4391 return rv;
4392}
[email protected]43f28f832010-02-03 02:28:484393
4394#if defined(OS_MACOSX)
4395gfx::PluginWindowHandle RenderView::AllocateFakePluginWindowHandle() {
4396 gfx::PluginWindowHandle window = NULL;
4397 Send(new ViewHostMsg_AllocateFakePluginWindowHandle(
4398 routing_id(), &window));
4399 return window;
4400}
4401
4402void RenderView::DestroyFakePluginWindowHandle(gfx::PluginWindowHandle window) {
4403 if (window)
4404 Send(new ViewHostMsg_DestroyFakePluginWindowHandle(routing_id(), window));
4405}
4406
4407void RenderView::GPUPluginSetIOSurface(gfx::PluginWindowHandle window,
4408 int32 width,
4409 int32 height,
4410 uint64 io_surface_identifier) {
4411 Send(new ViewHostMsg_GPUPluginSetIOSurface(
4412 routing_id(), window, width, height, io_surface_identifier));
4413}
4414
4415void RenderView::GPUPluginBuffersSwapped(gfx::PluginWindowHandle window) {
4416 Send(new ViewHostMsg_GPUPluginBuffersSwapped(routing_id(), window));
4417}
4418#endif