blob: 8acdcaf3f54560557c9183ab88de13888ed9d04f [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"
[email protected]2041cf342010-02-19 03:15:5917#include "base/callback.h"
initial.commit09911bf2008-07-26 23:55:2918#include "base/command_line.h"
[email protected]bb063b72009-03-27 23:18:5019#include "base/compiler_specific.h"
[email protected]4646f292009-05-20 03:49:0520#include "base/field_trial.h"
[email protected]30507922010-01-15 16:48:2321#include "base/histogram.h"
[email protected]8380c092009-06-25 17:45:5122#include "base/process_util.h"
[email protected]7b291f92009-08-14 05:43:5323#include "base/singleton.h"
initial.commit09911bf2008-07-26 23:55:2924#include "base/string_piece.h"
25#include "base/string_util.h"
[email protected]30507922010-01-15 16:48:2326#include "base/time.h"
[email protected]6c8afae52009-01-22 02:24:5727#include "build/build_config.h"
[email protected]81e63782009-02-27 19:35:0928#include "chrome/common/bindings_policy.h"
[email protected]ef916272009-07-08 21:40:5529#include "chrome/common/child_process_logging.h"
initial.commit09911bf2008-07-26 23:55:2930#include "chrome/common/chrome_switches.h"
[email protected]f0af6a72009-05-30 05:25:1731#include "chrome/common/chrome_constants.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]e09ba552009-02-05 03:26:2935#include "chrome/common/render_messages.h"
[email protected]9b6f40e2009-06-11 15:54:2636#include "chrome/common/renderer_preferences.h"
initial.commit09911bf2008-07-26 23:55:2937#include "chrome/common/thumbnail_score.h"
[email protected]6de74452009-02-25 18:04:5938#include "chrome/common/url_constants.h"
initial.commit09911bf2008-07-26 23:55:2939#include "chrome/renderer/about_handler.h"
[email protected]5fb88962009-04-16 19:03:2540#include "chrome/renderer/audio_message_filter.h"
[email protected]e4ac5df2009-03-17 15:33:1141#include "chrome/renderer/devtools_agent.h"
42#include "chrome/renderer/devtools_client.h"
[email protected]912256b32009-09-18 09:47:3543#include "chrome/renderer/extension_groups.h"
[email protected]f816c012009-06-26 21:48:3244#include "chrome/renderer/extensions/event_bindings.h"
[email protected]0f6053962009-07-09 19:26:3545#include "chrome/renderer/extensions/extension_process_bindings.h"
[email protected]7120f132009-07-20 21:05:3746#include "chrome/renderer/extensions/renderer_extension_bindings.h"
[email protected]58c321d2010-02-19 12:11:2847#include "chrome/renderer/geolocation_dispatcher.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]8400e032010-02-26 18:50:1150#include "chrome/renderer/media/ipc_video_renderer.h"
[email protected]ed3fb032009-06-16 19:50:5651#include "chrome/renderer/navigation_state.h"
[email protected]90e908552009-10-05 01:40:1252#include "chrome/renderer/notification_provider.h"
[email protected]8beff0762009-09-29 02:18:3053#include "chrome/renderer/plugin_channel_host.h"
[email protected]d81c1e52009-06-03 22:09:5054#include "chrome/renderer/print_web_view_helper.h"
[email protected]39008c02009-02-11 23:59:2555#include "chrome/renderer/render_process.h"
[email protected]00c39612010-03-06 02:53:2856#include "chrome/renderer/render_thread.h"
[email protected]bd92c3a2010-01-13 05:02:3457#include "chrome/renderer/renderer_webstoragenamespace_impl.h"
[email protected]85c55dc2009-11-06 03:05:4658#include "chrome/renderer/spellchecker/spellcheck.h"
[email protected]0938d3c2009-01-09 20:37:3559#include "chrome/renderer/user_script_slave.h"
initial.commit09911bf2008-07-26 23:55:2960#include "chrome/renderer/visitedlink_slave.h"
[email protected]d439ba072009-10-17 22:32:2961#include "chrome/renderer/webplugin_delegate_pepper.h"
[email protected]ba4b17f2009-02-11 21:32:2962#include "chrome/renderer/webplugin_delegate_proxy.h"
[email protected]9c00f002009-11-05 22:37:4263#include "chrome/renderer/websharedworker_proxy.h"
[email protected]eb47a132009-03-04 00:39:5664#include "chrome/renderer/webworker_proxy.h"
[email protected]34ac8f32009-02-22 23:03:2765#include "grit/generated_resources.h"
66#include "grit/renderer_resources.h"
[email protected]f11ca0732009-04-11 00:09:3467#include "net/base/data_url.h"
initial.commit09911bf2008-07-26 23:55:2968#include "net/base/escape.h"
69#include "net/base/net_errors.h"
[email protected]c399a8a2008-11-22 19:38:0070#include "skia/ext/bitmap_platform_device.h"
[email protected]83c9e6552008-12-03 16:22:1071#include "skia/ext/image_operations.h"
[email protected]651272792010-02-04 23:16:3072#include "third_party/cld/encodings/compact_lang_det/win/cld_unicodetext.h"
[email protected]58c321d2010-02-19 12:11:2873#include "third_party/WebKit/WebKit/chromium/public/GeolocationServiceBridgeChromium.h"
[email protected]418ed5ab2009-11-12 01:14:4974#include "third_party/WebKit/WebKit/chromium/public/WebAccessibilityCache.h"
75#include "third_party/WebKit/WebKit/chromium/public/WebAccessibilityObject.h"
[email protected]d9ec5c0f2009-12-23 11:55:0776#include "third_party/WebKit/WebKit/chromium/public/WebCString.h"
[email protected]418ed5ab2009-11-12 01:14:4977#include "third_party/WebKit/WebKit/chromium/public/WebDataSource.h"
78#include "third_party/WebKit/WebKit/chromium/public/WebDevToolsAgent.h"
[email protected]0bedb8a2010-01-14 19:36:3279#include "third_party/WebKit/WebKit/chromium/public/WebDocument.h"
[email protected]418ed5ab2009-11-12 01:14:4980#include "third_party/WebKit/WebKit/chromium/public/WebDragData.h"
[email protected]01178b52010-01-15 06:59:3581#include "third_party/WebKit/WebKit/chromium/public/WebFileChooserParams.h"
[email protected]418ed5ab2009-11-12 01:14:4982#include "third_party/WebKit/WebKit/chromium/public/WebFormElement.h"
83#include "third_party/WebKit/WebKit/chromium/public/WebFrame.h"
84#include "third_party/WebKit/WebKit/chromium/public/WebHistoryItem.h"
[email protected]95056b582010-02-18 01:29:2485#include "third_party/WebKit/WebKit/chromium/public/WebInputElement.h"
[email protected]418ed5ab2009-11-12 01:14:4986#include "third_party/WebKit/WebKit/chromium/public/WebNode.h"
[email protected]0bedb8a2010-01-14 19:36:3287#include "third_party/WebKit/WebKit/chromium/public/WebNodeList.h"
[email protected]d9ec5c0f2009-12-23 11:55:0788#include "third_party/WebKit/WebKit/chromium/public/WebPageSerializer.h"
[email protected]418ed5ab2009-11-12 01:14:4989#include "third_party/WebKit/WebKit/chromium/public/WebPoint.h"
90#include "third_party/WebKit/WebKit/chromium/public/WebRange.h"
91#include "third_party/WebKit/WebKit/chromium/public/WebRect.h"
92#include "third_party/WebKit/WebKit/chromium/public/WebScriptSource.h"
93#include "third_party/WebKit/WebKit/chromium/public/WebSearchableFormData.h"
94#include "third_party/WebKit/WebKit/chromium/public/WebSecurityOrigin.h"
95#include "third_party/WebKit/WebKit/chromium/public/WebSize.h"
[email protected]bd92c3a2010-01-13 05:02:3496#include "third_party/WebKit/WebKit/chromium/public/WebStorageNamespace.h"
[email protected]418ed5ab2009-11-12 01:14:4997#include "third_party/WebKit/WebKit/chromium/public/WebString.h"
98#include "third_party/WebKit/WebKit/chromium/public/WebURL.h"
99#include "third_party/WebKit/WebKit/chromium/public/WebURLError.h"
100#include "third_party/WebKit/WebKit/chromium/public/WebURLRequest.h"
101#include "third_party/WebKit/WebKit/chromium/public/WebURLResponse.h"
102#include "third_party/WebKit/WebKit/chromium/public/WebVector.h"
[email protected]80f584d92010-01-21 03:59:04103#include "webkit/appcache/web_application_cache_host_impl.h"
[email protected]ba4b17f2009-02-11 21:32:29104#include "webkit/default_plugin/default_plugin_shared.h"
initial.commit09911bf2008-07-26 23:55:29105#include "webkit/glue/dom_operations.h"
[email protected]95056b582010-02-18 01:29:24106#include "webkit/glue/form_field.h"
107#include "webkit/glue/form_field_values.h"
108#include "webkit/glue/glue_serialize.h"
[email protected]f11ca0732009-04-11 00:09:34109#include "webkit/glue/image_decoder.h"
[email protected]8e296bbd2009-07-22 21:37:17110#include "webkit/glue/media/buffered_data_source.h"
[email protected]8380c092009-06-25 17:45:51111#include "webkit/glue/media/simple_data_source.h"
initial.commit09911bf2008-07-26 23:55:29112#include "webkit/glue/password_form.h"
[email protected]ba4b17f2009-02-11 21:32:29113#include "webkit/glue/plugins/plugin_list.h"
[email protected]8a3b7962009-09-04 05:53:23114#include "webkit/glue/plugins/webplugin_delegate_impl.h"
[email protected]8400e032010-02-26 18:50:11115#include "webkit/glue/media/video_renderer_impl.h"
initial.commit09911bf2008-07-26 23:55:29116#include "webkit/glue/webdropdata.h"
initial.commit09911bf2008-07-26 23:55:29117#include "webkit/glue/webkit_glue.h"
[email protected]add51772009-06-11 18:25:17118#include "webkit/glue/webmediaplayer_impl.h"
[email protected]f103ab72009-09-02 17:10:59119#include "webkit/glue/webplugin_impl.h"
initial.commit09911bf2008-07-26 23:55:29120
[email protected]6c8afae52009-01-22 02:24:57121#if defined(OS_WIN)
122// TODO(port): these files are currently Windows only because they concern:
[email protected]6c8afae52009-01-22 02:24:57123// * theming
[email protected]86281ad2009-10-07 20:07:17124#include "app/gfx/native_theme_win.h"
[email protected]39cd64ed2010-02-05 02:18:46125#elif defined(OS_LINUX)
126#include "third_party/WebKit/WebKit/chromium/public/linux/WebRenderTheme.h"
[email protected]6c8afae52009-01-22 02:24:57127#endif
128
[email protected]80f584d92010-01-21 03:59:04129using appcache::WebApplicationCacheHostImpl;
[email protected]c20210e62009-04-03 21:39:26130using base::Time;
[email protected]e1acf6f2008-10-27 20:43:33131using base::TimeDelta;
[email protected]15d79e12009-08-02 19:23:45132using webkit_glue::AltErrorPageResourceFetcher;
[email protected]95056b582010-02-18 01:29:24133using webkit_glue::FormField;
[email protected]51bd36612009-10-20 22:49:47134using webkit_glue::FormFieldValues;
[email protected]b0950a72009-09-29 23:16:17135using webkit_glue::ImageResourceFetcher;
[email protected]ed3fb032009-06-16 19:50:56136using webkit_glue::PasswordForm;
[email protected]daa8c58e2009-06-15 17:21:10137using webkit_glue::PasswordFormDomManager;
[email protected]c7287a92009-11-04 20:06:15138using WebKit::WebAccessibilityCache;
[email protected]cc0445f2009-10-13 16:09:08139using WebKit::WebAccessibilityObject;
[email protected]1c83eb42009-09-11 21:08:41140using WebKit::WebColor;
141using WebKit::WebColorName;
[email protected]0dea3ea2009-03-31 23:30:59142using WebKit::WebConsoleMessage;
[email protected]79e37442009-10-09 18:17:44143using WebKit::WebContextMenuData;
[email protected]b921cfd22010-02-25 16:57:51144using WebKit::WebCookieJar;
[email protected]d9ec5c0f2009-12-23 11:55:07145using WebKit::WebCString;
[email protected]e6f546c32009-07-01 17:12:55146using WebKit::WebData;
[email protected]726985e22009-06-18 21:09:28147using WebKit::WebDataSource;
[email protected]2661b332009-11-03 18:42:29148using WebKit::WebDevToolsAgent;
[email protected]e80c73b2009-04-07 23:24:58149using WebKit::WebDragData;
[email protected]1d9f4132009-09-08 17:29:25150using WebKit::WebDragOperation;
151using WebKit::WebDragOperationsMask;
[email protected]79dbc662009-09-04 05:42:51152using WebKit::WebEditingAction;
[email protected]6069da8c2009-10-20 20:33:49153using WebKit::WebFindOptions;
[email protected]979c28b2009-11-07 01:30:48154using WebKit::WebFormElement;
[email protected]dd7daa82009-08-10 05:46:45155using WebKit::WebFrame;
[email protected]ca948a22009-06-25 19:36:17156using WebKit::WebHistoryItem;
[email protected]95056b582010-02-18 01:29:24157using WebKit::WebInputElement;
[email protected]3d9689372009-09-10 04:29:17158using WebKit::WebMediaPlayer;
[email protected]952cb702009-10-07 05:50:28159using WebKit::WebMediaPlayerAction;
[email protected]3d9689372009-09-10 04:29:17160using WebKit::WebMediaPlayerClient;
[email protected]4873c7d2009-07-16 06:36:28161using WebKit::WebNavigationPolicy;
[email protected]726985e22009-06-18 21:09:28162using WebKit::WebNavigationType;
[email protected]79dbc662009-09-04 05:42:51163using WebKit::WebNode;
[email protected]d9ec5c0f2009-12-23 11:55:07164using WebKit::WebPageSerializer;
165using WebKit::WebPageSerializerClient;
[email protected]3d9689372009-09-10 04:29:17166using WebKit::WebPlugin;
167using WebKit::WebPluginParams;
[email protected]48c9cf2d2009-09-16 16:47:52168using WebKit::WebPoint;
[email protected]88efb7ec2009-07-14 16:32:59169using WebKit::WebPopupMenuInfo;
[email protected]79dbc662009-09-04 05:42:51170using WebKit::WebRange;
[email protected]b3f2b912009-04-09 16:18:52171using WebKit::WebRect;
[email protected]4f999132009-03-31 18:08:40172using WebKit::WebScriptSource;
[email protected]ce0e250d2009-10-23 21:00:35173using WebKit::WebSearchableFormData;
[email protected]e3d60e5d2009-09-25 21:08:29174using WebKit::WebSecurityOrigin;
[email protected]2fab253a2009-08-17 23:00:59175using WebKit::WebSettings;
[email protected]9c00f002009-11-05 22:37:42176using WebKit::WebSharedWorker;
[email protected]8649fb32009-06-26 17:51:02177using WebKit::WebSize;
[email protected]bd92c3a2010-01-13 05:02:34178using WebKit::WebStorageNamespace;
[email protected]726985e22009-06-18 21:09:28179using WebKit::WebString;
[email protected]79dbc662009-09-04 05:42:51180using WebKit::WebTextAffinity;
[email protected]de570ef2009-07-29 18:27:52181using WebKit::WebTextDirection;
[email protected]726985e22009-06-18 21:09:28182using WebKit::WebURL;
183using WebKit::WebURLError;
184using WebKit::WebURLRequest;
185using WebKit::WebURLResponse;
[email protected]4873c7d2009-07-16 06:36:28186using WebKit::WebVector;
[email protected]50ae00ef2009-10-19 05:11:03187using WebKit::WebView;
[email protected]4873c7d2009-07-16 06:36:28188using WebKit::WebWidget;
[email protected]27ba8532009-04-24 20:22:43189using WebKit::WebWorker;
190using WebKit::WebWorkerClient;
[email protected]e1acf6f2008-10-27 20:43:33191
initial.commit09911bf2008-07-26 23:55:29192//-----------------------------------------------------------------------------
193
194// define to write the time necessary for thumbnail/DOM text retrieval,
195// respectively, into the system debug log
initial.commit09911bf2008-07-26 23:55:29196// #define TIME_TEXT_RETRIEVAL
197
198// maximum number of characters in the document to index, any text beyond this
199// point will be clipped
[email protected]6c8afae52009-01-22 02:24:57200static const size_t kMaxIndexChars = 65535;
initial.commit09911bf2008-07-26 23:55:29201
202// Size of the thumbnails that we'll generate
[email protected]8b4f4892009-09-04 21:52:37203static const int kThumbnailWidth = 212;
204static const int kThumbnailHeight = 132;
initial.commit09911bf2008-07-26 23:55:29205
206// Delay in milliseconds that we'll wait before capturing the page contents
207// and thumbnail.
208static const int kDelayForCaptureMs = 500;
209
210// Typically, we capture the page data once the page is loaded.
211// Sometimes, the page never finishes to load, preventing the page capture
212// To workaround this problem, we always perform a capture after the following
213// delay.
214static const int kDelayForForcedCaptureMs = 6000;
215
[email protected]882daa92009-11-05 16:31:31216// Time, in seconds, we delay before sending content state changes (such as form
217// state and scroll position) to the browser. We delay sending changes to avoid
218// spamming the browser.
219// To avoid having tab/session restore require sending a message to get the
220// current content state during tab closing we use a shorter timeout for the
221// foreground renderer. This means there is a small window of time from which
222// content state is modified and not sent to session restore, but this is
223// better than having to wake up all renderers during shutdown.
224static const int kDelaySecondsForContentStateSyncHidden = 5;
225static const int kDelaySecondsForContentStateSync = 1;
initial.commit09911bf2008-07-26 23:55:29226
[email protected]0aa55312008-10-17 21:53:08227// The maximum number of popups that can be spawned from one page.
228static const int kMaximumNumberOfUnacknowledgedPopups = 25;
229
initial.commit09911bf2008-07-26 23:55:29230static const char* const kUnreachableWebDataURL =
[email protected]60e448982009-05-06 04:21:16231 "chrome://chromewebdata/";
initial.commit09911bf2008-07-26 23:55:29232
[email protected]50b691c2008-10-31 19:08:35233static const char* const kBackForwardNavigationScheme = "history";
234
[email protected]8c4cdd42010-01-12 21:31:13235// The string returned in DetectLanguage if we failed to detect the language.
[email protected]8dc5a2052010-01-19 21:32:42236static const char* const kUnknownLanguageCode = "und";
[email protected]8c4cdd42010-01-12 21:31:13237
[email protected]726985e22009-06-18 21:09:28238static void GetRedirectChain(WebDataSource* ds, std::vector<GURL>* result) {
239 WebVector<WebURL> urls;
240 ds->redirectChain(urls);
241 result->reserve(urls.size());
242 for (size_t i = 0; i < urls.size(); ++i)
243 result->push_back(urls[i]);
244}
245
[email protected]61f5a7b2009-12-22 22:21:20246static bool UrlMatchesPermissions(
247 const GURL& url, const std::vector<URLPattern>& host_permissions) {
248 for (size_t i = 0; i < host_permissions.size(); ++i) {
249 if (host_permissions[i].MatchesUrl(url))
250 return true;
251 }
252
253 return false;
254}
255
[email protected]30507922010-01-15 16:48:23256static bool PaintViewIntoCanvas(WebView* view,
257 skia::PlatformCanvas& canvas) {
258 view->layout();
259 const WebSize& size = view->size();
260
261 if (!canvas.initialize(size.width, size.height, true))
262 return false;
263
264 view->paint(webkit_glue::ToWebCanvas(&canvas),
265 WebRect(0, 0, size.width, size.height));
266 // TODO: Add a way to snapshot the whole page, not just the currently
267 // visible part.
268
269 return true;
270}
271
272// Calculates how "boring" a thumbnail is. The boring score is the
273// 0,1 ranged percentage of pixels that are the most common
274// luma. Higher boring scores indicate that a higher percentage of a
275// bitmap are all the same brightness.
276static double CalculateBoringScore(SkBitmap* bitmap) {
277 int histogram[256] = {0};
278 color_utils::BuildLumaHistogram(bitmap, histogram);
279
280 int color_count = *std::max_element(histogram, histogram + 256);
281 int pixel_count = bitmap->width() * bitmap->height();
282 return static_cast<double>(color_count) / pixel_count;
283}
284
initial.commit09911bf2008-07-26 23:55:29285///////////////////////////////////////////////////////////////////////////////
286
[email protected]60c42a8c72009-10-09 04:08:59287int32 RenderView::next_page_id_ = 1;
288
[email protected]2fab253a2009-08-17 23:00:59289RenderView::RenderView(RenderThreadBase* render_thread,
[email protected]4e6419c2010-01-15 04:50:34290 const WebPreferences& webkit_preferences,
291 int64 session_storage_namespace_id)
[email protected]81a34412009-01-05 19:17:24292 : RenderWidget(render_thread, true),
[email protected]81e63782009-02-27 19:35:09293 enabled_bindings_(0),
[email protected]e75cb49e2009-01-05 23:13:21294 target_url_status_(TARGET_NONE),
[email protected]81a34412009-01-05 19:17:24295 is_loading_(false),
[email protected]e75cb49e2009-01-05 23:13:21296 navigation_gesture_(NavigationGestureUnknown),
[email protected]81a34412009-01-05 19:17:24297 page_id_(-1),
298 last_page_id_sent_to_browser_(-1),
299 last_indexed_page_id_(-1),
[email protected]81a34412009-01-05 19:17:24300 opened_by_user_gesture_(true),
[email protected]007a848b2009-10-26 15:55:46301 opener_suppressed_(false),
[email protected]bb063b72009-03-27 23:18:50302 ALLOW_THIS_IN_INITIALIZER_LIST(method_factory_(this)),
[email protected]e4ac5df2009-03-17 15:33:11303 devtools_agent_(NULL),
304 devtools_client_(NULL),
[email protected]a1128322009-10-06 18:38:46305 file_chooser_completion_(NULL),
[email protected]81a34412009-01-05 19:17:24306 history_back_list_count_(0),
307 history_forward_list_count_(0),
[email protected]81a34412009-01-05 19:17:24308 has_unload_listener_(false),
309 decrement_shared_popup_at_destruction_(false),
[email protected]acca2a1f2009-10-16 03:53:39310 autofill_query_id_(0),
[email protected]81a34412009-01-05 19:17:24311 popup_notification_visible_(false),
[email protected]8922e1f2009-10-03 05:01:26312 spelling_panel_visible_(false),
[email protected]882daa92009-11-05 16:31:31313 send_content_state_immediately_(false),
[email protected]ab32b16c2009-10-16 14:57:25314 send_preferred_size_changes_(false),
[email protected]b6849bda2009-10-14 23:59:26315 ALLOW_THIS_IN_INITIALIZER_LIST(
316 notification_provider_(new NotificationProvider(this))),
[email protected]7b291f92009-08-14 05:43:53317 view_type_(ViewType::INVALID),
318 browser_window_id_(-1),
[email protected]83dde542009-09-11 20:59:55319 last_top_level_navigation_page_id_(-1),
320#if defined(OS_MACOSX)
321 has_document_tag_(false),
322#endif
[email protected]98324892009-09-09 21:16:05323 document_tag_(0),
[email protected]0bedb8a2010-01-14 19:36:32324 webkit_preferences_(webkit_preferences),
[email protected]4e6419c2010-01-15 04:50:34325 session_storage_namespace_id_(session_storage_namespace_id),
[email protected]b921cfd22010-02-25 16:57:51326 ALLOW_THIS_IN_INITIALIZER_LIST(text_translator_(this)),
327 ALLOW_THIS_IN_INITIALIZER_LIST(cookie_jar_(this)) {
[email protected]71b0d5d2010-02-15 05:43:07328 ClearBlockedContentSettings();
[email protected]7e0831b2010-02-01 08:45:15329 page_translator_.reset(new PageTranslator(&text_translator_, this));
initial.commit09911bf2008-07-26 23:55:29330}
331
332RenderView::~RenderView() {
[email protected]0aa55312008-10-17 21:53:08333 if (decrement_shared_popup_at_destruction_)
334 shared_popup_counter_->data--;
335
[email protected]b0950a72009-09-29 23:16:17336 // Dispose of un-disposed image fetchers.
337 for (ImageResourceFetcherSet::iterator i = image_fetchers_.begin();
338 i != image_fetchers_.end(); ++i) {
339 delete *i;
340 }
341
[email protected]a1128322009-10-06 18:38:46342 // If file chooser is still waiting for answer, dispatch empty answer.
343 if (file_chooser_completion_)
344 file_chooser_completion_->didChooseFile(WebVector<WebString>());
345
[email protected]83dde542009-09-11 20:59:55346#if defined(OS_MACOSX)
[email protected]98324892009-09-09 21:16:05347 // Tell the spellchecker that the document is closed.
[email protected]83dde542009-09-11 20:59:55348 if (has_document_tag_)
349 Send(new ViewHostMsg_DocumentWithTagClosed(routing_id_, document_tag_));
350#endif
[email protected]98324892009-09-09 21:16:05351
[email protected]5fb88962009-04-16 19:03:25352 render_thread_->RemoveFilter(audio_message_filter_);
[email protected]60c42a8c72009-10-09 04:08:59353
354#ifndef NDEBUG
355 // Make sure we are no longer referenced by the ViewMap.
356 ViewMap* views = Singleton<ViewMap>::get();
357 for (ViewMap::iterator it = views->begin(); it != views->end(); ++it)
358 DCHECK_NE(this, it->second) << "Failed to call Close?";
359#endif
360}
361
362/*static*/
363void RenderView::ForEach(RenderViewVisitor* visitor) {
364 ViewMap* views = Singleton<ViewMap>::get();
365 for (ViewMap::iterator it = views->begin(); it != views->end(); ++it) {
366 if (!visitor->Visit(it->second))
367 return;
368 }
369}
370
371/*static*/
372RenderView* RenderView::FromWebView(WebView* webview) {
373 ViewMap* views = Singleton<ViewMap>::get();
374 ViewMap::iterator it = views->find(webview);
375 return it == views->end() ? NULL : it->second;
initial.commit09911bf2008-07-26 23:55:29376}
377
378/*static*/
[email protected]0aa55312008-10-17 21:53:08379RenderView* RenderView::Create(
[email protected]81a34412009-01-05 19:17:24380 RenderThreadBase* render_thread,
[email protected]18bcc3c2009-01-27 21:39:15381 gfx::NativeViewId parent_hwnd,
[email protected]0aa55312008-10-17 21:53:08382 int32 opener_id,
[email protected]80d96fa2009-06-10 22:34:51383 const RendererPreferences& renderer_prefs,
[email protected]0aa55312008-10-17 21:53:08384 const WebPreferences& webkit_prefs,
385 SharedRenderViewCounter* counter,
[email protected]4e6419c2010-01-15 04:50:34386 int32 routing_id,
387 int64 session_storage_namespace_id) {
initial.commit09911bf2008-07-26 23:55:29388 DCHECK(routing_id != MSG_ROUTING_NONE);
[email protected]4e6419c2010-01-15 04:50:34389 scoped_refptr<RenderView> view = new RenderView(render_thread, webkit_prefs,
390 session_storage_namespace_id);
initial.commit09911bf2008-07-26 23:55:29391 view->Init(parent_hwnd,
initial.commit09911bf2008-07-26 23:55:29392 opener_id,
[email protected]80d96fa2009-06-10 22:34:51393 renderer_prefs,
[email protected]0aa55312008-10-17 21:53:08394 counter,
initial.commit09911bf2008-07-26 23:55:29395 routing_id); // adds reference
396 return view;
397}
398
399/*static*/
400void RenderView::SetNextPageID(int32 next_page_id) {
401 // This method should only be called during process startup, and the given
402 // page id had better not exceed our current next page id!
[email protected]4646f292009-05-20 03:49:05403 DCHECK_EQ(next_page_id_, 1);
initial.commit09911bf2008-07-26 23:55:29404 DCHECK(next_page_id >= next_page_id_);
405 next_page_id_ = next_page_id;
406}
407
[email protected]afe3a1672009-11-17 19:04:12408void RenderView::UserMetricsRecordAction(const std::string& action) {
[email protected]1dbafaf72009-09-23 19:43:56409 Send(new ViewHostMsg_UserMetricsRecordAction(routing_id_, action));
410}
411
[email protected]a3a8fb6d2009-10-22 20:12:51412void RenderView::PluginCrashed(const FilePath& plugin_path) {
413 Send(new ViewHostMsg_CrashedPlugin(routing_id_, plugin_path));
initial.commit09911bf2008-07-26 23:55:29414}
415
[email protected]d8fd6fa2010-02-01 15:54:26416#if defined(OS_MACOSX)
417void RenderView::RegisterPluginDelegate(WebPluginDelegateProxy* delegate) {
418 plugin_delegates_.insert(delegate);
419}
420
421void RenderView::UnregisterPluginDelegate(WebPluginDelegateProxy* delegate) {
422 plugin_delegates_.erase(delegate);
423}
424#endif
425
[email protected]18bcc3c2009-01-27 21:39:15426void RenderView::Init(gfx::NativeViewId parent_hwnd,
initial.commit09911bf2008-07-26 23:55:29427 int32 opener_id,
[email protected]80d96fa2009-06-10 22:34:51428 const RendererPreferences& renderer_prefs,
[email protected]0aa55312008-10-17 21:53:08429 SharedRenderViewCounter* counter,
initial.commit09911bf2008-07-26 23:55:29430 int32 routing_id) {
431 DCHECK(!webview());
432
433 if (opener_id != MSG_ROUTING_NONE)
434 opener_id_ = opener_id;
435
[email protected]0aa55312008-10-17 21:53:08436 if (counter) {
437 shared_popup_counter_ = counter;
438 shared_popup_counter_->data++;
439 decrement_shared_popup_at_destruction_ = true;
440 } else {
441 shared_popup_counter_ = new SharedRenderViewCounter(0);
442 decrement_shared_popup_at_destruction_ = false;
443 }
444
[email protected]58bfc6b2009-06-24 09:45:02445 devtools_agent_.reset(new DevToolsAgent(routing_id, this));
[email protected]9b9d7282009-04-08 14:13:04446
[email protected]50ae00ef2009-10-19 05:11:03447 webwidget_ = WebView::create(this);
[email protected]60c42a8c72009-10-09 04:08:59448 Singleton<ViewMap>::get()->insert(std::make_pair(webview(), this));
[email protected]2fab253a2009-08-17 23:00:59449 webkit_preferences_.Apply(webview());
[email protected]b4bb2502009-10-01 22:35:27450 webview()->initializeMainFrame(this);
[email protected]2661b332009-11-03 18:42:29451 webview()->setDevToolsAgent(
452 WebDevToolsAgent::create(webview(), devtools_agent_.get()));
initial.commit09911bf2008-07-26 23:55:29453
[email protected]d3ba77272009-09-03 00:06:09454 OnSetRendererPrefs(renderer_prefs);
455
initial.commit09911bf2008-07-26 23:55:29456 routing_id_ = routing_id;
[email protected]81a34412009-01-05 19:17:24457 render_thread_->AddRoute(routing_id_, this);
initial.commit09911bf2008-07-26 23:55:29458 // Take a reference on behalf of the RenderThread. This will be balanced
459 // when we receive ViewMsg_Close.
460 AddRef();
461
462 // If this is a popup, we must wait for the CreatingNew_ACK message before
463 // completing initialization. Otherwise, we can finish it now.
464 if (opener_id == MSG_ROUTING_NONE) {
465 did_show_ = true;
466 CompleteInit(parent_hwnd);
467 }
468
469 host_window_ = parent_hwnd;
initial.commit09911bf2008-07-26 23:55:29470
[email protected]58bfc6b2009-06-24 09:45:02471 const CommandLine& command_line = *CommandLine::ForCurrentProcess();
[email protected]81e63782009-02-27 19:35:09472 if (command_line.HasSwitch(switches::kDomAutomationController))
473 enabled_bindings_ |= BindingsPolicy::DOM_AUTOMATION;
initial.commit09911bf2008-07-26 23:55:29474
[email protected]5fb88962009-04-16 19:03:25475 audio_message_filter_ = new AudioMessageFilter(routing_id_);
476 render_thread_->AddFilter(audio_message_filter_);
initial.commit09911bf2008-07-26 23:55:29477}
478
479void RenderView::OnMessageReceived(const IPC::Message& message) {
[email protected]26aa0482009-09-30 16:55:27480 WebFrame* main_frame = webview() ? webview()->mainFrame() : NULL;
[email protected]a9f607e2009-10-23 19:59:27481 if (main_frame)
482 child_process_logging::SetActiveURL(main_frame->url());
[email protected]f8b6b6f2009-03-10 16:48:26483
[email protected]b2abac72009-02-26 12:39:28484 // If this is developer tools renderer intercept tools messages first.
[email protected]e4ac5df2009-03-17 15:33:11485 if (devtools_client_.get() && devtools_client_->OnMessageReceived(message))
[email protected]b2abac72009-02-26 12:39:28486 return;
[email protected]b4b967e2009-04-22 11:33:05487 if (devtools_agent_.get() && devtools_agent_->OnMessageReceived(message))
488 return;
[email protected]b6849bda2009-10-14 23:59:26489 if (notification_provider_->OnMessageReceived(message))
490 return;
[email protected]58c321d2010-02-19 12:11:28491 if (geolocation_dispatcher_.get() &&
492 geolocation_dispatcher_->OnMessageReceived(message)) {
493 return;
494 }
[email protected]b2abac72009-02-26 12:39:28495
initial.commit09911bf2008-07-26 23:55:29496 IPC_BEGIN_MESSAGE_MAP(RenderView, message)
initial.commit09911bf2008-07-26 23:55:29497 IPC_MESSAGE_HANDLER(ViewMsg_CaptureThumbnail, SendThumbnail)
[email protected]30507922010-01-15 16:48:23498 IPC_MESSAGE_HANDLER(ViewMsg_CaptureSnapshot, SendSnapshot)
initial.commit09911bf2008-07-26 23:55:29499 IPC_MESSAGE_HANDLER(ViewMsg_PrintPages, OnPrintPages)
[email protected]82270452009-06-19 15:58:01500 IPC_MESSAGE_HANDLER(ViewMsg_PrintingDone, OnPrintingDone)
initial.commit09911bf2008-07-26 23:55:29501 IPC_MESSAGE_HANDLER(ViewMsg_Navigate, OnNavigate)
502 IPC_MESSAGE_HANDLER(ViewMsg_Stop, OnStop)
[email protected]1dda4022010-01-28 18:24:56503 IPC_MESSAGE_HANDLER(ViewMsg_ReloadFrame, OnReloadFrame)
initial.commit09911bf2008-07-26 23:55:29504 IPC_MESSAGE_HANDLER(ViewMsg_LoadAlternateHTMLText, OnLoadAlternateHTMLText)
505 IPC_MESSAGE_HANDLER(ViewMsg_StopFinding, OnStopFinding)
506 IPC_MESSAGE_HANDLER(ViewMsg_Undo, OnUndo)
507 IPC_MESSAGE_HANDLER(ViewMsg_Redo, OnRedo)
508 IPC_MESSAGE_HANDLER(ViewMsg_Cut, OnCut)
509 IPC_MESSAGE_HANDLER(ViewMsg_Copy, OnCopy)
[email protected]c0cc3092009-09-12 08:27:27510#if defined(OS_MACOSX)
[email protected]a954bf72009-09-12 07:30:35511 IPC_MESSAGE_HANDLER(ViewMsg_CopyToFindPboard, OnCopyToFindPboard)
[email protected]c0cc3092009-09-12 08:27:27512#endif
initial.commit09911bf2008-07-26 23:55:29513 IPC_MESSAGE_HANDLER(ViewMsg_Paste, OnPaste)
514 IPC_MESSAGE_HANDLER(ViewMsg_Replace, OnReplace)
[email protected]98324892009-09-09 21:16:05515 IPC_MESSAGE_HANDLER(ViewMsg_ToggleSpellPanel, OnToggleSpellPanel)
516 IPC_MESSAGE_HANDLER(ViewMsg_AdvanceToNextMisspelling,
517 OnAdvanceToNextMisspelling)
[email protected]bbbd545c2008-12-15 20:18:04518 IPC_MESSAGE_HANDLER(ViewMsg_ToggleSpellCheck, OnToggleSpellCheck)
initial.commit09911bf2008-07-26 23:55:29519 IPC_MESSAGE_HANDLER(ViewMsg_Delete, OnDelete)
520 IPC_MESSAGE_HANDLER(ViewMsg_SelectAll, OnSelectAll)
521 IPC_MESSAGE_HANDLER(ViewMsg_CopyImageAt, OnCopyImageAt)
[email protected]4b59ae602009-06-23 20:58:15522 IPC_MESSAGE_HANDLER(ViewMsg_ExecuteEditCommand, OnExecuteEditCommand)
initial.commit09911bf2008-07-26 23:55:29523 IPC_MESSAGE_HANDLER(ViewMsg_Find, OnFind)
[email protected]630e26b2008-10-14 22:55:17524 IPC_MESSAGE_HANDLER(ViewMsg_Zoom, OnZoom)
[email protected]f85f0702010-01-30 09:31:01525 IPC_MESSAGE_HANDLER(ViewMsg_SetContentSettingsForLoadingHost,
526 OnSetContentSettingsForLoadingHost)
[email protected]40bd6582009-12-04 23:49:51527 IPC_MESSAGE_HANDLER(ViewMsg_SetZoomLevelForLoadingHost,
528 OnSetZoomLevelForLoadingHost)
initial.commit09911bf2008-07-26 23:55:29529 IPC_MESSAGE_HANDLER(ViewMsg_SetPageEncoding, OnSetPageEncoding)
[email protected]a697f4c2009-09-14 22:30:18530 IPC_MESSAGE_HANDLER(ViewMsg_ResetPageEncodingToDefault,
531 OnResetPageEncodingToDefault)
[email protected]b2abac72009-02-26 12:39:28532 IPC_MESSAGE_HANDLER(ViewMsg_SetupDevToolsClient, OnSetupDevToolsClient)
[email protected]bf5c2ff392009-07-08 16:24:33533 IPC_MESSAGE_HANDLER(ViewMsg_DownloadFavIcon, OnDownloadFavIcon)
initial.commit09911bf2008-07-26 23:55:29534 IPC_MESSAGE_HANDLER(ViewMsg_ScriptEvalRequest, OnScriptEvalRequest)
[email protected]1810e132009-03-24 23:35:48535 IPC_MESSAGE_HANDLER(ViewMsg_CSSInsertRequest, OnCSSInsertRequest)
initial.commit09911bf2008-07-26 23:55:29536 IPC_MESSAGE_HANDLER(ViewMsg_AddMessageToConsole, OnAddMessageToConsole)
initial.commit09911bf2008-07-26 23:55:29537 IPC_MESSAGE_HANDLER(ViewMsg_ReservePageIDRange, OnReservePageIDRange)
initial.commit09911bf2008-07-26 23:55:29538 IPC_MESSAGE_HANDLER(ViewMsg_FillPasswordForm, OnFillPasswordForm)
539 IPC_MESSAGE_HANDLER(ViewMsg_DragTargetDragEnter, OnDragTargetDragEnter)
540 IPC_MESSAGE_HANDLER(ViewMsg_DragTargetDragOver, OnDragTargetDragOver)
541 IPC_MESSAGE_HANDLER(ViewMsg_DragTargetDragLeave, OnDragTargetDragLeave)
542 IPC_MESSAGE_HANDLER(ViewMsg_DragTargetDrop, OnDragTargetDrop)
[email protected]18cb2572008-08-21 20:34:45543 IPC_MESSAGE_HANDLER(ViewMsg_AllowBindings, OnAllowBindings)
initial.commit09911bf2008-07-26 23:55:29544 IPC_MESSAGE_HANDLER(ViewMsg_SetDOMUIProperty, OnSetDOMUIProperty)
[email protected]266eb6f2008-09-30 23:56:50545 IPC_MESSAGE_HANDLER(ViewMsg_DragSourceEndedOrMoved,
546 OnDragSourceEndedOrMoved)
initial.commit09911bf2008-07-26 23:55:29547 IPC_MESSAGE_HANDLER(ViewMsg_DragSourceSystemDragEnded,
548 OnDragSourceSystemDragEnded)
549 IPC_MESSAGE_HANDLER(ViewMsg_SetInitialFocus, OnSetInitialFocus)
550 IPC_MESSAGE_HANDLER(ViewMsg_FindReplyACK, OnFindReplyAck)
551 IPC_MESSAGE_HANDLER(ViewMsg_UpdateTargetURL_ACK, OnUpdateTargetURLAck)
552 IPC_MESSAGE_HANDLER(ViewMsg_UpdateWebPreferences, OnUpdateWebPreferences)
553 IPC_MESSAGE_HANDLER(ViewMsg_SetAltErrorPageURL, OnSetAltErrorPageURL)
554 IPC_MESSAGE_HANDLER(ViewMsg_InstallMissingPlugin, OnInstallMissingPlugin)
555 IPC_MESSAGE_HANDLER(ViewMsg_RunFileChooserResponse, OnFileChooserResponse)
556 IPC_MESSAGE_HANDLER(ViewMsg_EnableViewSourceMode, OnEnableViewSourceMode)
557 IPC_MESSAGE_HANDLER(ViewMsg_UpdateBackForwardListCount,
558 OnUpdateBackForwardListCount)
559 IPC_MESSAGE_HANDLER(ViewMsg_GetAllSavableResourceLinksForCurrentPage,
560 OnGetAllSavableResourceLinksForCurrentPage)
[email protected]f09c7182009-03-10 12:54:04561 IPC_MESSAGE_HANDLER(
562 ViewMsg_GetSerializedHtmlDataForCurrentPageWithLocalLinks,
563 OnGetSerializedHtmlDataForCurrentPageWithLocalLinks)
initial.commit09911bf2008-07-26 23:55:29564 IPC_MESSAGE_HANDLER(ViewMsg_GetApplicationInfo, OnGetApplicationInfo)
[email protected]266eb6f2008-09-30 23:56:50565 IPC_MESSAGE_HANDLER(ViewMsg_GetAccessibilityInfo, OnGetAccessibilityInfo)
566 IPC_MESSAGE_HANDLER(ViewMsg_ClearAccessibilityInfo,
567 OnClearAccessibilityInfo)
initial.commit09911bf2008-07-26 23:55:29568 IPC_MESSAGE_HANDLER(ViewMsg_ShouldClose, OnMsgShouldClose)
569 IPC_MESSAGE_HANDLER(ViewMsg_ClosePage, OnClosePage)
570 IPC_MESSAGE_HANDLER(ViewMsg_ThemeChanged, OnThemeChanged)
[email protected]18cb2572008-08-21 20:34:45571 IPC_MESSAGE_HANDLER(ViewMsg_HandleMessageFromExternalHost,
572 OnMessageFromExternalHost)
[email protected]0aa55312008-10-17 21:53:08573 IPC_MESSAGE_HANDLER(ViewMsg_DisassociateFromPopupCount,
574 OnDisassociateFromPopupCount)
[email protected]95056b582010-02-18 01:29:24575 IPC_MESSAGE_HANDLER(ViewMsg_AutoFillSuggestionsReturned,
576 OnAutoFillSuggestionsReturned)
577 IPC_MESSAGE_HANDLER(ViewMsg_AutocompleteSuggestionsReturned,
578 OnAutocompleteSuggestionsReturned)
[email protected]c83641732010-02-20 01:04:48579 IPC_MESSAGE_HANDLER(ViewMsg_AutoFillFormDataFilled,
580 OnAutoFillFormDataFilled)
[email protected]2c4410d2009-05-06 23:46:22581 IPC_MESSAGE_HANDLER(ViewMsg_PopupNotificationVisibilityChanged,
582 OnPopupNotificationVisibilityChanged)
[email protected]30f75e62009-02-25 22:01:00583 IPC_MESSAGE_HANDLER(ViewMsg_MoveOrResizeStarted, OnMoveOrResizeStarted)
[email protected]309d7a282009-03-24 09:18:27584 IPC_MESSAGE_HANDLER(ViewMsg_ExtensionResponse, OnExtensionResponse)
[email protected]7120f132009-07-20 21:05:37585 IPC_MESSAGE_HANDLER(ViewMsg_ExtensionMessageInvoke,
586 OnExtensionMessageInvoke)
[email protected]05d478752009-04-08 23:38:16587 IPC_MESSAGE_HANDLER(ViewMsg_ClearFocusedNode, OnClearFocusedNode)
[email protected]699ab0d2009-04-23 23:19:14588 IPC_MESSAGE_HANDLER(ViewMsg_SetBackground, OnSetBackground)
[email protected]ab32b16c2009-10-16 14:57:25589 IPC_MESSAGE_HANDLER(ViewMsg_EnablePreferredSizeChangedMode,
590 OnEnablePreferredSizeChangedMode)
[email protected]cda45c02010-02-25 19:28:10591 IPC_MESSAGE_HANDLER(ViewMsg_DisableScrollbarsForSmallWindows,
592 OnDisableScrollbarsForSmallWindows)
[email protected]80d96fa2009-06-10 22:34:51593 IPC_MESSAGE_HANDLER(ViewMsg_SetRendererPrefs, OnSetRendererPrefs)
[email protected]7b291f92009-08-14 05:43:53594 IPC_MESSAGE_HANDLER(ViewMsg_UpdateBrowserWindowId,
595 OnUpdateBrowserWindowId)
596 IPC_MESSAGE_HANDLER(ViewMsg_NotifyRenderViewType,
597 OnNotifyRendererViewType)
[email protected]581b87eb2009-07-23 23:06:56598 IPC_MESSAGE_HANDLER(ViewMsg_MediaPlayerActionAt, OnMediaPlayerActionAt)
[email protected]8c66c5a2009-07-22 17:26:34599 IPC_MESSAGE_HANDLER(ViewMsg_SetActive, OnSetActive)
[email protected]6ce7abc52010-02-02 18:40:14600#if defined(OS_MACOSX)
601 IPC_MESSAGE_HANDLER(ViewMsg_SetWindowVisibility, OnSetWindowVisibility)
[email protected]1e6e3c992010-02-08 15:52:13602 IPC_MESSAGE_HANDLER(ViewMsg_WindowFrameChanged, OnWindowFrameChanged)
[email protected]6ce7abc52010-02-02 18:40:14603#endif
[email protected]446705872009-09-10 07:22:48604 IPC_MESSAGE_HANDLER(ViewMsg_SetEditCommandsForNextKeyEvent,
[email protected]a0c7153e2009-12-09 14:36:33605 OnSetEditCommandsForNextKeyEvent)
[email protected]912256b32009-09-18 09:47:35606 IPC_MESSAGE_HANDLER(ViewMsg_ExecuteCode,
607 OnExecuteCode)
[email protected]a0c7153e2009-12-09 14:36:33608 IPC_MESSAGE_HANDLER(ViewMsg_CustomContextMenuAction,
609 OnCustomContextMenuAction)
[email protected]d4a00a72010-01-29 01:44:42610 IPC_MESSAGE_HANDLER(ViewMsg_TranslatePage, OnTranslatePage)
[email protected]0bedb8a2010-01-14 19:36:32611 IPC_MESSAGE_HANDLER(ViewMsg_TranslateTextReponse, OnTranslateTextResponse)
[email protected]634a6f92008-12-01 21:39:31612
initial.commit09911bf2008-07-26 23:55:29613 // Have the super handle all other messages.
614 IPC_MESSAGE_UNHANDLED(RenderWidget::OnMessageReceived(message))
615 IPC_END_MESSAGE_MAP()
616}
617
initial.commit09911bf2008-07-26 23:55:29618void RenderView::SendThumbnail() {
[email protected]26aa0482009-09-30 16:55:27619 WebFrame* main_frame = webview()->mainFrame();
initial.commit09911bf2008-07-26 23:55:29620 if (!main_frame)
621 return;
622
623 // get the URL for this page
[email protected]dd7daa82009-08-10 05:46:45624 GURL url(main_frame->url());
initial.commit09911bf2008-07-26 23:55:29625 if (url.is_empty())
626 return;
627
628 if (size_.IsEmpty())
629 return; // Don't create an empty thumbnail!
630
631 ThumbnailScore score;
632 SkBitmap thumbnail;
[email protected]8649fb32009-06-26 17:51:02633 if (!CaptureThumbnail(webview(), kThumbnailWidth, kThumbnailHeight,
[email protected]b6e4bec2008-11-12 01:17:15634 &thumbnail, &score))
635 return;
636
initial.commit09911bf2008-07-26 23:55:29637 // send the thumbnail message to the browser process
[email protected]674741932009-02-04 23:44:46638 Send(new ViewHostMsg_Thumbnail(routing_id_, url, score, thumbnail));
initial.commit09911bf2008-07-26 23:55:29639}
640
[email protected]30507922010-01-15 16:48:23641void RenderView::SendSnapshot() {
642 SkBitmap snapshot;
643 bool error = false;
644
645 WebFrame* main_frame = webview()->mainFrame();
646 if (!main_frame)
647 error = true;
648
649 if (!error && !CaptureSnapshot(webview(), &snapshot))
650 error = true;
651
652 DCHECK(error == snapshot.empty()) <<
653 "Snapshot should be empty on error, non-empty otherwise.";
654
655 // Send the snapshot to the browser process.
656 Send(new ViewHostMsg_Snapshot(routing_id_, snapshot));
657}
658
[email protected]068637222009-01-29 16:58:07659void RenderView::OnPrintPages() {
initial.commit09911bf2008-07-26 23:55:29660 DCHECK(webview());
[email protected]aa82249f2009-07-16 17:23:58661 if (webview()) {
662 // If the user has selected text in the currently focused frame we print
663 // only that frame (this makes print selection work for multiple frames).
[email protected]26aa0482009-09-30 16:55:27664 if (webview()->focusedFrame()->hasSelection())
665 Print(webview()->focusedFrame(), false);
[email protected]aa82249f2009-07-16 17:23:58666 else
[email protected]26aa0482009-09-30 16:55:27667 Print(webview()->mainFrame(), false);
[email protected]aa82249f2009-07-16 17:23:58668 }
initial.commit09911bf2008-07-26 23:55:29669}
670
[email protected]82270452009-06-19 15:58:01671void RenderView::OnPrintingDone(int document_cookie, bool success) {
672 // Ignoring document cookie here since only one print job can be outstanding
673 // per renderer and document_cookie is 0 when printing is successful.
674 DCHECK(print_helper_.get());
675 if (print_helper_.get() != NULL) {
676 print_helper_->DidFinishPrinting(success);
677 }
678}
679
initial.commit09911bf2008-07-26 23:55:29680void RenderView::CapturePageInfo(int load_id, bool preliminary_capture) {
681 if (load_id != page_id_)
682 return; // this capture call is no longer relevant due to navigation
683 if (load_id == last_indexed_page_id_)
684 return; // we already indexed this page
685
686 if (!webview())
687 return;
688
[email protected]26aa0482009-09-30 16:55:27689 WebFrame* main_frame = webview()->mainFrame();
initial.commit09911bf2008-07-26 23:55:29690 if (!main_frame)
691 return;
692
693 // Don't index/capture pages that are in view source mode.
[email protected]dd7daa82009-08-10 05:46:45694 if (main_frame->isViewSourceModeEnabled())
initial.commit09911bf2008-07-26 23:55:29695 return;
696
697 // Don't index/capture pages that failed to load. This only checks the top
698 // level frame so the thumbnail may contain a frame that failed to load.
[email protected]dd7daa82009-08-10 05:46:45699 WebDataSource* ds = main_frame->dataSource();
[email protected]726985e22009-06-18 21:09:28700 if (ds && ds->hasUnreachableURL())
initial.commit09911bf2008-07-26 23:55:29701 return;
702
703 if (!preliminary_capture)
704 last_indexed_page_id_ = load_id;
705
[email protected]a8a81292010-01-21 00:32:45706 // Get the URL for this page.
[email protected]dd7daa82009-08-10 05:46:45707 GURL url(main_frame->url());
initial.commit09911bf2008-07-26 23:55:29708 if (url.is_empty())
709 return;
710
[email protected]a8a81292010-01-21 00:32:45711 // Retrieve the frame's full text.
initial.commit09911bf2008-07-26 23:55:29712 std::wstring contents;
713 CaptureText(main_frame, &contents);
714 if (contents.size()) {
[email protected]a8a81292010-01-21 00:32:45715 base::TimeTicks begin_time = base::TimeTicks::Now();
716 std::string language = DetermineTextLanguage(contents);
717 UMA_HISTOGRAM_MEDIUM_TIMES("Renderer4.LanguageDetection",
718 base::TimeTicks::Now() - begin_time);
[email protected]7893a982010-01-07 23:25:52719
[email protected]a8a81292010-01-21 00:32:45720 // Send the text to the browser for indexing (the browser might decide not
721 // to index, if the URL is HTTPS for instance) and language discovery.
722 Send(new ViewHostMsg_PageContents(routing_id_, url, load_id, contents,
723 language));
[email protected]5c4266922009-07-10 16:41:27724 }
725
initial.commit09911bf2008-07-26 23:55:29726 // thumbnail
727 SendThumbnail();
728}
729
730void RenderView::CaptureText(WebFrame* frame, std::wstring* contents) {
731 contents->clear();
732 if (!frame)
733 return;
734
735#ifdef TIME_TEXT_RETRIEVAL
736 double begin = time_util::GetHighResolutionTimeNow();
737#endif
738
739 // get the contents of the frame
[email protected]dd7daa82009-08-10 05:46:45740 *contents = UTF16ToWideHack(frame->contentAsText(kMaxIndexChars));
initial.commit09911bf2008-07-26 23:55:29741
742#ifdef TIME_TEXT_RETRIEVAL
743 double end = time_util::GetHighResolutionTimeNow();
744 char buf[128];
745 sprintf_s(buf, "%d chars retrieved for indexing in %gms\n",
746 contents.size(), (end - begin)*1000);
747 OutputDebugStringA(buf);
748#endif
749
750 // When the contents are clipped to the maximum, we don't want to have a
751 // partial word indexed at the end that might have been clipped. Therefore,
752 // terminate the string at the last space to ensure no words are clipped.
753 if (contents->size() == kMaxIndexChars) {
754 size_t last_space_index = contents->find_last_of(kWhitespaceWide);
755 if (last_space_index == std::wstring::npos)
756 return; // don't index if we got a huge block of text with no spaces
757 contents->resize(last_space_index);
758 }
759}
760
[email protected]8649fb32009-06-26 17:51:02761bool RenderView::CaptureThumbnail(WebView* view,
initial.commit09911bf2008-07-26 23:55:29762 int w,
763 int h,
764 SkBitmap* thumbnail,
765 ThumbnailScore* score) {
[email protected]30507922010-01-15 16:48:23766 base::TimeTicks beginning_time = base::TimeTicks::Now();
[email protected]b6e4bec2008-11-12 01:17:15767
[email protected]8649fb32009-06-26 17:51:02768 skia::PlatformCanvas canvas;
[email protected]30507922010-01-15 16:48:23769
770 // Paint |view| into |canvas|.
771 if (!PaintViewIntoCanvas(view, canvas))
[email protected]8649fb32009-06-26 17:51:02772 return false;
[email protected]8649fb32009-06-26 17:51:02773
774 skia::BitmapPlatformDevice& device =
775 static_cast<skia::BitmapPlatformDevice&>(canvas.getTopPlatformDevice());
776
777 const SkBitmap& src_bmp = device.accessBitmap(false);
initial.commit09911bf2008-07-26 23:55:29778
[email protected]cab34d6a2009-09-24 01:14:52779 SkRect dest_rect = { 0, 0, SkIntToScalar(w), SkIntToScalar(h) };
initial.commit09911bf2008-07-26 23:55:29780 float dest_aspect = dest_rect.width() / dest_rect.height();
781
782 // Get the src rect so that we can preserve the aspect ratio while filling
783 // the destination.
784 SkIRect src_rect;
785 if (src_bmp.width() < dest_rect.width() ||
786 src_bmp.height() < dest_rect.height()) {
787 // Source image is smaller: we clip the part of source image within the
788 // dest rect, and then stretch it to fill the dest rect. We don't respect
789 // the aspect ratio in this case.
790 src_rect.set(0, 0, static_cast<S16CPU>(dest_rect.width()),
791 static_cast<S16CPU>(dest_rect.height()));
792 score->good_clipping = false;
793 } else {
794 float src_aspect = static_cast<float>(src_bmp.width()) / src_bmp.height();
795 if (src_aspect > dest_aspect) {
796 // Wider than tall, clip horizontally: we center the smaller thumbnail in
797 // the wider screen.
798 S16CPU new_width = static_cast<S16CPU>(src_bmp.height() * dest_aspect);
799 S16CPU x_offset = (src_bmp.width() - new_width) / 2;
800 src_rect.set(x_offset, 0, new_width + x_offset, src_bmp.height());
801 score->good_clipping = false;
802 } else {
803 src_rect.set(0, 0, src_bmp.width(),
804 static_cast<S16CPU>(src_bmp.width() / dest_aspect));
805 score->good_clipping = true;
806 }
807 }
808
[email protected]26aa0482009-09-30 16:55:27809 score->at_top = (view->mainFrame()->scrollOffset().height == 0);
initial.commit09911bf2008-07-26 23:55:29810
811 SkBitmap subset;
[email protected]8649fb32009-06-26 17:51:02812 device.accessBitmap(false).extractSubset(&subset, src_rect);
initial.commit09911bf2008-07-26 23:55:29813
814 // Resample the subset that we want to get it the right size.
[email protected]465b34b72008-12-12 20:19:14815 *thumbnail = skia::ImageOperations::Resize(
816 subset, skia::ImageOperations::RESIZE_LANCZOS3, w, h);
initial.commit09911bf2008-07-26 23:55:29817
818 score->boring_score = CalculateBoringScore(thumbnail);
819
[email protected]30507922010-01-15 16:48:23820 HISTOGRAM_TIMES("Renderer4.Thumbnail",
821 base::TimeTicks::Now() - beginning_time);
[email protected]b6e4bec2008-11-12 01:17:15822 return true;
initial.commit09911bf2008-07-26 23:55:29823}
824
[email protected]30507922010-01-15 16:48:23825bool RenderView::CaptureSnapshot(WebView* view, SkBitmap* snapshot) {
826 base::TimeTicks beginning_time = base::TimeTicks::Now();
initial.commit09911bf2008-07-26 23:55:29827
[email protected]30507922010-01-15 16:48:23828 skia::PlatformCanvas canvas;
829 if (!PaintViewIntoCanvas(view, canvas))
830 return false;
831
832 skia::BitmapPlatformDevice& device =
833 static_cast<skia::BitmapPlatformDevice&>(canvas.getTopPlatformDevice());
834
835 const SkBitmap& bitmap = device.accessBitmap(false);
836 if (!bitmap.copyTo(snapshot, SkBitmap::kARGB_8888_Config))
837 return false;
838
839 HISTOGRAM_TIMES("Renderer4.Snapshot",
840 base::TimeTicks::Now() - beginning_time);
841 return true;
initial.commit09911bf2008-07-26 23:55:29842}
843
844void RenderView::OnNavigate(const ViewMsg_Navigate_Params& params) {
845 if (!webview())
846 return;
847
[email protected]8c785c62009-07-13 14:20:15848 if (devtools_agent_.get())
849 devtools_agent_->OnNavigate();
850
[email protected]422197532010-01-25 17:38:23851 if (notification_provider_.get())
852 notification_provider_->OnNavigate();
853
[email protected]a9f607e2009-10-23 19:59:27854 child_process_logging::SetActiveURL(params.url);
[email protected]f8b6b6f2009-03-10 16:48:26855
initial.commit09911bf2008-07-26 23:55:29856 AboutHandler::MaybeHandle(params.url);
857
[email protected]ecbf10d2010-02-18 13:03:29858 bool is_reload =
859 params.navigation_type == ViewMsg_Navigate_Params::RELOAD ||
860 params.navigation_type == ViewMsg_Navigate_Params::RELOAD_IGNORING_CACHE;
initial.commit09911bf2008-07-26 23:55:29861
[email protected]26aa0482009-09-30 16:55:27862 WebFrame* main_frame = webview()->mainFrame();
[email protected]dd7daa82009-08-10 05:46:45863 if (is_reload && main_frame->currentHistoryItem().isNull()) {
initial.commit09911bf2008-07-26 23:55:29864 // We cannot reload if we do not have any history state. This happens, for
865 // example, when recovering from a crash. Our workaround here is a bit of
866 // a hack since it means that reload after a crashed tab does not cause an
867 // end-to-end cache validation.
868 is_reload = false;
869 }
870
[email protected]77f17a82009-05-21 04:42:54871 // A navigation resulting from loading a javascript URL should not be treated
872 // as a browser initiated event. Instead, we want it to look as if the page
873 // initiated any load resulting from JS execution.
874 if (!params.url.SchemeIs(chrome::kJavaScriptScheme)) {
[email protected]5e369672009-11-03 23:48:30875 NavigationState* state = NavigationState::CreateBrowserInitiated(
876 params.page_id, params.transition, params.request_time);
877 if (params.navigation_type == ViewMsg_Navigate_Params::RESTORE) {
878 // We're doing a load of a page that was restored from the last session.
879 // By default this prefers the cache over loading (LOAD_PREFERRING_CACHE)
880 // which can result in stale data for pages that are set to expire. We
881 // explicitly override that by setting the policy here so that as
882 // necessary we load from the network.
883 state->set_cache_policy_override(WebURLRequest::UseProtocolCachePolicy);
884 }
885 pending_navigation_state_.reset(state);
[email protected]77f17a82009-05-21 04:42:54886 }
initial.commit09911bf2008-07-26 23:55:29887
[email protected]a7ccc4d2010-01-27 08:14:48888 NavigationState* navigation_state = pending_navigation_state_.get();
889
[email protected]04d3c6e2009-05-22 17:00:13890 // If we are reloading, then WebKit will use the history state of the current
891 // page, so we should just ignore any given history state. Otherwise, if we
892 // have history state, then we need to navigate to it, which corresponds to a
893 // back/forward navigation event.
[email protected]e6f546c32009-07-01 17:12:55894 if (is_reload) {
[email protected]a7ccc4d2010-01-27 08:14:48895 if (navigation_state)
896 navigation_state->set_load_type(NavigationState::RELOAD);
[email protected]ecbf10d2010-02-18 13:03:29897 bool ignore_cache = (params.navigation_type ==
898 ViewMsg_Navigate_Params::RELOAD_IGNORING_CACHE);
899 main_frame->reload(ignore_cache);
[email protected]e6f546c32009-07-01 17:12:55900 } else if (!params.state.empty()) {
[email protected]04d3c6e2009-05-22 17:00:13901 // We must know the page ID of the page we are navigating back to.
[email protected]f929f2f22009-06-12 16:56:58902 DCHECK_NE(params.page_id, -1);
[email protected]a7ccc4d2010-01-27 08:14:48903 if (navigation_state)
904 navigation_state->set_load_type(NavigationState::HISTORY_LOAD);
[email protected]dd7daa82009-08-10 05:46:45905 main_frame->loadHistoryItem(
[email protected]ca948a22009-06-25 19:36:17906 webkit_glue::HistoryItemFromString(params.state));
[email protected]04d3c6e2009-05-22 17:00:13907 } else {
908 // Navigate to the given URL.
[email protected]726985e22009-06-18 21:09:28909 WebURLRequest request(params.url);
initial.commit09911bf2008-07-26 23:55:29910
[email protected]e6f546c32009-07-01 17:12:55911 // A session history navigation should have been accompanied by state.
912 DCHECK_EQ(params.page_id, -1);
[email protected]04d3c6e2009-05-22 17:00:13913
[email protected]dd7daa82009-08-10 05:46:45914 if (main_frame->isViewSourceModeEnabled())
[email protected]e6f546c32009-07-01 17:12:55915 request.setCachePolicy(WebURLRequest::ReturnCacheDataElseLoad);
[email protected]04d3c6e2009-05-22 17:00:13916
[email protected]726985e22009-06-18 21:09:28917 if (params.referrer.is_valid()) {
918 request.setHTTPHeaderField(WebString::fromUTF8("Referer"),
919 WebString::fromUTF8(params.referrer.spec()));
920 }
[email protected]04d3c6e2009-05-22 17:00:13921
[email protected]a7ccc4d2010-01-27 08:14:48922 if (navigation_state)
923 navigation_state->set_load_type(NavigationState::NORMAL_LOAD);
[email protected]dd7daa82009-08-10 05:46:45924 main_frame->loadRequest(request);
[email protected]c0588052008-10-27 23:01:50925 }
926
[email protected]77f17a82009-05-21 04:42:54927 // In case LoadRequest failed before DidCreateDataSource was called.
928 pending_navigation_state_.reset();
initial.commit09911bf2008-07-26 23:55:29929}
930
931// Stop loading the current page
932void RenderView::OnStop() {
933 if (webview())
[email protected]b4bb2502009-10-01 22:35:27934 webview()->mainFrame()->stopLoading();
initial.commit09911bf2008-07-26 23:55:29935}
936
[email protected]ecbf10d2010-02-18 13:03:29937// Reload current focused frame.
938// E.g. called by right-clicking on the frame and picking "reload this frame".
[email protected]1dda4022010-01-28 18:24:56939void RenderView::OnReloadFrame() {
[email protected]ecbf10d2010-02-18 13:03:29940 if (webview() && webview()->focusedFrame()) {
941 // We always obey the cache (ignore_cache=false) here.
942 // TODO(evanm): perhaps we could allow shift-clicking the menu item to do
943 // a cache-ignoring reload of the frame.
944 webview()->focusedFrame()->reload(false);
945 }
[email protected]1dda4022010-01-28 18:24:56946}
947
[email protected]e6f546c32009-07-01 17:12:55948void RenderView::OnLoadAlternateHTMLText(const std::string& html,
initial.commit09911bf2008-07-26 23:55:29949 bool new_navigation,
950 const GURL& display_url,
951 const std::string& security_info) {
952 if (!webview())
953 return;
954
[email protected]e6f546c32009-07-01 17:12:55955 pending_navigation_state_.reset(NavigationState::CreateBrowserInitiated(
956 new_navigation ? -1 : page_id_, PageTransition::LINK, Time::Now()));
957 pending_navigation_state_->set_security_info(security_info);
initial.commit09911bf2008-07-26 23:55:29958
[email protected]26aa0482009-09-30 16:55:27959 webview()->mainFrame()->loadHTMLString(
960 html, GURL(kUnreachableWebDataURL), display_url, !new_navigation);
[email protected]e6f546c32009-07-01 17:12:55961
962 pending_navigation_state_.reset();
initial.commit09911bf2008-07-26 23:55:29963}
964
965void RenderView::OnCopyImageAt(int x, int y) {
[email protected]26aa0482009-09-30 16:55:27966 webview()->copyImageAt(WebPoint(x, y));
initial.commit09911bf2008-07-26 23:55:29967}
968
[email protected]68b1e922009-06-23 16:00:25969void RenderView::OnExecuteEditCommand(const std::string& name,
970 const std::string& value) {
[email protected]26aa0482009-09-30 16:55:27971 if (!webview() || !webview()->focusedFrame())
[email protected]68b1e922009-06-23 16:00:25972 return;
973
[email protected]26aa0482009-09-30 16:55:27974 webview()->focusedFrame()->executeCommand(
[email protected]dd7daa82009-08-10 05:46:45975 WebString::fromUTF8(name), WebString::fromUTF8(value));
[email protected]68b1e922009-06-23 16:00:25976}
977
[email protected]b2abac72009-02-26 12:39:28978void RenderView::OnSetupDevToolsClient() {
[email protected]e4ac5df2009-03-17 15:33:11979 DCHECK(!devtools_client_.get());
980 devtools_client_.reset(new DevToolsClient(this));
[email protected]b2abac72009-02-26 12:39:28981}
982
initial.commit09911bf2008-07-26 23:55:29983void RenderView::OnStopFinding(bool clear_selection) {
984 WebView* view = webview();
985 if (!view)
986 return;
987
988 if (clear_selection)
[email protected]26aa0482009-09-30 16:55:27989 view->focusedFrame()->executeCommand(WebString::fromUTF8("Unselect"));
initial.commit09911bf2008-07-26 23:55:29990
[email protected]26aa0482009-09-30 16:55:27991 WebFrame* frame = view->mainFrame();
initial.commit09911bf2008-07-26 23:55:29992 while (frame) {
[email protected]dd7daa82009-08-10 05:46:45993 frame->stopFinding(clear_selection);
[email protected]b4bb2502009-10-01 22:35:27994 frame = frame->traverseNext(false);
initial.commit09911bf2008-07-26 23:55:29995 }
996}
997
998void RenderView::OnFindReplyAck() {
999 // Check if there is any queued up request waiting to be sent.
1000 if (queued_find_reply_message_.get()) {
1001 // Send the search result over to the browser process.
1002 Send(queued_find_reply_message_.get());
1003 queued_find_reply_message_.release();
1004 }
1005}
1006
1007void RenderView::OnUpdateTargetURLAck() {
1008 // Check if there is a targeturl waiting to be sent.
1009 if (target_url_status_ == TARGET_PENDING) {
1010 Send(new ViewHostMsg_UpdateTargetURL(routing_id_, page_id_,
1011 pending_target_url_));
1012 }
1013
1014 target_url_status_ = TARGET_NONE;
1015}
1016
1017void RenderView::OnUndo() {
1018 if (!webview())
1019 return;
1020
[email protected]26aa0482009-09-30 16:55:271021 webview()->focusedFrame()->executeCommand(WebString::fromUTF8("Undo"));
[email protected]afe3a1672009-11-17 19:04:121022 UserMetricsRecordAction("Undo");
initial.commit09911bf2008-07-26 23:55:291023}
1024
1025void RenderView::OnRedo() {
1026 if (!webview())
1027 return;
1028
[email protected]26aa0482009-09-30 16:55:271029 webview()->focusedFrame()->executeCommand(WebString::fromUTF8("Redo"));
[email protected]afe3a1672009-11-17 19:04:121030 UserMetricsRecordAction("Redo");
initial.commit09911bf2008-07-26 23:55:291031}
1032
1033void RenderView::OnCut() {
1034 if (!webview())
1035 return;
1036
[email protected]26aa0482009-09-30 16:55:271037 webview()->focusedFrame()->executeCommand(WebString::fromUTF8("Cut"));
[email protected]afe3a1672009-11-17 19:04:121038 UserMetricsRecordAction("Cut");
initial.commit09911bf2008-07-26 23:55:291039}
1040
1041void RenderView::OnCopy() {
1042 if (!webview())
1043 return;
1044
[email protected]26aa0482009-09-30 16:55:271045 webview()->focusedFrame()->executeCommand(WebString::fromUTF8("Copy"));
[email protected]afe3a1672009-11-17 19:04:121046 UserMetricsRecordAction("Copy");
initial.commit09911bf2008-07-26 23:55:291047}
1048
[email protected]c0cc3092009-09-12 08:27:271049#if defined(OS_MACOSX)
[email protected]a954bf72009-09-12 07:30:351050void RenderView::OnCopyToFindPboard() {
1051 if (!webview())
1052 return;
1053
1054 // Since the find pasteboard supports only plain text, this can be simpler
1055 // than the |OnCopy()| case.
[email protected]26aa0482009-09-30 16:55:271056 WebFrame* frame = webview()->focusedFrame();
[email protected]a954bf72009-09-12 07:30:351057 if (frame->hasSelection()) {
1058 string16 selection = frame->selectionAsText();
1059 RenderThread::current()->Send(
1060 new ViewHostMsg_ClipboardFindPboardWriteStringAsync(selection));
1061 }
1062
[email protected]afe3a1672009-11-17 19:04:121063 UserMetricsRecordAction("CopyToFindPboard");
[email protected]a954bf72009-09-12 07:30:351064}
[email protected]c0cc3092009-09-12 08:27:271065#endif
[email protected]a954bf72009-09-12 07:30:351066
initial.commit09911bf2008-07-26 23:55:291067void RenderView::OnPaste() {
1068 if (!webview())
1069 return;
1070
[email protected]26aa0482009-09-30 16:55:271071 webview()->focusedFrame()->executeCommand(WebString::fromUTF8("Paste"));
[email protected]afe3a1672009-11-17 19:04:121072 UserMetricsRecordAction("Paste");
initial.commit09911bf2008-07-26 23:55:291073}
1074
[email protected]2a3a7762009-10-19 19:17:321075void RenderView::OnReplace(const string16& text) {
initial.commit09911bf2008-07-26 23:55:291076 if (!webview())
1077 return;
1078
[email protected]1ff7a032010-02-03 02:46:031079 WebFrame* frame = webview()->focusedFrame();
1080 if (!frame->hasSelection())
1081 frame->selectWordAroundCaret();
1082 frame->replaceSelection(text);
initial.commit09911bf2008-07-26 23:55:291083}
1084
[email protected]98324892009-09-09 21:16:051085void RenderView::OnAdvanceToNextMisspelling() {
1086 if (!webview())
1087 return;
[email protected]26aa0482009-09-30 16:55:271088 webview()->focusedFrame()->executeCommand(
[email protected]98324892009-09-09 21:16:051089 WebString::fromUTF8("AdvanceToNextMisspelling"));
1090}
1091
1092void RenderView::OnToggleSpellPanel(bool is_currently_visible) {
1093 if (!webview())
1094 return;
1095 // We need to tell the webView whether the spelling panel is visible or not so
1096 // that it won't need to make ipc calls later.
[email protected]8922e1f2009-10-03 05:01:261097 spelling_panel_visible_ = is_currently_visible;
[email protected]26aa0482009-09-30 16:55:271098 webview()->focusedFrame()->executeCommand(
[email protected]98324892009-09-09 21:16:051099 WebString::fromUTF8("ToggleSpellPanel"));
1100}
1101
[email protected]bbbd545c2008-12-15 20:18:041102void RenderView::OnToggleSpellCheck() {
1103 if (!webview())
1104 return;
1105
[email protected]26aa0482009-09-30 16:55:271106 WebFrame* frame = webview()->focusedFrame();
[email protected]dd7daa82009-08-10 05:46:451107 frame->enableContinuousSpellChecking(
1108 !frame->isContinuousSpellCheckingEnabled());
[email protected]bbbd545c2008-12-15 20:18:041109}
1110
initial.commit09911bf2008-07-26 23:55:291111void RenderView::OnDelete() {
1112 if (!webview())
1113 return;
1114
[email protected]26aa0482009-09-30 16:55:271115 webview()->focusedFrame()->executeCommand(WebString::fromUTF8("Delete"));
[email protected]afe3a1672009-11-17 19:04:121116 UserMetricsRecordAction("DeleteSelection");
initial.commit09911bf2008-07-26 23:55:291117}
1118
1119void RenderView::OnSelectAll() {
1120 if (!webview())
1121 return;
1122
[email protected]26aa0482009-09-30 16:55:271123 webview()->focusedFrame()->executeCommand(
[email protected]a100d76bb2009-08-14 17:50:221124 WebString::fromUTF8("SelectAll"));
[email protected]afe3a1672009-11-17 19:04:121125 UserMetricsRecordAction("SelectAll");
initial.commit09911bf2008-07-26 23:55:291126}
1127
1128void RenderView::OnSetInitialFocus(bool reverse) {
1129 if (!webview())
1130 return;
[email protected]26aa0482009-09-30 16:55:271131 webview()->setInitialFocus(reverse);
initial.commit09911bf2008-07-26 23:55:291132}
1133
1134///////////////////////////////////////////////////////////////////////////////
1135
[email protected]433819d2010-01-30 20:20:011136void RenderView::SetContentSettings(const ContentSettings& settings) {
1137 current_content_settings_ = settings;
[email protected]f85f0702010-01-30 09:31:011138}
1139
initial.commit09911bf2008-07-26 23:55:291140// Tell the embedding application that the URL of the active page has changed
1141void RenderView::UpdateURL(WebFrame* frame) {
[email protected]dd7daa82009-08-10 05:46:451142 WebDataSource* ds = frame->dataSource();
initial.commit09911bf2008-07-26 23:55:291143 DCHECK(ds);
1144
[email protected]726985e22009-06-18 21:09:281145 const WebURLRequest& request = ds->request();
1146 const WebURLRequest& original_request = ds->originalRequest();
1147 const WebURLResponse& response = ds->response();
initial.commit09911bf2008-07-26 23:55:291148
[email protected]daa8c58e2009-06-15 17:21:101149 NavigationState* navigation_state = NavigationState::FromDataSource(ds);
1150 DCHECK(navigation_state);
initial.commit09911bf2008-07-26 23:55:291151
1152 ViewHostMsg_FrameNavigate_Params params;
[email protected]726985e22009-06-18 21:09:281153 params.http_status_code = response.httpStatusCode();
initial.commit09911bf2008-07-26 23:55:291154 params.is_post = false;
1155 params.page_id = page_id_;
[email protected]726985e22009-06-18 21:09:281156 params.is_content_filtered = response.isContentFiltered();
[email protected]e6f546c32009-07-01 17:12:551157 if (!navigation_state->security_info().empty()) {
initial.commit09911bf2008-07-26 23:55:291158 // SSL state specified in the request takes precedence over the one in the
1159 // response.
1160 // So far this is only intended for error pages that are not expected to be
1161 // over ssl, so we should not get any clash.
[email protected]726985e22009-06-18 21:09:281162 DCHECK(response.securityInfo().isEmpty());
[email protected]e6f546c32009-07-01 17:12:551163 params.security_info = navigation_state->security_info();
initial.commit09911bf2008-07-26 23:55:291164 } else {
[email protected]726985e22009-06-18 21:09:281165 params.security_info = response.securityInfo();
initial.commit09911bf2008-07-26 23:55:291166 }
1167
1168 // Set the URL to be displayed in the browser UI to the user.
[email protected]726985e22009-06-18 21:09:281169 if (ds->hasUnreachableURL()) {
1170 params.url = ds->unreachableURL();
initial.commit09911bf2008-07-26 23:55:291171 } else {
[email protected]726985e22009-06-18 21:09:281172 params.url = request.url();
initial.commit09911bf2008-07-26 23:55:291173 }
1174
[email protected]726985e22009-06-18 21:09:281175 GetRedirectChain(ds, &params.redirects);
[email protected]d94dc1e2010-03-04 09:29:241176 params.should_update_history = !ds->hasUnreachableURL() &&
1177 !response.isMultipartPayload();
initial.commit09911bf2008-07-26 23:55:291178
[email protected]ce0e250d2009-10-23 21:00:351179 params.searchable_form_url = navigation_state->searchable_form_url();
1180 params.searchable_form_encoding =
1181 navigation_state->searchable_form_encoding();
initial.commit09911bf2008-07-26 23:55:291182
1183 const PasswordForm* password_form_data =
[email protected]daa8c58e2009-06-15 17:21:101184 navigation_state->password_form_data();
initial.commit09911bf2008-07-26 23:55:291185 if (password_form_data)
1186 params.password_form = *password_form_data;
1187
1188 params.gesture = navigation_gesture_;
1189 navigation_gesture_ = NavigationGestureUnknown;
1190
[email protected]dd7daa82009-08-10 05:46:451191 if (!frame->parent()) {
initial.commit09911bf2008-07-26 23:55:291192 // Top-level navigation.
1193
[email protected]71b0d5d2010-02-15 05:43:071194 // Clear "block" flags for the new page. This needs to happen before any of
1195 // allowScripts(), allowImages(), allowPlugins() is called for the new page
1196 // so that these functions can correctly detect that a piece of content
1197 // flipped from "not blocked" to "blocked".
1198 ClearBlockedContentSettings();
1199
[email protected]f85f0702010-01-30 09:31:011200 // Set content settings.
1201 HostContentSettings::iterator host_content_settings =
1202 host_content_settings_.find(GURL(request.url()).host());
1203 if (host_content_settings != host_content_settings_.end()) {
[email protected]433819d2010-01-30 20:20:011204 SetContentSettings(host_content_settings->second);
[email protected]f85f0702010-01-30 09:31:011205
1206 // These content settings were merely recorded transiently for this load.
1207 // We can erase them now. If at some point we reload this page, the
1208 // browser will send us new, up-to-date content settings.
1209 host_content_settings_.erase(host_content_settings);
1210 }
1211
[email protected]40bd6582009-12-04 23:49:511212 // Set zoom level.
[email protected]f85f0702010-01-30 09:31:011213 HostZoomLevels::iterator host_zoom =
[email protected]40bd6582009-12-04 23:49:511214 host_zoom_levels_.find(GURL(request.url()).host());
[email protected]f85f0702010-01-30 09:31:011215 if (host_zoom != host_zoom_levels_.end()) {
1216 webview()->setZoomLevel(false, host_zoom->second);
[email protected]40bd6582009-12-04 23:49:511217 // This zoom level was merely recorded transiently for this load. We can
1218 // erase it now. If at some point we reload this page, the browser will
1219 // send us a new, up-to-date zoom level.
[email protected]f85f0702010-01-30 09:31:011220 host_zoom_levels_.erase(host_zoom);
[email protected]40bd6582009-12-04 23:49:511221 }
1222
initial.commit09911bf2008-07-26 23:55:291223 // Update contents MIME type for main frame.
[email protected]9c5645b2009-08-11 03:37:551224 params.contents_mime_type = ds->response().mimeType().utf8();
initial.commit09911bf2008-07-26 23:55:291225
[email protected]daa8c58e2009-06-15 17:21:101226 params.transition = navigation_state->transition_type();
initial.commit09911bf2008-07-26 23:55:291227 if (!PageTransition::IsMainFrame(params.transition)) {
1228 // If the main frame does a load, it should not be reported as a subframe
1229 // navigation. This can occur in the following case:
1230 // 1. You're on a site with frames.
1231 // 2. You do a subframe navigation. This is stored with transition type
1232 // MANUAL_SUBFRAME.
1233 // 3. You navigate to some non-frame site, say, google.com.
1234 // 4. You navigate back to the page from step 2. Since it was initially
1235 // MANUAL_SUBFRAME, it will be that same transition type here.
1236 // We don't want that, because any navigation that changes the toplevel
1237 // frame should be tracked as a toplevel navigation (this allows us to
1238 // update the URL bar, etc).
1239 params.transition = PageTransition::LINK;
1240 }
1241
initial.commit09911bf2008-07-26 23:55:291242 // If we have a valid consumed client redirect source,
1243 // the page contained a client redirect (meta refresh, document.loc...),
1244 // so we set the referrer and transition to match.
1245 if (completed_client_redirect_src_.is_valid()) {
[email protected]77e09a92008-08-01 18:11:041246 DCHECK(completed_client_redirect_src_ == params.redirects[0]);
initial.commit09911bf2008-07-26 23:55:291247 params.referrer = completed_client_redirect_src_;
1248 params.transition = static_cast<PageTransition::Type>(
1249 params.transition | PageTransition::CLIENT_REDIRECT);
1250 } else {
1251 // Bug 654101: the referrer will be empty on https->http transitions. It
1252 // would be nice if we could get the real referrer from somewhere.
[email protected]726985e22009-06-18 21:09:281253 params.referrer = GURL(
1254 original_request.httpHeaderField(WebString::fromUTF8("Referer")));
initial.commit09911bf2008-07-26 23:55:291255 }
1256
[email protected]726985e22009-06-18 21:09:281257 string16 method = request.httpMethod();
1258 if (EqualsASCII(method, "POST"))
initial.commit09911bf2008-07-26 23:55:291259 params.is_post = true;
1260
[email protected]c2a797d2009-09-21 16:46:321261 // Save some histogram data so we can compute the average memory used per
1262 // page load of the glyphs.
1263 UMA_HISTOGRAM_COUNTS_10000("Memory.GlyphPagesPerLoad",
1264 webkit_glue::GetGlyphPageCount());
1265
[email protected]15cf526b2010-02-12 06:33:491266 // This message needs to be sent before any of allowScripts(),
1267 // allowImages(), allowPlugins() is called for the new page, so that when
1268 // these functions send a ViewHostMsg_ContentBlocked message, it arrives
1269 // after the ViewHostMsg_FrameNavigate message.
initial.commit09911bf2008-07-26 23:55:291270 Send(new ViewHostMsg_FrameNavigate(routing_id_, params));
1271 } else {
1272 // Subframe navigation: the type depends on whether this navigation
1273 // generated a new session history entry. When they do generate a session
1274 // history entry, it means the user initiated the navigation and we should
1275 // mark it as such. This test checks if this is the first time UpdateURL
1276 // has been called since WillNavigateToURL was called to initiate the load.
1277 if (page_id_ > last_page_id_sent_to_browser_)
1278 params.transition = PageTransition::MANUAL_SUBFRAME;
1279 else
1280 params.transition = PageTransition::AUTO_SUBFRAME;
1281
initial.commit09911bf2008-07-26 23:55:291282 Send(new ViewHostMsg_FrameNavigate(routing_id_, params));
1283 }
1284
1285 last_page_id_sent_to_browser_ =
1286 std::max(last_page_id_sent_to_browser_, page_id_);
1287
1288 // If we end up reusing this WebRequest (for example, due to a #ref click),
[email protected]daa8c58e2009-06-15 17:21:101289 // we don't want the transition type to persist. Just clear it.
1290 navigation_state->set_transition_type(PageTransition::LINK);
[email protected]266eb6f2008-09-30 23:56:501291
[email protected]6c8afae52009-01-22 02:24:571292#if defined(OS_WIN)
[email protected]c7287a92009-11-04 20:06:151293 if (accessibility_.get()) {
[email protected]17455962010-02-24 01:39:351294 // Remove accessibility info cache.
1295 accessibility_.reset();
[email protected]266eb6f2008-09-30 23:56:501296 }
[email protected]6c8afae52009-01-22 02:24:571297#else
[email protected]7d926f92009-03-03 14:26:541298 // TODO(port): accessibility not yet implemented. See http://crbug.com/8288.
[email protected]6c8afae52009-01-22 02:24:571299#endif
initial.commit09911bf2008-07-26 23:55:291300}
1301
1302// Tell the embedding application that the title of the active page has changed
[email protected]3d9689372009-09-10 04:29:171303void RenderView::UpdateTitle(WebFrame* frame, const string16& title) {
initial.commit09911bf2008-07-26 23:55:291304 // Ignore all but top level navigations...
[email protected]3d9689372009-09-10 04:29:171305 if (!frame->parent()) {
[email protected]f0af6a72009-05-30 05:25:171306 Send(new ViewHostMsg_UpdateTitle(
[email protected]3d9689372009-09-10 04:29:171307 routing_id_,
1308 page_id_,
1309 UTF16ToWideHack(title.length() > chrome::kMaxTitleChars ?
1310 title.substr(0, chrome::kMaxTitleChars) : title)));
[email protected]f0af6a72009-05-30 05:25:171311 }
initial.commit09911bf2008-07-26 23:55:291312}
1313
1314void RenderView::UpdateEncoding(WebFrame* frame,
[email protected]41fc0322009-09-04 22:23:401315 const std::string& encoding_name) {
initial.commit09911bf2008-07-26 23:55:291316 // Only update main frame's encoding_name.
[email protected]26aa0482009-09-30 16:55:271317 if (webview()->mainFrame() == frame &&
initial.commit09911bf2008-07-26 23:55:291318 last_encoding_name_ != encoding_name) {
[email protected]e38f40152008-09-12 23:08:301319 // Save the encoding name for later comparing.
initial.commit09911bf2008-07-26 23:55:291320 last_encoding_name_ = encoding_name;
1321
[email protected]e38f40152008-09-12 23:08:301322 Send(new ViewHostMsg_UpdateEncoding(routing_id_, last_encoding_name_));
initial.commit09911bf2008-07-26 23:55:291323 }
1324}
1325
[email protected]f4d34b52008-11-24 23:05:011326// Sends the previous session history state to the browser so it will be saved
1327// before we navigate to a new page. This must be called *before* the page ID
1328// has been updated so we know what it was.
initial.commit09911bf2008-07-26 23:55:291329void RenderView::UpdateSessionHistory(WebFrame* frame) {
1330 // If we have a valid page ID at this point, then it corresponds to the page
1331 // we are navigating away from. Otherwise, this is the first navigation, so
1332 // there is no past session history to record.
1333 if (page_id_ == -1)
1334 return;
1335
[email protected]ca948a22009-06-25 19:36:171336 const WebHistoryItem& item =
[email protected]26aa0482009-09-30 16:55:271337 webview()->mainFrame()->previousHistoryItem();
[email protected]ca948a22009-06-25 19:36:171338 if (item.isNull())
initial.commit09911bf2008-07-26 23:55:291339 return;
[email protected]ca948a22009-06-25 19:36:171340
1341 Send(new ViewHostMsg_UpdateState(
1342 routing_id_, page_id_, webkit_glue::HistoryItemToString(item)));
initial.commit09911bf2008-07-26 23:55:291343}
1344
[email protected]3d9689372009-09-10 04:29:171345void RenderView::OpenURL(
1346 const GURL& url, const GURL& referrer, WebNavigationPolicy policy) {
1347 Send(new ViewHostMsg_OpenURL(
1348 routing_id_, url, referrer, NavigationPolicyToDisposition(policy)));
1349}
1350
[email protected]79dbc662009-09-04 05:42:511351// WebViewDelegate ------------------------------------------------------------
initial.commit09911bf2008-07-26 23:55:291352
initial.commit09911bf2008-07-26 23:55:291353void RenderView::LoadNavigationErrorPage(WebFrame* frame,
[email protected]726985e22009-06-18 21:09:281354 const WebURLRequest& failed_request,
1355 const WebURLError& error,
initial.commit09911bf2008-07-26 23:55:291356 const std::string& html,
1357 bool replace) {
[email protected]726985e22009-06-18 21:09:281358 GURL failed_url = error.unreachableURL;
initial.commit09911bf2008-07-26 23:55:291359
1360 std::string alt_html;
1361 if (html.empty()) {
1362 // Use a local error page.
1363 int resource_id;
1364 DictionaryValue error_strings;
[email protected]726985e22009-06-18 21:09:281365 if (error.reason == net::ERR_CACHE_MISS &&
1366 EqualsASCII(failed_request.httpMethod(), "POST")) {
initial.commit09911bf2008-07-26 23:55:291367 GetFormRepostErrorValues(failed_url, &error_strings);
1368 resource_id = IDR_ERROR_NO_DETAILS_HTML;
1369 } else {
1370 GetLocalizedErrorValues(error, &error_strings);
1371 resource_id = IDR_NET_ERROR_HTML;
1372 }
initial.commit09911bf2008-07-26 23:55:291373
1374 alt_html = GetAltHTMLForTemplate(error_strings, resource_id);
1375 } else {
1376 alt_html = html;
1377 }
1378
[email protected]dd7daa82009-08-10 05:46:451379 frame->loadHTMLString(alt_html,
[email protected]e6f546c32009-07-01 17:12:551380 GURL(kUnreachableWebDataURL),
1381 failed_url,
1382 replace);
initial.commit09911bf2008-07-26 23:55:291383}
1384
[email protected]7ccddb8c2009-08-04 17:36:551385void RenderView::BindDOMAutomationController(WebFrame* frame) {
initial.commit09911bf2008-07-26 23:55:291386 dom_automation_controller_.set_message_sender(this);
1387 dom_automation_controller_.set_routing_id(routing_id_);
[email protected]7ccddb8c2009-08-04 17:36:551388 dom_automation_controller_.BindToJavascript(frame,
initial.commit09911bf2008-07-26 23:55:291389 L"domAutomationController");
1390}
1391
initial.commit09911bf2008-07-26 23:55:291392bool RenderView::RunJavaScriptMessage(int type,
1393 const std::wstring& message,
1394 const std::wstring& default_value,
[email protected]a455d3812009-03-05 20:18:071395 const GURL& frame_url,
initial.commit09911bf2008-07-26 23:55:291396 std::wstring* result) {
1397 bool success = false;
1398 std::wstring result_temp;
1399 if (!result)
1400 result = &result_temp;
initial.commit09911bf2008-07-26 23:55:291401
[email protected]12636df2009-09-28 22:32:211402 SendAndRunNestedMessageLoop(new ViewHostMsg_RunJavaScriptMessage(
1403 routing_id_, message, default_value, frame_url, type, &success, result));
initial.commit09911bf2008-07-26 23:55:291404 return success;
1405}
1406
[email protected]c1f50aa2010-02-18 03:46:571407bool RenderView::SendAndRunNestedMessageLoop(IPC::SyncMessage* message) {
1408 // Before WebKit asks us to show an alert (etc.), it takes care of doing the
1409 // equivalent of WebView::willEnterModalLoop. In the case of showModalDialog
1410 // it is particularly important that we do not call willEnterModalLoop as
1411 // that would defer resource loads for the dialog itself.
1412 if (RenderThread::current()) // Will be NULL during unit tests.
1413 RenderThread::current()->DoNotNotifyWebKitOfModalLoop();
1414
1415 message->EnableMessagePumping(); // Runs a nested message loop.
1416 return Send(message);
1417}
1418
initial.commit09911bf2008-07-26 23:55:291419void RenderView::AddGURLSearchProvider(const GURL& osd_url, bool autodetected) {
1420 if (!osd_url.is_empty())
1421 Send(new ViewHostMsg_PageHasOSDD(routing_id_, page_id_, osd_url,
1422 autodetected));
1423}
1424
[email protected]95056b582010-02-18 01:29:241425void RenderView::OnAutoFillSuggestionsReturned(
1426 int query_id,
1427 const std::vector<string16>& names,
1428 const std::vector<string16>& labels,
1429 int default_suggestion_index) {
1430 if (webview() && query_id == autofill_query_id_) {
1431 webview()->applyAutoFillSuggestions(
1432 autofill_query_node_, names, labels, default_suggestion_index);
1433 }
1434 autofill_query_node_.reset();
1435}
1436
1437void RenderView::OnAutocompleteSuggestionsReturned(
[email protected]acca2a1f2009-10-16 03:53:391438 int query_id,
1439 const std::vector<string16>& suggestions,
[email protected]0ebf3872008-11-07 21:35:031440 int default_suggestion_index) {
[email protected]7e089f272009-11-03 17:07:181441 if (webview() && query_id == autofill_query_id_) {
[email protected]9e3444c2010-02-11 21:30:081442 webview()->applyAutocompleteSuggestions(
[email protected]acca2a1f2009-10-16 03:53:391443 autofill_query_node_, suggestions, default_suggestion_index);
1444 }
1445 autofill_query_node_.reset();
[email protected]0ebf3872008-11-07 21:35:031446}
1447
[email protected]c83641732010-02-20 01:04:481448void RenderView::OnAutoFillFormDataFilled(int query_id, const FormData& form) {
1449 if (query_id != autofill_query_id_)
1450 return;
1451
1452 form_manager_.FillForm(form);
1453}
1454
[email protected]2c4410d2009-05-06 23:46:221455void RenderView::OnPopupNotificationVisibilityChanged(bool visible) {
[email protected]634a6f92008-12-01 21:39:311456 popup_notification_visible_ = visible;
1457}
1458
initial.commit09911bf2008-07-26 23:55:291459uint32 RenderView::GetCPBrowsingContext() {
1460 uint32 context = 0;
1461 Send(new ViewHostMsg_GetCPBrowsingContext(&context));
1462 return context;
1463}
1464
initial.commit09911bf2008-07-26 23:55:291465void RenderView::AddSearchProvider(const std::string& url) {
1466 AddGURLSearchProvider(GURL(url),
1467 false); // not autodetected
1468}
1469
[email protected]f103ab72009-09-02 17:10:591470void RenderView::OnMissingPluginStatus(
1471 WebPluginDelegateProxy* delegate,
1472 int status) {
[email protected]6c8afae52009-01-22 02:24:571473#if defined(OS_WIN)
[email protected]f103ab72009-09-02 17:10:591474 if (!first_default_plugin_) {
initial.commit09911bf2008-07-26 23:55:291475 // Show the InfoBar for the first available plugin.
1476 if (status == default_plugin::MISSING_PLUGIN_AVAILABLE) {
[email protected]f103ab72009-09-02 17:10:591477 first_default_plugin_ = delegate->AsWeakPtr();
initial.commit09911bf2008-07-26 23:55:291478 Send(new ViewHostMsg_MissingPluginStatus(routing_id_, status));
1479 }
1480 } else {
1481 // Closes the InfoBar if user clicks on the plugin (instead of the InfoBar)
1482 // to start the download/install.
1483 if (status == default_plugin::MISSING_PLUGIN_USER_STARTED_DOWNLOAD) {
1484 Send(new ViewHostMsg_MissingPluginStatus(routing_id_, status));
1485 }
1486 }
[email protected]6c8afae52009-01-22 02:24:571487#else
1488 // TODO(port): plugins current not supported
1489 NOTIMPLEMENTED();
1490#endif
initial.commit09911bf2008-07-26 23:55:291491}
1492
[email protected]48c9cf2d2009-09-16 16:47:521493// WebKit::WebViewClient ------------------------------------------------------
1494
1495WebView* RenderView::createView(WebFrame* creator) {
1496 // Check to make sure we aren't overloading on popups.
1497 if (shared_popup_counter_->data > kMaximumNumberOfUnacknowledgedPopups)
1498 return NULL;
1499
1500 // This window can't be closed from a window.close() call until we receive a
1501 // message from the Browser process explicitly allowing it.
1502 popup_notification_visible_ = true;
1503
1504 int32 routing_id = MSG_ROUTING_NONE;
1505 bool user_gesture = creator->isProcessingUserGesture();
[email protected]007a848b2009-10-26 15:55:461506 bool opener_suppressed = creator->willSuppressOpenerInNewFrame();
[email protected]4e6419c2010-01-15 04:50:341507 int64 cloned_session_storage_namespace_id;
[email protected]48c9cf2d2009-09-16 16:47:521508
[email protected]48c9cf2d2009-09-16 16:47:521509 render_thread_->Send(
[email protected]4e6419c2010-01-15 04:50:341510 new ViewHostMsg_CreateWindow(routing_id_, user_gesture,
1511 session_storage_namespace_id_,
1512 &routing_id,
1513 &cloned_session_storage_namespace_id));
[email protected]12636df2009-09-28 22:32:211514 if (routing_id == MSG_ROUTING_NONE)
[email protected]48c9cf2d2009-09-16 16:47:521515 return NULL;
[email protected]48c9cf2d2009-09-16 16:47:521516
[email protected]48c9cf2d2009-09-16 16:47:521517 RenderView* view = RenderView::Create(render_thread_,
[email protected]659f73fa2009-10-13 13:43:421518 0,
[email protected]12636df2009-09-28 22:32:211519 routing_id_,
[email protected]48c9cf2d2009-09-16 16:47:521520 renderer_preferences_,
1521 webkit_preferences_,
[email protected]12636df2009-09-28 22:32:211522 shared_popup_counter_,
[email protected]4e6419c2010-01-15 04:50:341523 routing_id,
1524 cloned_session_storage_namespace_id);
[email protected]48c9cf2d2009-09-16 16:47:521525 view->opened_by_user_gesture_ = user_gesture;
1526
[email protected]007a848b2009-10-26 15:55:461527 // Record whether the creator frame is trying to suppress the opener field.
1528 view->opener_suppressed_ = opener_suppressed;
1529
[email protected]48c9cf2d2009-09-16 16:47:521530 // Record the security origin of the creator.
[email protected]91733b62009-09-18 06:21:091531 GURL creator_url(creator->securityOrigin().toString().utf8());
[email protected]48c9cf2d2009-09-16 16:47:521532 if (!creator_url.is_valid() || !creator_url.IsStandard())
1533 creator_url = GURL();
1534 view->creator_url_ = creator_url;
1535
1536 // Copy over the alternate error page URL so we can have alt error pages in
1537 // the new render view (we don't need the browser to send the URL back down).
1538 view->alternate_error_page_url_ = alternate_error_page_url_;
1539
1540 return view->webview();
1541}
1542
1543WebWidget* RenderView::createPopupMenu(bool activatable) {
1544 RenderWidget* widget = RenderWidget::Create(routing_id_,
1545 render_thread_,
1546 activatable);
1547 return widget->webwidget();
1548}
1549
1550WebWidget* RenderView::createPopupMenu(const WebPopupMenuInfo& info) {
1551 RenderWidget* widget = RenderWidget::Create(routing_id_,
1552 render_thread_,
1553 true);
1554 widget->ConfigureAsExternalPopupMenu(info);
1555 return widget->webwidget();
1556}
1557
[email protected]bd92c3a2010-01-13 05:02:341558WebStorageNamespace* RenderView::createSessionStorageNamespace() {
1559 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kSingleProcess))
1560 return WebStorageNamespace::createSessionStorageNamespace();
[email protected]59afea12010-01-20 04:48:291561 CHECK(session_storage_namespace_id_ != kInvalidSessionStorageNamespaceId);
1562 return new RendererWebStorageNamespaceImpl(DOM_STORAGE_SESSION,
1563 session_storage_namespace_id_);
[email protected]bd92c3a2010-01-13 05:02:341564}
1565
[email protected]48c9cf2d2009-09-16 16:47:521566void RenderView::didAddMessageToConsole(
1567 const WebConsoleMessage& message, const WebString& source_name,
1568 unsigned source_line) {
1569 Send(new ViewHostMsg_AddMessageToConsole(routing_id_,
1570 UTF16ToWideHack(message.text),
1571 static_cast<int32>(source_line),
1572 UTF16ToWideHack(source_name)));
1573}
1574
1575void RenderView::printPage(WebFrame* frame) {
[email protected]71a14262009-09-22 20:02:581576 DCHECK(frame);
1577 Print(frame, true);
[email protected]48c9cf2d2009-09-16 16:47:521578}
1579
1580void RenderView::didStartLoading() {
1581 if (is_loading_) {
1582 DLOG(WARNING) << "didStartLoading called while loading";
1583 return;
1584 }
1585
1586 is_loading_ = true;
1587 // Clear the pointer so that we can assign it only when there is an unknown
1588 // plugin on a page.
1589 first_default_plugin_.reset();
1590
1591 Send(new ViewHostMsg_DidStartLoading(routing_id_));
1592}
1593
1594void RenderView::didStopLoading() {
1595 if (!is_loading_) {
1596 DLOG(WARNING) << "DidStopLoading called while not loading";
1597 return;
1598 }
1599
1600 is_loading_ = false;
1601
1602 // NOTE: For now we're doing the safest thing, and sending out notification
1603 // when done loading. This currently isn't an issue as the favicon is only
1604 // displayed when done loading. Ideally we would send notification when
1605 // finished parsing the head, but webkit doesn't support that yet.
1606 // The feed discovery code would also benefit from access to the head.
[email protected]26aa0482009-09-30 16:55:271607 GURL favicon_url(webview()->mainFrame()->favIconURL());
[email protected]48c9cf2d2009-09-16 16:47:521608 if (!favicon_url.is_empty())
1609 Send(new ViewHostMsg_UpdateFavIconURL(routing_id_, page_id_, favicon_url));
1610
[email protected]26aa0482009-09-30 16:55:271611 AddGURLSearchProvider(webview()->mainFrame()->openSearchDescriptionURL(),
[email protected]48c9cf2d2009-09-16 16:47:521612 true); // autodetected
1613
1614 Send(new ViewHostMsg_DidStopLoading(routing_id_));
1615
1616 MessageLoop::current()->PostDelayedTask(FROM_HERE,
1617 method_factory_.NewRunnableMethod(&RenderView::CapturePageInfo, page_id_,
1618 false),
1619 kDelayForCaptureMs);
[email protected]48c9cf2d2009-09-16 16:47:521620}
1621
[email protected]f55039a2010-02-17 14:12:061622bool RenderView::isSmartInsertDeleteEnabled() {
1623#if defined(OS_MACOSX)
1624 return true;
1625#else
1626 return false;
1627#endif
1628}
1629
[email protected]04fc9482009-09-18 22:13:031630bool RenderView::isSelectTrailingWhitespaceEnabled() {
1631#if defined(OS_WIN)
1632 return true;
1633#else
1634 return false;
1635#endif
1636}
1637
1638void RenderView::setInputMethodEnabled(bool enabled) {
1639 // Save the updated IME status and mark the input focus has been updated.
1640 // The IME status is to be sent to a browser process next time when
1641 // the input caret is rendered.
1642 if (!ime_control_busy_) {
1643 ime_control_updated_ = true;
1644 ime_control_new_state_ = enabled;
1645 }
1646}
1647
1648void RenderView::didChangeSelection(bool is_empty_selection) {
1649#if defined(OS_LINUX)
1650 if (!handling_input_event_)
1651 return;
1652 // TODO(estade): investigate incremental updates to the selection so that we
1653 // don't send the entire selection over IPC every time.
1654 if (!is_empty_selection) {
1655 // Sometimes we get repeated didChangeSelection calls from webkit when
1656 // the selection hasn't actually changed. We don't want to report these
1657 // because it will cause us to continually claim the X clipboard.
1658 const std::string& this_selection =
[email protected]26aa0482009-09-30 16:55:271659 webview()->focusedFrame()->selectionAsText().utf8();
[email protected]04fc9482009-09-18 22:13:031660 if (this_selection == last_selection_)
1661 return;
1662
1663 Send(new ViewHostMsg_SelectionChanged(routing_id_,
1664 this_selection));
1665 last_selection_ = this_selection;
1666 } else {
1667 last_selection_.clear();
1668 }
1669#endif
1670}
1671
1672void RenderView::didExecuteCommand(const WebString& command_name) {
[email protected]afe3a1672009-11-17 19:04:121673 const std::string& name = UTF16ToUTF8(command_name);
1674 if (StartsWithASCII(name, "Move", true) ||
1675 StartsWithASCII(name, "Insert", true) ||
1676 StartsWithASCII(name, "Delete", true))
[email protected]04fc9482009-09-18 22:13:031677 return;
1678 UserMetricsRecordAction(name);
1679}
1680
[email protected]b2528b72009-09-24 06:57:101681bool RenderView::handleCurrentKeyboardEvent() {
1682 if (edit_commands_.empty())
1683 return false;
1684
[email protected]26aa0482009-09-30 16:55:271685 WebFrame* frame = webview()->focusedFrame();
[email protected]b2528b72009-09-24 06:57:101686 if (!frame)
1687 return false;
1688
1689 EditCommands::iterator it = edit_commands_.begin();
1690 EditCommands::iterator end = edit_commands_.end();
1691
[email protected]507b33ea2009-09-29 03:56:511692 bool did_execute_command = false;
[email protected]b2528b72009-09-24 06:57:101693 for (; it != end; ++it) {
[email protected]e6e15012009-09-30 14:59:331694 // In gtk and cocoa, it's possible to bind multiple edit commands to one
1695 // key (but it's the exception). Once one edit command is not executed, it
1696 // seems safest to not execute the rest.
[email protected]b2528b72009-09-24 06:57:101697 if (!frame->executeCommand(WebString::fromUTF8(it->name),
1698 WebString::fromUTF8(it->value)))
1699 break;
[email protected]507b33ea2009-09-29 03:56:511700 did_execute_command = true;
[email protected]b2528b72009-09-24 06:57:101701 }
1702
[email protected]507b33ea2009-09-29 03:56:511703 return did_execute_command;
[email protected]b2528b72009-09-24 06:57:101704}
1705
[email protected]2a3a7762009-10-19 19:17:321706void RenderView::spellCheck(const WebString& text,
1707 int& misspelled_offset,
1708 int& misspelled_length) {
[email protected]1dbafaf72009-09-23 19:43:561709 EnsureDocumentTag();
[email protected]85c55dc2009-11-06 03:05:461710
[email protected]85c55dc2009-11-06 03:05:461711 string16 word(text);
[email protected]cb6037d2009-11-16 22:55:171712 RenderThread* thread = RenderThread::current();
1713 // Will be NULL during unit tests.
1714 if (thread) {
[email protected]c27324b2009-11-19 22:44:291715 thread->spellchecker()->SpellCheckWord(
[email protected]cb6037d2009-11-16 22:55:171716 word.c_str(), word.size(), document_tag_,
1717 &misspelled_offset, &misspelled_length, NULL);
1718 }
[email protected]1dbafaf72009-09-23 19:43:561719}
1720
1721WebString RenderView::autoCorrectWord(const WebKit::WebString& word) {
[email protected]2a3a7762009-10-19 19:17:321722 string16 autocorrect_word;
[email protected]1dbafaf72009-09-23 19:43:561723 const CommandLine& command_line = *CommandLine::ForCurrentProcess();
[email protected]b86c8c12009-10-05 22:01:261724 if (command_line.HasSwitch(switches::kExperimentalSpellcheckerFeatures)) {
[email protected]1dbafaf72009-09-23 19:43:561725 EnsureDocumentTag();
[email protected]cb6037d2009-11-16 22:55:171726 RenderThread* thread = RenderThread::current();
1727 // Will be NULL during unit tests.
1728 if (thread) {
1729 autocorrect_word =
[email protected]c27324b2009-11-19 22:44:291730 thread->spellchecker()->GetAutoCorrectionWord(
[email protected]cb6037d2009-11-16 22:55:171731 word, document_tag_);
1732 }
[email protected]1dbafaf72009-09-23 19:43:561733 }
[email protected]2a3a7762009-10-19 19:17:321734 return autocorrect_word;
[email protected]1dbafaf72009-09-23 19:43:561735}
1736
[email protected]c49085c72009-10-02 16:28:561737void RenderView::showSpellingUI(bool show) {
1738 Send(new ViewHostMsg_ShowSpellingPanel(routing_id_, show));
1739}
1740
[email protected]8922e1f2009-10-03 05:01:261741bool RenderView::isShowingSpellingUI() {
1742 return spelling_panel_visible_;
1743}
1744
[email protected]1dbafaf72009-09-23 19:43:561745void RenderView::updateSpellingUIWithMisspelledWord(const WebString& word) {
[email protected]2a3a7762009-10-19 19:17:321746 Send(new ViewHostMsg_UpdateSpellingPanelWithMisspelledWord(routing_id_,
1747 word));
[email protected]1dbafaf72009-09-23 19:43:561748}
1749
[email protected]a1128322009-10-06 18:38:461750bool RenderView::runFileChooser(
[email protected]01178b52010-01-15 06:59:351751 const WebKit::WebFileChooserParams& params,
[email protected]a1128322009-10-06 18:38:461752 WebKit::WebFileChooserCompletion* chooser_completion) {
1753 if (file_chooser_completion_) {
1754 // TODO(brettw): bug 1235154: This should be a synchronous message to deal
1755 // with the fact that web pages can programatically trigger this. With the
1756 // asnychronous messages, we can get an additional call when one is pending,
1757 // which this test is for. For now, we just ignore the additional file
1758 // chooser request. WebKit doesn't do anything to expect the callback, so
1759 // we can just ignore calling it.
1760 return false;
1761 }
1762 file_chooser_completion_ = chooser_completion;
1763 Send(new ViewHostMsg_RunFileChooser(
[email protected]01178b52010-01-15 06:59:351764 routing_id_, params.multiSelect, params.title,
1765 webkit_glue::WebStringToFilePath(params.initialValue)));
[email protected]a1128322009-10-06 18:38:461766 return true;
1767}
1768
[email protected]48c9cf2d2009-09-16 16:47:521769void RenderView::runModalAlertDialog(
1770 WebFrame* frame, const WebString& message) {
1771 RunJavaScriptMessage(MessageBoxFlags::kIsJavascriptAlert,
1772 UTF16ToWideHack(message),
1773 std::wstring(),
1774 frame->url(),
1775 NULL);
1776}
1777
1778bool RenderView::runModalConfirmDialog(
1779 WebFrame* frame, const WebString& message) {
1780 return RunJavaScriptMessage(MessageBoxFlags::kIsJavascriptConfirm,
1781 UTF16ToWideHack(message),
1782 std::wstring(),
1783 frame->url(),
1784 NULL);
1785}
1786
1787bool RenderView::runModalPromptDialog(
1788 WebFrame* frame, const WebString& message, const WebString& default_value,
1789 WebString* actual_value) {
1790 std::wstring result;
1791 bool ok = RunJavaScriptMessage(MessageBoxFlags::kIsJavascriptPrompt,
1792 UTF16ToWideHack(message),
1793 UTF16ToWideHack(default_value),
1794 frame->url(),
1795 &result);
1796 if (ok)
1797 actual_value->assign(WideToUTF16Hack(result));
1798 return ok;
1799}
1800
1801bool RenderView::runModalBeforeUnloadDialog(
1802 WebFrame* frame, const WebString& message) {
1803 bool success = false;
1804 // This is an ignored return value, but is included so we can accept the same
1805 // response as RunJavaScriptMessage.
1806 std::wstring ignored_result;
[email protected]12636df2009-09-28 22:32:211807 SendAndRunNestedMessageLoop(new ViewHostMsg_RunBeforeUnloadConfirm(
[email protected]48c9cf2d2009-09-16 16:47:521808 routing_id_, frame->url(), UTF16ToWideHack(message), &success,
[email protected]12636df2009-09-28 22:32:211809 &ignored_result));
[email protected]48c9cf2d2009-09-16 16:47:521810 return success;
1811}
1812
[email protected]79e37442009-10-09 18:17:441813void RenderView::showContextMenu(
1814 WebFrame* frame, const WebContextMenuData& data) {
[email protected]c27324b2009-11-19 22:44:291815 ContextMenuParams params = ContextMenuParams(data);
1816 if (!params.misspelled_word.empty() && RenderThread::current()) {
1817 int misspelled_offset, misspelled_length;
[email protected]c76a36a2010-01-26 22:44:041818 bool spelled_right = RenderThread::current()->spellchecker()->
1819 SpellCheckWord(
1820 params.misspelled_word.c_str(), params.misspelled_word.size(),
1821 document_tag_,
1822 &misspelled_offset, &misspelled_length,
1823 &params.dictionary_suggestions);
1824 if (spelled_right)
[email protected]c27324b2009-11-19 22:44:291825 params.misspelled_word.clear();
1826 }
1827
1828 Send(new ViewHostMsg_ContextMenu(routing_id_, params));
[email protected]79e37442009-10-09 18:17:441829}
1830
[email protected]48c9cf2d2009-09-16 16:47:521831void RenderView::setStatusText(const WebString& text) {
1832}
1833
[email protected]163f8242009-10-30 20:19:551834void RenderView::UpdateTargetURL(const GURL& url, const GURL& fallback_url) {
1835 GURL latest_url = url.spec().empty() ? fallback_url : url;
[email protected]48c9cf2d2009-09-16 16:47:521836 if (latest_url == target_url_)
1837 return;
[email protected]163f8242009-10-30 20:19:551838
[email protected]48c9cf2d2009-09-16 16:47:521839 // Tell the browser to display a destination link.
1840 if (target_url_status_ == TARGET_INFLIGHT ||
1841 target_url_status_ == TARGET_PENDING) {
1842 // If we have a request in-flight, save the URL to be sent when we
1843 // receive an ACK to the in-flight request. We can happily overwrite
1844 // any existing pending sends.
1845 pending_target_url_ = latest_url;
1846 target_url_status_ = TARGET_PENDING;
1847 } else {
1848 Send(new ViewHostMsg_UpdateTargetURL(routing_id_, page_id_, latest_url));
1849 target_url_ = latest_url;
1850 target_url_status_ = TARGET_INFLIGHT;
1851 }
1852}
1853
[email protected]882daa92009-11-05 16:31:311854void RenderView::StartNavStateSyncTimerIfNecessary() {
1855 int delay;
1856 if (send_content_state_immediately_)
1857 delay = 0;
1858 else if (is_hidden())
1859 delay = kDelaySecondsForContentStateSyncHidden;
1860 else
1861 delay = kDelaySecondsForContentStateSync;
1862
1863 if (nav_state_sync_timer_.IsRunning()) {
1864 // The timer is already running. If the delay of the timer maches the amount
1865 // we want to delay by, then return. Otherwise stop the timer so that it
1866 // gets started with the right delay.
1867 if (nav_state_sync_timer_.GetCurrentDelay().InSeconds() == delay)
1868 return;
1869 nav_state_sync_timer_.Stop();
1870 }
1871
1872 nav_state_sync_timer_.Start(
1873 TimeDelta::FromSeconds(delay), this, &RenderView::SyncNavigationState);
1874}
1875
[email protected]163f8242009-10-30 20:19:551876void RenderView::setMouseOverURL(const WebURL& url) {
1877 mouse_over_url_ = GURL(url);
1878 UpdateTargetURL(mouse_over_url_, focus_url_);
1879}
1880
1881void RenderView::setKeyboardFocusURL(const WebURL& url) {
1882 focus_url_ = GURL(url);
1883 UpdateTargetURL(focus_url_, mouse_over_url_);
1884}
1885
[email protected]48c9cf2d2009-09-16 16:47:521886void RenderView::setToolTipText(const WebString& text, WebTextDirection hint) {
1887 Send(new ViewHostMsg_SetTooltipText(routing_id_, UTF16ToWideHack(text),
1888 hint));
1889}
1890
1891void RenderView::startDragging(const WebPoint& from, const WebDragData& data,
1892 WebDragOperationsMask allowed_ops) {
1893 Send(new ViewHostMsg_StartDragging(routing_id_,
1894 WebDropData(data),
1895 allowed_ops));
1896}
1897
[email protected]28b92df2009-09-25 17:35:451898bool RenderView::acceptsLoadDrops() {
1899 return renderer_preferences_.can_accept_load_drops;
1900}
1901
[email protected]48c9cf2d2009-09-16 16:47:521902void RenderView::focusNext() {
1903 Send(new ViewHostMsg_TakeFocus(routing_id_, false));
1904}
1905
1906void RenderView::focusPrevious() {
1907 Send(new ViewHostMsg_TakeFocus(routing_id_, true));
1908}
1909
1910void RenderView::navigateBackForwardSoon(int offset) {
1911 history_back_list_count_ += offset;
1912 history_forward_list_count_ -= offset;
1913
1914 Send(new ViewHostMsg_GoToEntryAtOffset(routing_id_, offset));
1915}
1916
1917int RenderView::historyBackListCount() {
1918 return history_back_list_count_;
1919}
1920
1921int RenderView::historyForwardListCount() {
1922 return history_forward_list_count_;
1923}
1924
1925void RenderView::didAddHistoryItem() {
1926 // We don't want to update the history length for the start page
1927 // navigation.
[email protected]26aa0482009-09-30 16:55:271928 WebFrame* main_frame = webview()->mainFrame();
[email protected]48c9cf2d2009-09-16 16:47:521929 DCHECK(main_frame != NULL);
1930
1931 WebDataSource* ds = main_frame->dataSource();
1932 DCHECK(ds != NULL);
1933
1934 NavigationState* navigation_state = NavigationState::FromDataSource(ds);
1935 DCHECK(navigation_state);
1936 if (navigation_state->transition_type() == PageTransition::START_PAGE)
1937 return;
1938
1939 history_back_list_count_++;
1940 history_forward_list_count_ = 0;
1941}
1942
[email protected]8922e1f2009-10-03 05:01:261943void RenderView::didUpdateInspectorSettings() {
1944 Send(new ViewHostMsg_UpdateInspectorSettings(
1945 routing_id_, webview()->inspectorSettings().utf8()));
1946}
1947
[email protected]acca2a1f2009-10-16 03:53:391948void RenderView::queryAutofillSuggestions(const WebNode& node,
1949 const WebString& name,
1950 const WebString& value) {
1951 static int query_counter = 0;
1952 autofill_query_id_ = query_counter++;
1953 autofill_query_node_ = node;
[email protected]95056b582010-02-18 01:29:241954 const WebKit::WebInputElement input_element =
1955 node.toConstElement<WebInputElement>();
[email protected]acca2a1f2009-10-16 03:53:391956 Send(new ViewHostMsg_QueryFormFieldAutofill(
[email protected]95056b582010-02-18 01:29:241957 routing_id_, autofill_query_id_, FormField(input_element)));
[email protected]acca2a1f2009-10-16 03:53:391958}
1959
1960void RenderView::removeAutofillSuggestions(const WebString& name,
1961 const WebString& value) {
1962 Send(new ViewHostMsg_RemoveAutofillEntry(routing_id_, name, value));
1963}
1964
[email protected]c83641732010-02-20 01:04:481965void RenderView::didAcceptAutoFillSuggestion(
1966 const WebKit::WebNode& node,
1967 const WebKit::WebString& name,
1968 const WebKit::WebString& label) {
1969 static int query_counter = 0;
1970 autofill_query_id_ = query_counter++;
1971
1972 FormData form;
1973 const WebInputElement element = node.toConstElement<WebInputElement>();
1974 if (!form_manager_.FindForm(element, &form))
1975 return;
1976
1977 Send(new ViewHostMsg_FillAutoFillFormData(
1978 routing_id_, autofill_query_id_, form, name, label));
1979}
1980
[email protected]79dbc662009-09-04 05:42:511981// WebKit::WebWidgetClient ----------------------------------------------------
1982
initial.commit09911bf2008-07-26 23:55:291983// We are supposed to get a single call to Show for a newly created RenderView
1984// that was created via RenderView::CreateWebView. So, we wait until this
1985// point to dispatch the ShowView message.
1986//
1987// This method provides us with the information about how to display the newly
1988// created RenderView (i.e., as a constrained popup or as a new tab).
1989//
[email protected]4873c7d2009-07-16 06:36:281990void RenderView::show(WebNavigationPolicy policy) {
initial.commit09911bf2008-07-26 23:55:291991 DCHECK(!did_show_) << "received extraneous Show call";
1992 DCHECK(opener_id_ != MSG_ROUTING_NONE);
1993
1994 if (did_show_)
1995 return;
1996 did_show_ = true;
1997
[email protected]28295ec2009-10-16 05:34:331998 // Force new windows to a popup if they were not opened with a user gesture.
1999 if (!opened_by_user_gesture_) {
2000 // We exempt background tabs for compat with older versions of Chrome.
2001 // TODO(darin): This seems bogus. These should have a user gesture, so
2002 // we probably don't need this check.
2003 if (policy != WebKit::WebNavigationPolicyNewBackgroundTab)
2004 policy = WebKit::WebNavigationPolicyNewPopup;
2005 }
2006
initial.commit09911bf2008-07-26 23:55:292007 // NOTE: initial_pos_ may still have its default values at this point, but
2008 // that's okay. It'll be ignored if disposition is not NEW_POPUP, or the
2009 // browser process will impose a default position otherwise.
[email protected]4873c7d2009-07-16 06:36:282010 Send(new ViewHostMsg_ShowView(opener_id_, routing_id_,
2011 NavigationPolicyToDisposition(policy), initial_pos_,
[email protected]7e7414ae2010-01-26 20:19:292012 opened_by_user_gesture_));
[email protected]2533ce12009-05-09 00:02:242013 SetPendingWindowRect(initial_pos_);
initial.commit09911bf2008-07-26 23:55:292014}
2015
[email protected]4873c7d2009-07-16 06:36:282016void RenderView::closeWidgetSoon() {
[email protected]2c4410d2009-05-06 23:46:222017 if (!popup_notification_visible_)
[email protected]4873c7d2009-07-16 06:36:282018 RenderWidget::closeWidgetSoon();
[email protected]634a6f92008-12-01 21:39:312019}
2020
[email protected]4873c7d2009-07-16 06:36:282021void RenderView::runModal() {
initial.commit09911bf2008-07-26 23:55:292022 DCHECK(did_show_) << "should already have shown the view";
2023
[email protected]c1f50aa2010-02-18 03:46:572024 // We must keep WebKit's shared timer running in this case in order to allow
2025 // showModalDialog to function properly.
2026 //
2027 // TODO(darin): WebKit should really be smarter about suppressing events and
2028 // timers so that we do not need to manage the shared timer in such a heavy
2029 // handed manner.
2030 //
2031 if (RenderThread::current()) // Will be NULL during unit tests.
2032 RenderThread::current()->DoNotSuspendWebKitSharedTimer();
2033
[email protected]12636df2009-09-28 22:32:212034 SendAndRunNestedMessageLoop(new ViewHostMsg_RunModal(routing_id_));
initial.commit09911bf2008-07-26 23:55:292035}
2036
[email protected]3d9689372009-09-10 04:29:172037// WebKit::WebFrameClient -----------------------------------------------------
2038
2039WebPlugin* RenderView::createPlugin(
2040 WebFrame* frame, const WebPluginParams& params) {
2041 return new webkit_glue::WebPluginImpl(frame, params, AsWeakPtr());
2042}
2043
2044WebWorker* RenderView::createWorker(WebFrame* frame, WebWorkerClient* client) {
2045 return new WebWorkerProxy(client, RenderThread::current(), routing_id_);
2046}
2047
[email protected]9c00f002009-11-05 22:37:422048WebSharedWorker* RenderView::createSharedWorker(
2049 WebFrame* frame, const WebURL& url, const WebString& name,
[email protected]30447b62009-11-13 01:13:372050 unsigned long long document_id) {
[email protected]9c00f002009-11-05 22:37:422051
[email protected]30447b62009-11-13 01:13:372052 int route_id = MSG_ROUTING_NONE;
[email protected]6de0bcf2010-02-17 22:00:512053 bool exists = false;
[email protected]30447b62009-11-13 01:13:372054 bool url_mismatch = false;
[email protected]6de0bcf2010-02-17 22:00:512055 ViewHostMsg_CreateWorker_Params params;
2056 params.url = url;
2057 params.is_shared = true;
2058 params.name = name;
2059 params.document_id = document_id;
2060 params.render_view_route_id = routing_id_;
2061 params.route_id = MSG_ROUTING_NONE;
[email protected]30447b62009-11-13 01:13:372062 Send(new ViewHostMsg_LookupSharedWorker(
[email protected]6de0bcf2010-02-17 22:00:512063 params, &exists, &route_id, &url_mismatch));
[email protected]30447b62009-11-13 01:13:372064 if (url_mismatch) {
2065 return NULL;
2066 } else {
2067 return new WebSharedWorkerProxy(RenderThread::current(),
[email protected]0791d3a2010-01-28 01:28:492068 document_id,
[email protected]6de0bcf2010-02-17 22:00:512069 exists,
[email protected]30447b62009-11-13 01:13:372070 route_id,
2071 routing_id_);
2072 }
[email protected]9c00f002009-11-05 22:37:422073}
2074
[email protected]3d9689372009-09-10 04:29:172075WebMediaPlayer* RenderView::createMediaPlayer(
2076 WebFrame* frame, WebMediaPlayerClient* client) {
2077 scoped_refptr<media::FilterFactoryCollection> factory =
2078 new media::FilterFactoryCollection();
2079 // Add in any custom filter factories first.
2080 const CommandLine* cmd_line = CommandLine::ForCurrentProcess();
2081 if (!cmd_line->HasSwitch(switches::kDisableAudio)) {
2082 // Add the chrome specific audio renderer.
2083 factory->AddFactory(
2084 AudioRendererImpl::CreateFactory(audio_message_filter()));
2085 }
2086
[email protected]80f584d92010-01-21 03:59:042087 WebApplicationCacheHostImpl* appcache_host =
2088 WebApplicationCacheHostImpl::FromFrame(frame);
2089
[email protected]3d9689372009-09-10 04:29:172090 // TODO(hclam): obtain the following parameters from |client|.
2091 webkit_glue::MediaResourceLoaderBridgeFactory* bridge_factory =
2092 new webkit_glue::MediaResourceLoaderBridgeFactory(
[email protected]810a52ef2010-01-08 01:22:152093 GURL(), // referrer
2094 "null", // frame origin
2095 "null", // main_frame_origin
[email protected]3d9689372009-09-10 04:29:172096 base::GetCurrentProcId(),
[email protected]80f584d92010-01-21 03:59:042097 appcache_host ? appcache_host->host_id() : appcache::kNoHostId,
[email protected]3d9689372009-09-10 04:29:172098 routing_id());
2099
[email protected]0436b9a2009-10-23 00:23:052100 // A simple data source that keeps all data in memory.
2101 media::FilterFactory* simple_data_source_factory =
2102 webkit_glue::SimpleDataSource::CreateFactory(MessageLoop::current(),
2103 bridge_factory);
2104 // A sophisticated data source that does memory caching.
2105 media::FilterFactory* buffered_data_source_factory =
2106 webkit_glue::BufferedDataSource::CreateFactory(MessageLoop::current(),
2107 bridge_factory);
2108 if (cmd_line->HasSwitch(switches::kSimpleDataSource)) {
2109 factory->AddFactory(simple_data_source_factory);
2110 factory->AddFactory(buffered_data_source_factory);
[email protected]3d9689372009-09-10 04:29:172111 } else {
[email protected]0436b9a2009-10-23 00:23:052112 factory->AddFactory(buffered_data_source_factory);
2113 factory->AddFactory(simple_data_source_factory);
[email protected]3d9689372009-09-10 04:29:172114 }
[email protected]8400e032010-02-26 18:50:112115
2116 webkit_glue::WebVideoRendererFactoryFactory* factory_factory = NULL;
2117 if (cmd_line->HasSwitch(switches::kEnableVideoLayering)) {
2118 factory_factory = new IPCVideoRenderer::FactoryFactory(routing_id_);
2119 } else {
2120 factory_factory = new webkit_glue::VideoRendererImpl::FactoryFactory();
2121 }
2122
2123 return new webkit_glue::WebMediaPlayerImpl(client, factory, factory_factory);
[email protected]3d9689372009-09-10 04:29:172124}
2125
[email protected]b921cfd22010-02-25 16:57:512126WebCookieJar* RenderView::cookieJar() {
2127 return &cookie_jar_;
2128}
2129
[email protected]3d9689372009-09-10 04:29:172130void RenderView::willClose(WebFrame* frame) {
2131 if (!frame->parent()) {
2132 const GURL& url = frame->url();
2133 if (url.SchemeIs("http") || url.SchemeIs("https"))
2134 DumpLoadHistograms();
2135 }
[email protected]fa7b6b542009-11-03 05:02:302136
2137 WebDataSource* ds = frame->dataSource();
2138 NavigationState* navigation_state = NavigationState::FromDataSource(ds);
2139 navigation_state->user_script_idle_scheduler()->Cancel();
[email protected]3d9689372009-09-10 04:29:172140}
2141
[email protected]684e4a42010-01-30 06:44:112142bool RenderView::allowPlugins(WebFrame* frame, bool enabled_per_settings) {
[email protected]8934a3b2010-02-25 00:34:002143 if (!enabled_per_settings)
2144 return false;
[email protected]c21f1d52010-03-04 03:19:432145 return AllowContentType(CONTENT_SETTINGS_TYPE_PLUGINS);
[email protected]684e4a42010-01-30 06:44:112146}
2147
2148bool RenderView::allowImages(WebFrame* frame, bool enabled_per_settings) {
[email protected]8934a3b2010-02-25 00:34:002149 if (!enabled_per_settings)
2150 return false;
2151 if (!AllowContentType(CONTENT_SETTINGS_TYPE_IMAGES)) {
2152 DidBlockContentType(CONTENT_SETTINGS_TYPE_IMAGES);
2153 return false;
2154 }
2155 return true;
[email protected]684e4a42010-01-30 06:44:112156}
2157
[email protected]3d9689372009-09-10 04:29:172158void RenderView::loadURLExternally(
2159 WebFrame* frame, const WebURLRequest& request,
2160 WebNavigationPolicy policy) {
[email protected]efce17b2009-09-11 18:04:592161 GURL referrer(request.httpHeaderField(WebString::fromUTF8("Referer")));
2162 if (policy == WebKit::WebNavigationPolicyDownload) {
2163 Send(new ViewHostMsg_DownloadUrl(routing_id_, request.url(), referrer));
2164 } else {
2165 OpenURL(request.url(), referrer, policy);
2166 }
[email protected]3d9689372009-09-10 04:29:172167}
2168
2169WebNavigationPolicy RenderView::decidePolicyForNavigation(
2170 WebFrame* frame, const WebURLRequest& request, WebNavigationType type,
[email protected]65b95cd2009-10-09 05:10:222171 const WebNode&, WebNavigationPolicy default_policy, bool is_redirect) {
[email protected]3d9689372009-09-10 04:29:172172 // Webkit is asking whether to navigate to a new URL.
2173 // This is fine normally, except if we're showing UI from one security
2174 // context and they're trying to navigate to a different context.
2175 const GURL& url = request.url();
2176
2177 // If the browser is interested, then give it a chance to look at top level
2178 // navigations
2179 if (renderer_preferences_.browser_handles_top_level_requests &&
2180 // Only send once.
2181 last_top_level_navigation_page_id_ != page_id_ &&
2182 // Not interested in reloads.
2183 type != WebKit::WebNavigationTypeReload &&
2184 type != WebKit::WebNavigationTypeFormSubmitted &&
2185 // Must be a top level frame.
2186 frame->parent() == NULL) {
2187 // Skip if navigation is on the same page (using '#').
2188 GURL frame_origin = GURL(frame->url()).GetOrigin();
2189 if (url.GetOrigin() != frame_origin || url.ref().empty()) {
2190 last_top_level_navigation_page_id_ = page_id_;
[email protected]b36a9f92009-10-19 17:34:572191 GURL referrer(request.httpHeaderField(WebString::fromUTF8("Referer")));
2192 OpenURL(url, referrer, default_policy);
[email protected]3d9689372009-09-10 04:29:172193 return WebKit::WebNavigationPolicyIgnore; // Suppress the load here.
2194 }
2195 }
2196
2197 // A content initiated navigation may have originated from a link-click,
2198 // script, drag-n-drop operation, etc.
2199 bool is_content_initiated =
2200 NavigationState::FromDataSource(frame->provisionalDataSource())->
2201 is_content_initiated();
2202
2203 // We only care about navigations that are within the current tab (as opposed
2204 // to, for example, opening a new window).
2205 // But we sometimes navigate to about:blank to clear a tab, and we want to
2206 // still allow that.
2207 if (default_policy == WebKit::WebNavigationPolicyCurrentTab &&
2208 is_content_initiated && frame->parent() == NULL &&
2209 !url.SchemeIs(chrome::kAboutScheme)) {
2210 // When we received such unsolicited navigations, we sometimes want to
2211 // punt them up to the browser to handle.
2212 if (BindingsPolicy::is_dom_ui_enabled(enabled_bindings_) ||
2213 BindingsPolicy::is_extension_enabled(enabled_bindings_) ||
2214 frame->isViewSourceModeEnabled() ||
2215 url.SchemeIs(chrome::kViewSourceScheme) ||
2216 url.SchemeIs(chrome::kPrintScheme)) {
2217 OpenURL(url, GURL(), default_policy);
2218 return WebKit::WebNavigationPolicyIgnore; // Suppress the load here.
2219 }
2220 }
2221
2222 // Detect when a page is "forking" a new tab that can be safely rendered in
2223 // its own process. This is done by sites like Gmail that try to open links
2224 // in new windows without script connections back to the original page. We
2225 // treat such cases as browser navigations (in which we will create a new
2226 // renderer for a cross-site navigation), rather than WebKit navigations.
2227 //
2228 // We use the following heuristic to decide whether to fork a new page in its
2229 // own process:
2230 // The parent page must open a new tab to about:blank, set the new tab's
2231 // window.opener to null, and then redirect the tab to a cross-site URL using
2232 // JavaScript.
[email protected]007a848b2009-10-26 15:55:462233 //
2234 // TODO(creis): Deprecate this logic once we can rely on rel=noreferrer
2235 // (see below).
[email protected]3d9689372009-09-10 04:29:172236 bool is_fork =
2237 // Must start from a tab showing about:blank, which is later redirected.
[email protected]e0d481582009-09-15 21:06:252238 GURL(frame->url()) == GURL(chrome::kAboutBlankURL) &&
[email protected]3d9689372009-09-10 04:29:172239 // Must be the first real navigation of the tab.
[email protected]48c9cf2d2009-09-16 16:47:522240 historyBackListCount() < 1 &&
2241 historyForwardListCount() < 1 &&
[email protected]3d9689372009-09-10 04:29:172242 // The parent page must have set the child's window.opener to null before
2243 // redirecting to the desired URL.
2244 frame->opener() == NULL &&
2245 // Must be a top-level frame.
2246 frame->parent() == NULL &&
2247 // Must not have issued the request from this page.
2248 is_content_initiated &&
2249 // Must be targeted at the current tab.
2250 default_policy == WebKit::WebNavigationPolicyCurrentTab &&
2251 // Must be a JavaScript navigation, which appears as "other".
2252 type == WebKit::WebNavigationTypeOther;
[email protected]007a848b2009-10-26 15:55:462253
2254 // Recognize if this navigation is from a link with rel=noreferrer and
2255 // target=_blank attributes, in which case the opener will be suppressed. If
2256 // so, it is safe to load cross-site pages in a separate process, so we
2257 // should let the browser handle it.
2258 bool is_noreferrer_and_blank_target =
2259 // Frame should be top level and not yet navigated.
2260 frame->parent() == NULL &&
2261 frame->url().isEmpty() &&
2262 historyBackListCount() < 1 &&
2263 historyForwardListCount() < 1 &&
2264 // Links with rel=noreferrer will have no Referer field, and their
2265 // resulting frame will have its window.opener suppressed.
2266 // TODO(creis): should add a request.httpReferrer() method to help avoid
2267 // typos on the unusual spelling of Referer.
2268 request.httpHeaderField(WebString::fromUTF8("Referer")).isNull() &&
2269 opener_suppressed_ &&
2270 frame->opener() == NULL &&
2271 // Links with target=_blank will have no name.
2272 frame->name().isNull() &&
2273 // Another frame (with a non-empty creator) should have initiated the
2274 // request, targeted at this frame.
2275 !creator_url_.is_empty() &&
2276 is_content_initiated &&
2277 default_policy == WebKit::WebNavigationPolicyCurrentTab &&
2278 type == WebKit::WebNavigationTypeOther;
2279
2280 if (is_fork || is_noreferrer_and_blank_target) {
[email protected]3d9689372009-09-10 04:29:172281 // Open the URL via the browser, not via WebKit.
2282 OpenURL(url, GURL(), default_policy);
2283 return WebKit::WebNavigationPolicyIgnore;
2284 }
2285
2286 return default_policy;
2287}
2288
[email protected]6069da8c2009-10-20 20:33:492289bool RenderView::canHandleRequest(
2290 WebFrame* frame, const WebURLRequest& request) {
2291 // We allow WebKit to think that everything can be handled even though
2292 // browser-side we limit what we load.
[email protected]7b7a7dc2009-10-19 02:23:342293 return true;
2294}
2295
[email protected]6069da8c2009-10-20 20:33:492296WebURLError RenderView::cannotHandleRequestError(
2297 WebFrame* frame, const WebURLRequest& request) {
2298 NOTREACHED(); // Since we said we can handle all requests.
2299 return WebURLError();
2300}
2301
2302WebURLError RenderView::cancelledError(
2303 WebFrame* frame, const WebURLRequest& request) {
2304 WebURLError error;
2305 error.domain = WebString::fromUTF8(net::kErrorDomain);
2306 error.reason = net::ERR_ABORTED;
2307 error.unreachableURL = request.url();
2308 return error;
[email protected]7b7a7dc2009-10-19 02:23:342309}
2310
2311void RenderView::unableToImplementPolicyWithError(
[email protected]6069da8c2009-10-20 20:33:492312 WebFrame*, const WebURLError&) {
2313 NOTREACHED(); // Since we said we can handle all requests.
[email protected]7b7a7dc2009-10-19 02:23:342314}
2315
[email protected]979c28b2009-11-07 01:30:482316void RenderView::willSubmitForm(WebFrame* frame, const WebFormElement& form) {
[email protected]3d9689372009-09-10 04:29:172317 NavigationState* navigation_state =
2318 NavigationState::FromDataSource(frame->provisionalDataSource());
2319
2320 if (navigation_state->transition_type() == PageTransition::LINK)
2321 navigation_state->set_transition_type(PageTransition::FORM_SUBMIT);
2322
2323 // Save these to be processed when the ensuing navigation is committed.
[email protected]ce0e250d2009-10-23 21:00:352324 WebSearchableFormData web_searchable_form_data(form);
2325 navigation_state->set_searchable_form_url(web_searchable_form_data.url());
2326 navigation_state->set_searchable_form_encoding(
[email protected]b7910b3a2010-01-13 18:33:212327 web_searchable_form_data.encoding().utf8());
[email protected]3d9689372009-09-10 04:29:172328 navigation_state->set_password_form_data(
2329 PasswordFormDomManager::CreatePasswordForm(form));
2330
[email protected]979c28b2009-11-07 01:30:482331 if (form.autoComplete()) {
[email protected]c54d269e2009-10-21 18:07:382332 scoped_ptr<FormFieldValues> form_values(FormFieldValues::Create(form));
2333 if (form_values.get())
[email protected]51bd36612009-10-20 22:49:472334 Send(new ViewHostMsg_FormFieldValuesSubmitted(routing_id_,
[email protected]c54d269e2009-10-21 18:07:382335 *form_values));
[email protected]3d9689372009-09-10 04:29:172336 }
2337}
2338
2339void RenderView::willPerformClientRedirect(
2340 WebFrame* frame, const WebURL& from, const WebURL& to, double interval,
2341 double fire_time) {
2342 // Ignore
2343}
2344
2345void RenderView::didCancelClientRedirect(WebFrame* frame) {
2346 // Ignore
2347}
2348
2349void RenderView::didCompleteClientRedirect(
2350 WebFrame* frame, const WebURL& from) {
2351 if (!frame->parent())
2352 completed_client_redirect_src_ = from;
2353}
2354
2355void RenderView::didCreateDataSource(WebFrame* frame, WebDataSource* ds) {
2356 // The rest of RenderView assumes that a WebDataSource will always have a
2357 // non-null NavigationState.
[email protected]a7ccc4d2010-01-27 08:14:482358 bool content_initiated = !pending_navigation_state_.get();
2359 NavigationState* state = content_initiated ?
2360 NavigationState::CreateContentInitiated() :
2361 pending_navigation_state_.release();
[email protected]4c1b6f0b2010-02-07 16:38:182362 if (content_initiated) {
2363 switch (ds->request().cachePolicy()) {
2364 case WebURLRequest::UseProtocolCachePolicy: // normal load.
2365 state->set_load_type(NavigationState::LINK_LOAD_NORMAL);
2366 break;
2367 case WebURLRequest::ReloadIgnoringCacheData: // reload.
2368 state->set_load_type(NavigationState::LINK_LOAD_RELOAD);
2369 break;
2370 case WebURLRequest::ReturnCacheDataElseLoad: // allow stale data.
2371 state->set_load_type(NavigationState::LINK_LOAD_CACHE_STALE_OK);
2372 break;
2373 case WebURLRequest::ReturnCacheDataDontLoad: // Don't re-post.
2374 state->set_load_type(NavigationState::LINK_LOAD_CACHE_ONLY);
2375 break;
2376 }
2377 }
[email protected]fa7b6b542009-11-03 05:02:302378
2379 state->set_user_script_idle_scheduler(
2380 new UserScriptIdleScheduler(this, frame));
2381 ds->setExtraData(state);
[email protected]3d9689372009-09-10 04:29:172382}
2383
2384void RenderView::didStartProvisionalLoad(WebFrame* frame) {
2385 WebDataSource* ds = frame->provisionalDataSource();
2386 NavigationState* navigation_state = NavigationState::FromDataSource(ds);
2387
2388 navigation_state->set_start_load_time(Time::Now());
2389
2390 // Update the request time if WebKit has better knowledge of it.
2391 if (navigation_state->request_time().is_null()) {
2392 double event_time = ds->triggeringEventTime();
2393 if (event_time != 0.0)
2394 navigation_state->set_request_time(Time::FromDoubleT(event_time));
2395 }
2396
2397 bool is_top_most = !frame->parent();
2398 if (is_top_most) {
2399 navigation_gesture_ = frame->isProcessingUserGesture() ?
2400 NavigationGestureUnknown : NavigationGestureAuto;
2401
2402 // Make sure redirect tracking state is clear for the new load.
2403 completed_client_redirect_src_ = GURL();
2404 } else if (frame->parent()->isLoading()) {
2405 // Take note of AUTO_SUBFRAME loads here, so that we can know how to
[email protected]4fb66842009-12-04 21:41:002406 // load an error page. See didFailProvisionalLoad.
[email protected]3d9689372009-09-10 04:29:172407 navigation_state->set_transition_type(PageTransition::AUTO_SUBFRAME);
2408 }
2409
2410 Send(new ViewHostMsg_DidStartProvisionalLoadForFrame(
2411 routing_id_, is_top_most, ds->request().url()));
2412}
2413
2414void RenderView::didReceiveServerRedirectForProvisionalLoad(WebFrame* frame) {
2415 if (frame->parent())
2416 return;
2417 // Received a redirect on the main frame.
2418 WebDataSource* data_source = frame->provisionalDataSource();
2419 if (!data_source) {
2420 // Should only be invoked when we have a data source.
2421 NOTREACHED();
2422 return;
2423 }
2424 std::vector<GURL> redirects;
2425 GetRedirectChain(data_source, &redirects);
2426 if (redirects.size() >= 2) {
[email protected]40bd6582009-12-04 23:49:512427 Send(new ViewHostMsg_DidRedirectProvisionalLoad(routing_id_, page_id_,
2428 redirects[redirects.size() - 2], redirects.back()));
[email protected]3d9689372009-09-10 04:29:172429 }
2430}
2431
[email protected]40bd6582009-12-04 23:49:512432void RenderView::didFailProvisionalLoad(WebFrame* frame,
2433 const WebURLError& error) {
[email protected]3d9689372009-09-10 04:29:172434 // Notify the browser that we failed a provisional load with an error.
2435 //
2436 // Note: It is important this notification occur before DidStopLoading so the
2437 // SSL manager can react to the provisional load failure before being
2438 // notified the load stopped.
2439 //
2440 WebDataSource* ds = frame->provisionalDataSource();
2441 DCHECK(ds);
2442
2443 const WebURLRequest& failed_request = ds->request();
2444
2445 bool show_repost_interstitial =
2446 (error.reason == net::ERR_CACHE_MISS &&
2447 EqualsASCII(failed_request.httpMethod(), "POST"));
2448 Send(new ViewHostMsg_DidFailProvisionalLoadWithError(
2449 routing_id_, !frame->parent(), error.reason, error.unreachableURL,
2450 show_repost_interstitial));
2451
2452 // Don't display an error page if this is simply a cancelled load. Aside
2453 // from being dumb, WebCore doesn't expect it and it will cause a crash.
2454 if (error.reason == net::ERR_ABORTED)
2455 return;
2456
2457 // Make sure we never show errors in view source mode.
2458 frame->enableViewSourceMode(false);
2459
2460 NavigationState* navigation_state = NavigationState::FromDataSource(ds);
2461
2462 // If this is a failed back/forward/reload navigation, then we need to do a
2463 // 'replace' load. This is necessary to avoid messing up session history.
2464 // Otherwise, we do a normal load, which simulates a 'go' navigation as far
2465 // as session history is concerned.
2466 //
2467 // AUTO_SUBFRAME loads should always be treated as loads that do not advance
2468 // the page id.
2469 //
2470 bool replace =
2471 navigation_state->pending_page_id() != -1 ||
2472 navigation_state->transition_type() == PageTransition::AUTO_SUBFRAME;
2473
2474 // If we failed on a browser initiated request, then make sure that our error
2475 // page load is regarded as the same browser initiated request.
2476 if (!navigation_state->is_content_initiated()) {
2477 pending_navigation_state_.reset(NavigationState::CreateBrowserInitiated(
2478 navigation_state->pending_page_id(),
2479 navigation_state->transition_type(),
2480 navigation_state->request_time()));
2481 }
2482
2483 // Provide the user with a more helpful error page?
2484 if (MaybeLoadAlternateErrorPage(frame, error, replace))
2485 return;
2486
2487 // Fallback to a local error page.
2488 LoadNavigationErrorPage(frame, failed_request, error, std::string(),
2489 replace);
2490}
2491
2492void RenderView::didReceiveDocumentData(
2493 WebFrame* frame, const char* data, size_t data_len,
2494 bool& prevent_default) {
2495 NavigationState* navigation_state =
2496 NavigationState::FromDataSource(frame->dataSource());
2497 if (!navigation_state->postpone_loading_data())
2498 return;
2499
2500 // We're going to call commitDocumentData ourselves...
2501 prevent_default = true;
2502
2503 // Continue buffering the response data for the original 404 page. If it
2504 // grows too large, then we'll just let it through.
2505 navigation_state->append_postponed_data(data, data_len);
2506 if (navigation_state->postponed_data().size() >= 512) {
2507 navigation_state->set_postpone_loading_data(false);
2508 frame->commitDocumentData(navigation_state->postponed_data().data(),
2509 navigation_state->postponed_data().size());
2510 navigation_state->clear_postponed_data();
2511 }
2512}
2513
[email protected]40bd6582009-12-04 23:49:512514void RenderView::didCommitProvisionalLoad(WebFrame* frame,
2515 bool is_new_navigation) {
[email protected]3d9689372009-09-10 04:29:172516 NavigationState* navigation_state =
2517 NavigationState::FromDataSource(frame->dataSource());
2518
[email protected]9e84a872010-02-09 18:23:422519 if (!frame->parent()) { // Main frame case.
2520 // Let the page translator know that the page has changed so it can clear
2521 // its states.
2522 page_translator_->MainFrameNavigated();
2523 }
2524
[email protected]3d9689372009-09-10 04:29:172525 navigation_state->set_commit_load_time(Time::Now());
2526 if (is_new_navigation) {
2527 // When we perform a new navigation, we need to update the previous session
2528 // history entry with state for the page we are leaving.
2529 UpdateSessionHistory(frame);
2530
2531 // We bump our Page ID to correspond with the new session history entry.
2532 page_id_ = next_page_id_++;
2533
2534 MessageLoop::current()->PostDelayedTask(FROM_HERE,
2535 method_factory_.NewRunnableMethod(&RenderView::CapturePageInfo,
2536 page_id_, true),
2537 kDelayForForcedCaptureMs);
2538 } else {
2539 // Inspect the navigation_state on this frame to see if the navigation
2540 // corresponds to a session history navigation... Note: |frame| may or
2541 // may not be the toplevel frame, but for the case of capturing session
2542 // history, the first committed frame suffices. We keep track of whether
2543 // we've seen this commit before so that only capture session history once
2544 // per navigation.
2545 //
2546 // Note that we need to check if the page ID changed. In the case of a
2547 // reload, the page ID doesn't change, and UpdateSessionHistory gets the
2548 // previous URL and the current page ID, which would be wrong.
2549 if (navigation_state->pending_page_id() != -1 &&
2550 navigation_state->pending_page_id() != page_id_ &&
2551 !navigation_state->request_committed()) {
2552 // This is a successful session history navigation!
2553 UpdateSessionHistory(frame);
2554 page_id_ = navigation_state->pending_page_id();
2555 }
2556 }
2557
2558 // Remember that we've already processed this request, so we don't update
2559 // the session history again. We do this regardless of whether this is
2560 // a session history navigation, because if we attempted a session history
2561 // navigation without valid HistoryItem state, WebCore will think it is a
2562 // new navigation.
2563 navigation_state->set_request_committed(true);
2564
2565 UpdateURL(frame);
2566
2567 // If this committed load was initiated by a client redirect, we're
2568 // at the last stop now, so clear it.
2569 completed_client_redirect_src_ = GURL();
2570
2571 // Check whether we have new encoding name.
[email protected]26aa0482009-09-30 16:55:272572 UpdateEncoding(frame, frame->view()->pageEncoding().utf8());
[email protected]3d9689372009-09-10 04:29:172573}
2574
2575void RenderView::didClearWindowObject(WebFrame* frame) {
2576 if (BindingsPolicy::is_dom_automation_enabled(enabled_bindings_))
2577 BindDOMAutomationController(frame);
2578 if (BindingsPolicy::is_dom_ui_enabled(enabled_bindings_)) {
2579 dom_ui_bindings_.set_message_sender(this);
2580 dom_ui_bindings_.set_routing_id(routing_id_);
2581 dom_ui_bindings_.BindToJavascript(frame, L"chrome");
2582 }
2583 if (BindingsPolicy::is_external_host_enabled(enabled_bindings_)) {
2584 external_host_bindings_.set_message_sender(this);
2585 external_host_bindings_.set_routing_id(routing_id_);
2586 external_host_bindings_.BindToJavascript(frame, L"externalHost");
2587 }
2588}
2589
2590void RenderView::didCreateDocumentElement(WebFrame* frame) {
2591 if (RenderThread::current()) { // Will be NULL during unit tests.
2592 RenderThread::current()->user_script_slave()->InjectScripts(
2593 frame, UserScript::DOCUMENT_START);
2594 }
[email protected]078b34612009-09-19 19:31:512595 if (view_type_ == ViewType::EXTENSION_TOOLSTRIP ||
2596 view_type_ == ViewType::EXTENSION_MOLE) {
2597 InjectToolstripCSS();
2598 ExtensionProcessBindings::SetViewType(webview(), view_type_);
2599 }
[email protected]3d9689372009-09-10 04:29:172600
2601 // Notify the browser about non-blank documents loading in the top frame.
2602 GURL url = frame->url();
[email protected]e0d481582009-09-15 21:06:252603 if (url.is_valid() && url.spec() != chrome::kAboutBlankURL) {
[email protected]26aa0482009-09-30 16:55:272604 if (frame == webview()->mainFrame())
[email protected]3d9689372009-09-10 04:29:172605 Send(new ViewHostMsg_DocumentAvailableInMainFrame(routing_id_));
2606 }
2607}
2608
2609void RenderView::didReceiveTitle(WebFrame* frame, const WebString& title) {
2610 UpdateTitle(frame, title);
2611
2612 // Also check whether we have new encoding name.
[email protected]26aa0482009-09-30 16:55:272613 UpdateEncoding(frame, frame->view()->pageEncoding().utf8());
[email protected]3d9689372009-09-10 04:29:172614}
2615
2616void RenderView::didFinishDocumentLoad(WebFrame* frame) {
2617 WebDataSource* ds = frame->dataSource();
2618 NavigationState* navigation_state = NavigationState::FromDataSource(ds);
2619 DCHECK(navigation_state);
2620 navigation_state->set_finish_document_load_time(Time::Now());
2621
2622 Send(new ViewHostMsg_DocumentLoadedInFrame(routing_id_));
2623
[email protected]e9e07992010-02-17 21:04:362624 // The document has now been fully loaded. Scan for forms to be sent up to
2625 // the browser.
2626 // TODO(jhawkins): Make these use the FormManager.
[email protected]c83641732010-02-20 01:04:482627 form_manager_.ExtractForms(frame);
[email protected]e9e07992010-02-17 21:04:362628 SendForms(frame);
[email protected]3d9689372009-09-10 04:29:172629 SendPasswordForms(frame);
2630
2631 // Check whether we have new encoding name.
[email protected]26aa0482009-09-30 16:55:272632 UpdateEncoding(frame, frame->view()->pageEncoding().utf8());
[email protected]3d9689372009-09-10 04:29:172633
2634 if (RenderThread::current()) { // Will be NULL during unit tests.
2635 RenderThread::current()->user_script_slave()->InjectScripts(
2636 frame, UserScript::DOCUMENT_END);
2637 }
[email protected]fa7b6b542009-11-03 05:02:302638
2639 navigation_state->user_script_idle_scheduler()->DidFinishDocumentLoad();
[email protected]9e84a872010-02-09 18:23:422640
2641 if (page_translator_->IsPageTranslated())
2642 page_translator_->TranslateFrame(frame);
[email protected]fa7b6b542009-11-03 05:02:302643}
2644
2645void RenderView::OnUserScriptIdleTriggered(WebFrame* frame) {
2646 if (RenderThread::current()) { // Will be NULL during unit tests.
2647 RenderThread::current()->user_script_slave()->InjectScripts(
2648 frame, UserScript::DOCUMENT_IDLE);
2649 }
2650
2651 WebFrame* main_frame = webview()->mainFrame();
2652 if (frame == main_frame) {
2653 while (!pending_code_execution_queue_.empty()) {
[email protected]61f5a7b2009-12-22 22:21:202654 linked_ptr<ViewMsg_ExecuteCode_Params>& params =
[email protected]fa7b6b542009-11-03 05:02:302655 pending_code_execution_queue_.front();
[email protected]61f5a7b2009-12-22 22:21:202656 ExecuteCodeImpl(main_frame, *params);
[email protected]fa7b6b542009-11-03 05:02:302657 pending_code_execution_queue_.pop();
2658 }
2659 }
[email protected]3d9689372009-09-10 04:29:172660}
2661
2662void RenderView::didHandleOnloadEvents(WebFrame* frame) {
2663 // Ignore
2664}
2665
2666void RenderView::didFailLoad(WebFrame* frame, const WebURLError& error) {
2667 // Ignore
2668}
2669
2670void RenderView::didFinishLoad(WebFrame* frame) {
2671 WebDataSource* ds = frame->dataSource();
2672 NavigationState* navigation_state = NavigationState::FromDataSource(ds);
2673 DCHECK(navigation_state);
2674 navigation_state->set_finish_load_time(Time::Now());
[email protected]fa7b6b542009-11-03 05:02:302675 navigation_state->user_script_idle_scheduler()->DidFinishLoad();
[email protected]3d9689372009-09-10 04:29:172676}
2677
2678void RenderView::didChangeLocationWithinPage(
2679 WebFrame* frame, bool is_new_navigation) {
[email protected]f6c2459d2010-02-24 22:34:062680
2681 // Determine if the UserScriptIdleScheduler already ran scripts on this page,
2682 // since a new one gets created by didCreateDataSource.
2683 NavigationState* state =
2684 NavigationState::FromDataSource(frame->dataSource());
2685 bool idle_scheduler_ran = state->user_script_idle_scheduler()->has_run();
2686
[email protected]3d9689372009-09-10 04:29:172687 // If this was a reference fragment navigation that we initiated, then we
2688 // could end up having a non-null pending navigation state. We just need to
2689 // update the ExtraData on the datasource so that others who read the
2690 // ExtraData will get the new NavigationState. Similarly, if we did not
2691 // initiate this navigation, then we need to take care to reset any pre-
2692 // existing navigation state to a content-initiated navigation state.
2693 // DidCreateDataSource conveniently takes care of this for us.
2694 didCreateDataSource(frame, frame->dataSource());
2695
[email protected]f6c2459d2010-02-24 22:34:062696 if (idle_scheduler_ran) {
2697 // Update the new UserScriptIdleScheduler so we don't re-run scripts.
2698 NavigationState* new_state =
2699 NavigationState::FromDataSource(frame->dataSource());
2700 new_state->user_script_idle_scheduler()->set_has_run(true);
2701 }
2702
[email protected]3d9689372009-09-10 04:29:172703 didCommitProvisionalLoad(frame, is_new_navigation);
2704
[email protected]26aa0482009-09-30 16:55:272705 UpdateTitle(frame, frame->view()->mainFrame()->dataSource()->pageTitle());
[email protected]3d9689372009-09-10 04:29:172706}
2707
[email protected]476b6f82009-09-10 21:00:592708void RenderView::didUpdateCurrentHistoryItem(WebFrame* frame) {
[email protected]882daa92009-11-05 16:31:312709 StartNavStateSyncTimerIfNecessary();
[email protected]476b6f82009-09-10 21:00:592710}
2711
[email protected]3d9689372009-09-10 04:29:172712void RenderView::assignIdentifierToRequest(
2713 WebFrame* frame, unsigned identifier, const WebURLRequest& request) {
2714 // Ignore
2715}
2716
2717void RenderView::willSendRequest(
2718 WebFrame* frame, unsigned identifier, WebURLRequest& request,
2719 const WebURLResponse& redirect_response) {
[email protected]5e369672009-11-03 23:48:302720 WebFrame* top_frame = frame->top();
2721 if (!top_frame)
2722 top_frame = frame;
2723 WebDataSource* data_source = top_frame->provisionalDataSource();
2724 if (!data_source)
2725 data_source = top_frame->dataSource();
2726 if (data_source) {
2727 NavigationState* state = NavigationState::FromDataSource(data_source);
2728 if (state && state->is_cache_policy_override_set())
2729 request.setCachePolicy(state->cache_policy_override());
2730 }
[email protected]3d9689372009-09-10 04:29:172731 request.setRequestorID(routing_id_);
[email protected]7deade42010-03-05 09:33:132732 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kNoReferrers)) {
2733 request.clearHTTPHeaderField("Referer");
2734 }
[email protected]3d9689372009-09-10 04:29:172735}
2736
2737void RenderView::didReceiveResponse(
2738 WebFrame* frame, unsigned identifier, const WebURLResponse& response) {
[email protected]3d9689372009-09-10 04:29:172739 // Only do this for responses that correspond to a provisional data source
2740 // of the top-most frame. If we have a provisional data source, then we
2741 // can't have any sub-resources yet, so we know that this response must
2742 // correspond to a frame load.
2743 if (!frame->provisionalDataSource() || frame->parent())
2744 return;
2745
2746 // If we are in view source mode, then just let the user see the source of
2747 // the server's 404 error page.
2748 if (frame->isViewSourceModeEnabled())
2749 return;
2750
[email protected]f48013be2010-01-14 22:07:452751 // Record that this was a page loaded over SPDY.
2752 if (response.wasFetchedViaSPDY()) {
2753 NavigationState* navigation_state =
2754 NavigationState::FromDataSource(frame->provisionalDataSource());
2755 navigation_state->set_was_fetched_via_spdy(true);
2756 }
2757
2758 // Consider loading an alternate error page for 404 responses.
2759 if (response.httpStatusCode() != 404)
2760 return;
2761
[email protected]3d9689372009-09-10 04:29:172762 // Can we even load an alternate error page for this URL?
2763 if (!GetAlternateErrorPageURL(response.url(), HTTP_404).is_valid())
2764 return;
2765
2766 NavigationState* navigation_state =
2767 NavigationState::FromDataSource(frame->provisionalDataSource());
2768 navigation_state->set_postpone_loading_data(true);
2769 navigation_state->clear_postponed_data();
2770}
2771
2772void RenderView::didFinishResourceLoad(
2773 WebFrame* frame, unsigned identifier) {
2774 NavigationState* navigation_state =
2775 NavigationState::FromDataSource(frame->dataSource());
2776 if (!navigation_state->postpone_loading_data())
2777 return;
2778
2779 // The server returned a 404 and the content was < 512 bytes (which we
2780 // suppressed). Go ahead and fetch the alternate page content.
2781
2782 const GURL& frame_url = frame->url();
2783
2784 const GURL& error_page_url = GetAlternateErrorPageURL(frame_url, HTTP_404);
2785 DCHECK(error_page_url.is_valid());
2786
2787 WebURLError original_error;
2788 original_error.unreachableURL = frame_url;
2789
2790 navigation_state->set_alt_error_page_fetcher(
2791 new AltErrorPageResourceFetcher(
2792 error_page_url, frame, original_error,
2793 NewCallback(this, &RenderView::AltErrorPageFinished)));
2794}
2795
2796void RenderView::didFailResourceLoad(
2797 WebFrame* frame, unsigned identifier, const WebURLError& error) {
2798 // Ignore
2799}
2800
2801void RenderView::didLoadResourceFromMemoryCache(
2802 WebFrame* frame, const WebURLRequest& request,
2803 const WebURLResponse& response) {
2804 // Let the browser know we loaded a resource from the memory cache. This
2805 // message is needed to display the correct SSL indicators.
2806 Send(new ViewHostMsg_DidLoadResourceFromMemoryCache(
2807 routing_id_,
2808 request.url(),
[email protected]91733b62009-09-18 06:21:092809 frame->securityOrigin().toString().utf8(),
2810 frame->top()->securityOrigin().toString().utf8(),
[email protected]3d9689372009-09-10 04:29:172811 response.securityInfo()));
2812}
2813
[email protected]6069da8c2009-10-20 20:33:492814void RenderView::didDisplayInsecureContent(WebFrame* frame) {
[email protected]e3d60e5d2009-09-25 21:08:292815 Send(new ViewHostMsg_DidDisplayInsecureContent(routing_id_));
2816}
2817
2818void RenderView::didRunInsecureContent(
2819 WebFrame* frame, const WebSecurityOrigin& origin) {
2820 Send(new ViewHostMsg_DidRunInsecureContent(
2821 routing_id_,
2822 origin.toString().utf8()));
2823}
2824
[email protected]7ea093ba2009-11-03 05:54:592825bool RenderView::allowScript(WebFrame* frame, bool enabled_per_settings) {
[email protected]8934a3b2010-02-25 00:34:002826 if (enabled_per_settings)
2827 return AllowContentType(CONTENT_SETTINGS_TYPE_JAVASCRIPT);
[email protected]7ea093ba2009-11-03 05:54:592828
2829 WebSecurityOrigin origin = frame->securityOrigin();
2830 if (origin.isEmpty())
2831 return false; // Uninitialized document?
2832
2833 if (EqualsASCII(origin.protocol(), chrome::kChromeUIScheme))
2834 return true; // Browser UI elements should still work.
2835
2836 // If the scheme is ftp: or file:, an empty file name indicates a directory
2837 // listing, which requires JavaScript to function properly.
2838 GURL frame_url = frame->url();
2839 const char* kDirProtocols[] = { "ftp", "file" };
2840 for (size_t i = 0; i < arraysize(kDirProtocols); ++i) {
2841 if (EqualsASCII(origin.protocol(), kDirProtocols[i])) {
2842 return frame_url.SchemeIs(kDirProtocols[i]) &&
2843 frame_url.ExtractFileName().empty();
2844 }
2845 }
2846
2847 return false; // Other protocols fall through here.
2848}
2849
[email protected]8934a3b2010-02-25 00:34:002850void RenderView::didNotAllowScript(WebKit::WebFrame* frame) {
2851 DidBlockContentType(CONTENT_SETTINGS_TYPE_JAVASCRIPT);
2852}
2853
[email protected]c21f1d52010-03-04 03:19:432854void RenderView::didNotAllowPlugins(WebKit::WebFrame* frame) {
2855 DidBlockContentType(CONTENT_SETTINGS_TYPE_PLUGINS);
2856}
2857
[email protected]3d9689372009-09-10 04:29:172858void RenderView::didExhaustMemoryAvailableForScript(WebFrame* frame) {
2859 Send(new ViewHostMsg_JSOutOfMemory(routing_id_));
2860}
2861
[email protected]0c882b282009-10-07 17:01:282862void RenderView::didCreateScriptContext(WebFrame* frame) {
2863 EventBindings::HandleContextCreated(frame, false);
2864}
2865
2866void RenderView::didDestroyScriptContext(WebFrame* frame) {
2867 EventBindings::HandleContextDestroyed(frame);
2868}
2869
2870void RenderView::didCreateIsolatedScriptContext(WebFrame* frame) {
2871 EventBindings::HandleContextCreated(frame, true);
2872}
2873
[email protected]3d9689372009-09-10 04:29:172874void RenderView::didChangeContentsSize(WebFrame* frame, const WebSize& size) {
[email protected]d8a179c2010-01-31 00:58:142875 CheckPreferredSize();
2876}
2877
2878void RenderView::CheckPreferredSize() {
[email protected]3d9689372009-09-10 04:29:172879 // We don't always want to send the change messages over IPC, only if we've
[email protected]ab32b16c2009-10-16 14:57:252880 // be put in that mode by getting a |ViewMsg_EnablePreferredSizeChangedMode|
[email protected]3d9689372009-09-10 04:29:172881 // message.
[email protected]ab32b16c2009-10-16 14:57:252882 if (send_preferred_size_changes_) {
[email protected]3d9689372009-09-10 04:29:172883 // WebCore likes to tell us things have changed even when they haven't, so
[email protected]ab32b16c2009-10-16 14:57:252884 // cache the width and height and only send the IPC message when we're sure
2885 // they're different.
[email protected]26aa0482009-09-30 16:55:272886 int width = webview()->mainFrame()->contentsPreferredWidth();
[email protected]440a52a2009-11-18 07:23:392887 int height = webview()->mainFrame()->documentElementScrollHeight();
[email protected]c27324b2009-11-19 22:44:292888
[email protected]ab32b16c2009-10-16 14:57:252889 if (width != preferred_size_.width() ||
[email protected]440a52a2009-11-18 07:23:392890 height != preferred_size_.height()) {
[email protected]ab32b16c2009-10-16 14:57:252891 preferred_size_.set_width(width);
[email protected]440a52a2009-11-18 07:23:392892 preferred_size_.set_height(height);
[email protected]ab32b16c2009-10-16 14:57:252893
[email protected]ab32b16c2009-10-16 14:57:252894 Send(new ViewHostMsg_DidContentsPreferredSizeChange(routing_id_,
2895 preferred_size_));
[email protected]3d9689372009-09-10 04:29:172896 }
2897 }
2898}
2899
[email protected]143dcd592009-11-06 21:33:492900void RenderView::didChangeScrollOffset(WebFrame* frame) {
2901 StartNavStateSyncTimerIfNecessary();
2902}
2903
[email protected]8922e1f2009-10-03 05:01:262904void RenderView::reportFindInPageMatchCount(int request_id, int count,
2905 bool final_update) {
2906 // If we have a message that has been queued up, then we should just replace
2907 // it. The ACK from the browser will make sure it gets sent when the browser
2908 // wants it.
2909 if (queued_find_reply_message_.get()) {
2910 IPC::Message* msg = new ViewHostMsg_Find_Reply(
2911 routing_id_,
2912 request_id,
2913 count,
2914 gfx::Rect(),
2915 -1, // Don't update active match ordinal.
2916 final_update);
2917 queued_find_reply_message_.reset(msg);
2918 } else {
2919 // Send the search result over to the browser process.
2920 Send(new ViewHostMsg_Find_Reply(
2921 routing_id_,
2922 request_id,
2923 count,
2924 gfx::Rect(),
2925 -1, // // Don't update active match ordinal.
2926 final_update));
2927 }
2928}
2929
2930void RenderView::reportFindInPageSelection(int request_id,
2931 int active_match_ordinal,
2932 const WebRect& selection_rect) {
2933 // Send the search result over to the browser process.
2934 Send(new ViewHostMsg_Find_Reply(routing_id_,
2935 request_id,
2936 -1,
2937 selection_rect,
2938 active_match_ordinal,
2939 false));
2940}
2941
[email protected]79dbc662009-09-04 05:42:512942// webkit_glue::WebPluginPageDelegate -----------------------------------------
2943
[email protected]f103ab72009-09-02 17:10:592944webkit_glue::WebPluginDelegate* RenderView::CreatePluginDelegate(
2945 const GURL& url,
2946 const std::string& mime_type,
[email protected]f103ab72009-09-02 17:10:592947 std::string* actual_mime_type) {
2948 if (!PluginChannelHost::IsListening())
2949 return NULL;
2950
2951 GURL policy_url;
[email protected]26aa0482009-09-30 16:55:272952 WebFrame* main_frame = webview()->mainFrame();
[email protected]f103ab72009-09-02 17:10:592953 if (main_frame)
2954 policy_url = main_frame->url();
2955
2956 FilePath path;
[email protected]610c0892009-09-08 19:46:182957 render_thread_->Send(new ViewHostMsg_GetPluginPath(
2958 url, policy_url, mime_type, &path, actual_mime_type));
[email protected]f103ab72009-09-02 17:10:592959 if (path.value().empty())
2960 return NULL;
2961
2962 const std::string* mime_type_to_use;
2963 if (!actual_mime_type->empty())
2964 mime_type_to_use = actual_mime_type;
2965 else
2966 mime_type_to_use = &mime_type;
2967
[email protected]d2139662009-12-10 03:21:142968 bool use_pepper_host = false;
[email protected]00c39612010-03-06 02:53:282969 bool in_process_plugin = RenderProcess::current()->UseInProcessPlugins();
[email protected]d2139662009-12-10 03:21:142970 // Check for trusted Pepper plugins.
[email protected]26e8d5e2009-10-13 02:47:162971 const char kPepperPrefix[] = "pepper-";
2972 if (StartsWithASCII(*mime_type_to_use, kPepperPrefix, true)) {
[email protected]d2139662009-12-10 03:21:142973 if (CommandLine::ForCurrentProcess()->
2974 HasSwitch(switches::kInternalPepper)) {
2975 in_process_plugin = true;
2976 use_pepper_host = true;
2977 } else {
2978 // In process Pepper plugins must be explicitly enabled.
2979 return NULL;
2980 }
[email protected]26e8d5e2009-10-13 02:47:162981 }
[email protected]d2139662009-12-10 03:21:142982 // Check for Native Client modules.
[email protected]d032f492009-09-29 00:33:462983 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kInternalNaCl)) {
2984 if (mime_type == "application/x-nacl-srpc") {
2985 in_process_plugin = true;
[email protected]d2139662009-12-10 03:21:142986 use_pepper_host = true;
[email protected]d032f492009-09-29 00:33:462987 }
2988 }
2989 if (in_process_plugin) {
[email protected]d2139662009-12-10 03:21:142990 if (use_pepper_host) {
[email protected]00c39612010-03-06 02:53:282991 WebPluginDelegatePepper* pepper_plugin =
2992 WebPluginDelegatePepper::Create(path, *mime_type_to_use,
2993 AsWeakPtr());
2994 current_pepper_plugins_.insert(pepper_plugin);
2995 return pepper_plugin;
[email protected]d2139662009-12-10 03:21:142996 } else {
[email protected]6876dff2010-01-15 19:38:092997#if defined(OS_WIN) // In-proc plugins aren't supported on Linux or Mac.
[email protected]d2139662009-12-10 03:21:142998 return WebPluginDelegateImpl::Create(
2999 path, *mime_type_to_use, gfx::NativeViewFromId(host_window_));
[email protected]6876dff2010-01-15 19:38:093000#else
[email protected]596b2c42010-01-14 20:40:433001 NOTIMPLEMENTED();
3002 return NULL;
[email protected]7b6616f2010-01-14 18:07:553003#endif
[email protected]6876dff2010-01-15 19:38:093004 }
[email protected]f103ab72009-09-02 17:10:593005 }
3006
[email protected]610c0892009-09-08 19:46:183007 return new WebPluginDelegateProxy(*mime_type_to_use, AsWeakPtr());
[email protected]f103ab72009-09-02 17:10:593008}
3009
3010void RenderView::CreatedPluginWindow(gfx::PluginWindowHandle window) {
3011#if defined(OS_LINUX)
3012 RenderThread::current()->Send(new ViewHostMsg_CreatePluginContainer(
3013 routing_id(), window));
3014#endif
3015}
3016
3017void RenderView::WillDestroyPluginWindow(gfx::PluginWindowHandle window) {
3018#if defined(OS_LINUX)
3019 RenderThread::current()->Send(new ViewHostMsg_DestroyPluginContainer(
3020 routing_id(), window));
3021#endif
3022 CleanupWindowInPluginMoves(window);
3023}
3024
3025void RenderView::DidMovePlugin(const webkit_glue::WebPluginGeometry& move) {
3026 SchedulePluginMove(move);
3027}
3028
3029void RenderView::DidStartLoadingForPlugin() {
3030 // TODO(darin): Make is_loading_ be a counter!
[email protected]48c9cf2d2009-09-16 16:47:523031 didStartLoading();
[email protected]f103ab72009-09-02 17:10:593032}
3033
3034void RenderView::DidStopLoadingForPlugin() {
3035 // TODO(darin): Make is_loading_ be a counter!
[email protected]48c9cf2d2009-09-16 16:47:523036 didStopLoading();
[email protected]f103ab72009-09-02 17:10:593037}
3038
3039void RenderView::ShowModalHTMLDialogForPlugin(
3040 const GURL& url,
3041 const gfx::Size& size,
3042 const std::string& json_arguments,
3043 std::string* json_retval) {
[email protected]12636df2009-09-28 22:32:213044 SendAndRunNestedMessageLoop(new ViewHostMsg_ShowModalHTMLDialog(
[email protected]f103ab72009-09-02 17:10:593045 routing_id_, url, size.width(), size.height(), json_arguments,
[email protected]12636df2009-09-28 22:32:213046 json_retval));
[email protected]f103ab72009-09-02 17:10:593047}
3048
[email protected]b921cfd22010-02-25 16:57:513049WebCookieJar* RenderView::GetCookieJar() {
3050 return &cookie_jar_;
3051}
3052
3053void RenderView::PageTranslated(int page_id,
3054 const std::string& original_lang,
3055 const std::string& target_lang) {
3056 Send(new ViewHostMsg_PageTranslated(routing_id_, page_id_,
3057 original_lang, target_lang));
3058}
3059
initial.commit09911bf2008-07-26 23:55:293060void RenderView::SyncNavigationState() {
3061 if (!webview())
3062 return;
3063
[email protected]26aa0482009-09-30 16:55:273064 const WebHistoryItem& item = webview()->mainFrame()->currentHistoryItem();
[email protected]ca948a22009-06-25 19:36:173065 if (item.isNull())
initial.commit09911bf2008-07-26 23:55:293066 return;
[email protected]ca948a22009-06-25 19:36:173067
3068 Send(new ViewHostMsg_UpdateState(
3069 routing_id_, page_id_, webkit_glue::HistoryItemToString(item)));
initial.commit09911bf2008-07-26 23:55:293070}
3071
[email protected]b0950a72009-09-29 23:16:173072bool RenderView::DownloadImage(int id, const GURL& image_url, int image_size) {
3073 // Make sure webview was not shut down.
3074 if (!webview())
3075 return false;
3076 // Create an image resource fetcher and assign it with a call back object.
3077 image_fetchers_.insert(new ImageResourceFetcher(
[email protected]26aa0482009-09-30 16:55:273078 image_url, webview()->mainFrame(), id, image_size,
[email protected]b0950a72009-09-29 23:16:173079 NewCallback(this, &RenderView::DidDownloadImage)));
3080 return true;
3081}
3082
3083void RenderView::DidDownloadImage(ImageResourceFetcher* fetcher,
initial.commit09911bf2008-07-26 23:55:293084 const SkBitmap& image) {
[email protected]b0950a72009-09-29 23:16:173085 // Notify requester of image download status.
[email protected]51bd36612009-10-20 22:49:473086 Send(new ViewHostMsg_DidDownloadFavIcon(routing_id_,
3087 fetcher->id(),
3088 fetcher->image_url(),
3089 image.isNull(),
3090 image));
[email protected]b0950a72009-09-29 23:16:173091 // Dispose of the image fetcher.
3092 DCHECK(image_fetchers_.find(fetcher) != image_fetchers_.end());
3093 image_fetchers_.erase(fetcher);
3094 // We're in the callback from the ImageResourceFetcher, best to delay
3095 // deletion.
3096 MessageLoop::current()->DeleteSoon(FROM_HERE, fetcher);
initial.commit09911bf2008-07-26 23:55:293097}
3098
[email protected]bf5c2ff392009-07-08 16:24:333099void RenderView::OnDownloadFavIcon(int id,
3100 const GURL& image_url,
3101 int image_size) {
[email protected]f11ca0732009-04-11 00:09:343102 bool data_image_failed = false;
3103 if (image_url.SchemeIs("data")) {
3104 SkBitmap data_image = ImageFromDataUrl(image_url);
3105 data_image_failed = data_image.empty();
3106 if (!data_image_failed) {
[email protected]bf5c2ff392009-07-08 16:24:333107 Send(new ViewHostMsg_DidDownloadFavIcon(routing_id_, id, image_url, false,
3108 data_image));
[email protected]f11ca0732009-04-11 00:09:343109 }
3110 }
3111
[email protected]bf5c2ff392009-07-08 16:24:333112 if (data_image_failed ||
[email protected]b0950a72009-09-29 23:16:173113 !DownloadImage(id, image_url, image_size)) {
[email protected]bf5c2ff392009-07-08 16:24:333114 Send(new ViewHostMsg_DidDownloadFavIcon(routing_id_, id, image_url, true,
3115 SkBitmap()));
3116 }
initial.commit09911bf2008-07-26 23:55:293117}
3118
[email protected]f11ca0732009-04-11 00:09:343119SkBitmap RenderView::ImageFromDataUrl(const GURL& url) const {
3120 std::string mime_type, char_set, data;
3121 if (net::DataURL::Parse(url, &mime_type, &char_set, &data) && !data.empty()) {
3122 // Decode the favicon using WebKit's image decoder.
3123 webkit_glue::ImageDecoder decoder(gfx::Size(kFavIconSize, kFavIconSize));
3124 const unsigned char* src_data =
3125 reinterpret_cast<const unsigned char*>(&data[0]);
3126
3127 return decoder.Decode(src_data, data.size());
3128 }
3129 return SkBitmap();
3130}
3131
initial.commit09911bf2008-07-26 23:55:293132void RenderView::OnGetApplicationInfo(int page_id) {
3133 webkit_glue::WebApplicationInfo app_info;
3134 if (page_id == page_id_)
3135 webkit_glue::GetApplicationInfo(webview(), &app_info);
3136
3137 // Prune out any data URLs in the set of icons. The browser process expects
3138 // any icon with a data URL to have originated from a favicon. We don't want
3139 // to decode arbitrary data URLs in the browser process. See
3140 // http://b/issue?id=1162972
3141 for (size_t i = 0; i < app_info.icons.size(); ++i) {
[email protected]6de74452009-02-25 18:04:593142 if (app_info.icons[i].url.SchemeIs(chrome::kDataScheme)) {
initial.commit09911bf2008-07-26 23:55:293143 app_info.icons.erase(app_info.icons.begin() + i);
3144 --i;
3145 }
3146 }
3147
3148 Send(new ViewHostMsg_DidGetApplicationInfo(routing_id_, page_id, app_info));
3149}
3150
[email protected]7ccddb8c2009-08-04 17:36:553151GURL RenderView::GetAlternateErrorPageURL(const GURL& failed_url,
initial.commit09911bf2008-07-26 23:55:293152 ErrorPageType error_type) {
[email protected]7ccddb8c2009-08-04 17:36:553153 if (failed_url.SchemeIsSecure()) {
initial.commit09911bf2008-07-26 23:55:293154 // If the URL that failed was secure, then the embedding web page was not
3155 // expecting a network attacker to be able to manipulate its contents. As
3156 // we fetch alternate error pages over HTTP, we would be allowing a network
3157 // attacker to manipulate the contents of the response if we tried to use
3158 // the link doctor here.
[email protected]810a52ef2010-01-08 01:22:153159 return GURL();
initial.commit09911bf2008-07-26 23:55:293160 }
3161
3162 // Grab the base URL from the browser process.
3163 if (!alternate_error_page_url_.is_valid())
[email protected]810a52ef2010-01-08 01:22:153164 return GURL();
initial.commit09911bf2008-07-26 23:55:293165
3166 // Strip query params from the failed URL.
3167 GURL::Replacements remove_params;
3168 remove_params.ClearUsername();
3169 remove_params.ClearPassword();
3170 remove_params.ClearQuery();
3171 remove_params.ClearRef();
[email protected]7ccddb8c2009-08-04 17:36:553172 const GURL url_to_send = failed_url.ReplaceComponents(remove_params);
initial.commit09911bf2008-07-26 23:55:293173
3174 // Construct the query params to send to link doctor.
3175 std::string params(alternate_error_page_url_.query());
3176 params.append("&url=");
[email protected]0d2e6a62010-01-15 20:09:193177 params.append(EscapeQueryParamValue(url_to_send.spec(), true));
initial.commit09911bf2008-07-26 23:55:293178 params.append("&sourceid=chrome");
3179 params.append("&error=");
3180 switch (error_type) {
3181 case DNS_ERROR:
3182 params.append("dnserror");
3183 break;
3184
3185 case HTTP_404:
3186 params.append("http404");
3187 break;
3188
[email protected]5df266ac2008-10-15 19:50:133189 case CONNECTION_ERROR:
[email protected]e1f934b2009-01-26 20:41:333190 params.append("connectionfailure");
[email protected]5df266ac2008-10-15 19:50:133191 break;
3192
initial.commit09911bf2008-07-26 23:55:293193 default:
3194 NOTREACHED() << "unknown ErrorPageType";
3195 }
3196
3197 // OK, build the final url to return.
3198 GURL::Replacements link_doctor_params;
3199 link_doctor_params.SetQueryStr(params);
3200 GURL url = alternate_error_page_url_.ReplaceComponents(link_doctor_params);
3201 return url;
3202}
3203
[email protected]6069da8c2009-10-20 20:33:493204void RenderView::OnFind(int request_id, const string16& search_text,
3205 const WebFindOptions& options) {
[email protected]26aa0482009-09-30 16:55:273206 WebFrame* main_frame = webview()->mainFrame();
[email protected]b4bb2502009-10-01 22:35:273207 WebFrame* frame_after_main = main_frame->traverseNext(true);
[email protected]26aa0482009-09-30 16:55:273208 WebFrame* focused_frame = webview()->focusedFrame();
initial.commit09911bf2008-07-26 23:55:293209 WebFrame* search_frame = focused_frame; // start searching focused frame.
3210
3211 bool multi_frame = (frame_after_main != main_frame);
3212
3213 // If we have multiple frames, we don't want to wrap the search within the
3214 // frame, so we check here if we only have main_frame in the chain.
3215 bool wrap_within_frame = !multi_frame;
3216
[email protected]b3f2b912009-04-09 16:18:523217 WebRect selection_rect;
initial.commit09911bf2008-07-26 23:55:293218 bool result = false;
3219
[email protected]7830da3e2009-11-06 16:27:263220 // If something is selected when we start searching it means we cannot just
3221 // increment the current match ordinal; we need to re-generate it.
3222 WebRange current_selection = focused_frame->selectionRange();
3223
initial.commit09911bf2008-07-26 23:55:293224 do {
[email protected]dd7daa82009-08-10 05:46:453225 result = search_frame->find(
[email protected]7ea066a2009-04-06 20:21:593226 request_id, search_text, options, wrap_within_frame, &selection_rect);
initial.commit09911bf2008-07-26 23:55:293227
3228 if (!result) {
3229 // don't leave text selected as you move to the next frame.
[email protected]a100d76bb2009-08-14 17:50:223230 search_frame->executeCommand(WebString::fromUTF8("Unselect"));
initial.commit09911bf2008-07-26 23:55:293231
3232 // Find the next frame, but skip the invisible ones.
3233 do {
3234 // What is the next frame to search? (we might be going backwards). Note
3235 // that we specify wrap=true so that search_frame never becomes NULL.
[email protected]7ea066a2009-04-06 20:21:593236 search_frame = options.forward ?
[email protected]b4bb2502009-10-01 22:35:273237 search_frame->traverseNext(true) :
3238 search_frame->traversePrevious(true);
[email protected]dd7daa82009-08-10 05:46:453239 } while (!search_frame->hasVisibleContent() &&
3240 search_frame != focused_frame);
initial.commit09911bf2008-07-26 23:55:293241
[email protected]884db412008-11-24 23:46:503242 // Make sure selection doesn't affect the search operation in new frame.
[email protected]a100d76bb2009-08-14 17:50:223243 search_frame->executeCommand(WebString::fromUTF8("Unselect"));
initial.commit09911bf2008-07-26 23:55:293244
3245 // If we have multiple frames and we have wrapped back around to the
3246 // focused frame, we need to search it once more allowing wrap within
3247 // the frame, otherwise it will report 'no match' if the focused frame has
3248 // reported matches, but no frames after the focused_frame contain a
3249 // match for the search word(s).
3250 if (multi_frame && search_frame == focused_frame) {
[email protected]dd7daa82009-08-10 05:46:453251 result = search_frame->find(
[email protected]7ea066a2009-04-06 20:21:593252 request_id, search_text, options, true, // Force wrapping.
3253 &selection_rect);
initial.commit09911bf2008-07-26 23:55:293254 }
3255 }
3256
[email protected]26aa0482009-09-30 16:55:273257 webview()->setFocusedFrame(search_frame);
initial.commit09911bf2008-07-26 23:55:293258 } while (!result && search_frame != focused_frame);
3259
[email protected]7830da3e2009-11-06 16:27:263260 if (options.findNext && current_selection.isNull()) {
[email protected]4f3dc372009-02-24 00:10:293261 // Force the main_frame to report the actual count.
[email protected]dd7daa82009-08-10 05:46:453262 main_frame->increaseMatchCount(0, request_id);
[email protected]4f3dc372009-02-24 00:10:293263 } else {
3264 // If nothing is found, set result to "0 of 0", otherwise, set it to
3265 // "-1 of 1" to indicate that we found at least one item, but we don't know
3266 // yet what is active.
3267 int ordinal = result ? -1 : 0; // -1 here means, we might know more later.
3268 int match_count = result ? 1 : 0; // 1 here means possibly more coming.
initial.commit09911bf2008-07-26 23:55:293269
[email protected]4f3dc372009-02-24 00:10:293270 // If we find no matches then this will be our last status update.
3271 // Otherwise the scoping effort will send more results.
3272 bool final_status_update = !result;
initial.commit09911bf2008-07-26 23:55:293273
[email protected]4f3dc372009-02-24 00:10:293274 // Send the search result over to the browser process.
[email protected]4f999132009-03-31 18:08:403275 Send(new ViewHostMsg_Find_Reply(routing_id_,
[email protected]7ea066a2009-04-06 20:21:593276 request_id,
[email protected]4f3dc372009-02-24 00:10:293277 match_count,
3278 selection_rect,
3279 ordinal,
3280 final_status_update));
initial.commit09911bf2008-07-26 23:55:293281
initial.commit09911bf2008-07-26 23:55:293282 // Scoping effort begins, starting with the mainframe.
3283 search_frame = main_frame;
3284
[email protected]dd7daa82009-08-10 05:46:453285 main_frame->resetMatchCount();
initial.commit09911bf2008-07-26 23:55:293286
3287 do {
3288 // Cancel all old scoping requests before starting a new one.
[email protected]dd7daa82009-08-10 05:46:453289 search_frame->cancelPendingScopingEffort();
initial.commit09911bf2008-07-26 23:55:293290
3291 // We don't start another scoping effort unless at least one match has
3292 // been found.
3293 if (result) {
3294 // Start new scoping request. If the scoping function determines that it
3295 // needs to scope, it will defer until later.
[email protected]dd7daa82009-08-10 05:46:453296 search_frame->scopeStringMatches(request_id,
[email protected]7ea066a2009-04-06 20:21:593297 search_text,
3298 options,
initial.commit09911bf2008-07-26 23:55:293299 true); // reset the tickmarks
3300 }
3301
3302 // Iterate to the next frame. The frame will not necessarily scope, for
3303 // example if it is not visible.
[email protected]b4bb2502009-10-01 22:35:273304 search_frame = search_frame->traverseNext(true);
initial.commit09911bf2008-07-26 23:55:293305 } while (search_frame != main_frame);
3306 }
3307}
3308
[email protected]8c4cdd42010-01-12 21:31:133309// static
3310std::string RenderView::DetermineTextLanguage(const std::wstring& text) {
[email protected]70082aab2010-02-24 01:44:403311 // Text with less than 100 bytes will probably not provide good results.
3312 // Report it as unknown language.
3313 if (text.length() < 100)
3314 return kUnknownLanguageCode;
3315
[email protected]8c4cdd42010-01-12 21:31:133316 std::string language = kUnknownLanguageCode;
[email protected]8c4cdd42010-01-12 21:31:133317 int num_languages = 0;
3318 bool is_reliable = false;
[email protected]8dc5a2052010-01-19 21:32:423319 string16 input = WideToUTF16(text);
[email protected]8c4cdd42010-01-12 21:31:133320 Language cld_language =
[email protected]8dc5a2052010-01-19 21:32:423321 DetectLanguageOfUnicodeText(NULL, input.c_str(), true, &is_reliable,
[email protected]8c4cdd42010-01-12 21:31:133322 &num_languages, NULL);
[email protected]70082aab2010-02-24 01:44:403323 if (is_reliable && cld_language != NUM_LANGUAGES &&
3324 cld_language != UNKNOWN_LANGUAGE && cld_language != TG_UNKNOWN_LANGUAGE) {
[email protected]a7ccc4d2010-01-27 08:14:483325 // We should not use LanguageCode_ISO_639_1 because it does not cover all
3326 // the languages CLD can detect. As a result, it'll return the invalid
[email protected]8d022a92010-02-04 02:49:263327 // language code for tradtional Chinese among others.
3328 // |LanguageCodeWithDialect| will go through ISO 639-1, ISO-639-2 and
3329 // 'other' tables to do the 'right' thing. In addition, it'll return zh-CN
3330 // for Simplified Chinese.
3331 language = LanguageCodeWithDialects(cld_language);
[email protected]8c4cdd42010-01-12 21:31:133332 }
[email protected]8c4cdd42010-01-12 21:31:133333 return language;
[email protected]7893a982010-01-07 23:25:523334}
3335
[email protected]8934a3b2010-02-25 00:34:003336bool RenderView::AllowContentType(ContentSettingsType settings_type) {
[email protected]0de80162010-02-03 04:52:353337 // CONTENT_SETTING_ASK is only valid for cookies.
[email protected]8934a3b2010-02-25 00:34:003338 return current_content_settings_.settings[settings_type] !=
3339 CONTENT_SETTING_BLOCK;
3340}
3341
3342void RenderView::DidBlockContentType(ContentSettingsType settings_type) {
3343 if (!content_blocked_[settings_type]) {
3344 content_blocked_[settings_type] = true;
3345 Send(new ViewHostMsg_ContentBlocked(routing_id_, settings_type));
[email protected]0de80162010-02-03 04:52:353346 }
[email protected]0de80162010-02-03 04:52:353347}
3348
[email protected]71b0d5d2010-02-15 05:43:073349void RenderView::ClearBlockedContentSettings() {
3350 for (size_t i = 0; i < arraysize(content_blocked_); ++i)
3351 content_blocked_[i] = false;
3352}
3353
initial.commit09911bf2008-07-26 23:55:293354void RenderView::DnsPrefetch(const std::vector<std::string>& host_names) {
3355 Send(new ViewHostMsg_DnsPrefetch(host_names));
3356}
3357
[email protected]40bd6582009-12-04 23:49:513358void RenderView::OnZoom(PageZoom::Function function) {
3359 if (!webview()) // Not sure if this can happen, but no harm in being safe.
3360 return;
3361
3362 int zoom_level = webview()->zoomLevel();
3363 int new_zoom_level = webview()->setZoomLevel(false,
3364 (function == PageZoom::RESET) ? 0 : (zoom_level + function));
3365
3366 // Tell the browser which host got zoomed so it can update the saved values.
3367 // Pages like the safe browsing interstitial can have empty hosts; don't
3368 // record those.
3369 std::string host(GURL(webview()->mainFrame()->url()).host());
3370 if (!host.empty())
3371 Send(new ViewHostMsg_DidZoomHost(host, new_zoom_level));
3372}
3373
[email protected]f85f0702010-01-30 09:31:013374void RenderView::OnSetContentSettingsForLoadingHost(
3375 std::string host,
3376 const ContentSettings& content_settings) {
3377 host_content_settings_[host] = content_settings;
3378}
3379
[email protected]40bd6582009-12-04 23:49:513380void RenderView::OnSetZoomLevelForLoadingHost(std::string host,
3381 int zoom_level) {
3382 host_zoom_levels_[host] = zoom_level;
initial.commit09911bf2008-07-26 23:55:293383}
3384
[email protected]41fc0322009-09-04 22:23:403385void RenderView::OnSetPageEncoding(const std::string& encoding_name) {
[email protected]26aa0482009-09-30 16:55:273386 webview()->setPageEncoding(WebString::fromUTF8(encoding_name));
initial.commit09911bf2008-07-26 23:55:293387}
3388
[email protected]a697f4c2009-09-14 22:30:183389void RenderView::OnResetPageEncodingToDefault() {
[email protected]26aa0482009-09-30 16:55:273390 WebString no_encoding;
3391 webview()->setPageEncoding(no_encoding);
[email protected]a697f4c2009-09-14 22:30:183392}
3393
[email protected]20ad2692009-11-20 18:27:203394bool RenderView::GetAllChildFrames(
3395 WebFrame* parent_frame,
3396 std::vector<WebFrame*>* frames_vector) const {
3397 if (!parent_frame)
3398 return false;
3399 for (WebFrame* child_frame = parent_frame->firstChild(); child_frame;
3400 child_frame = child_frame->nextSibling()) {
3401 frames_vector->push_back(child_frame);
3402 GetAllChildFrames(child_frame, frames_vector);
3403 }
3404 return true;
3405}
3406
[email protected]dd7daa82009-08-10 05:46:453407WebFrame* RenderView::GetChildFrame(const std::wstring& xpath) const {
3408 if (xpath.empty())
[email protected]26aa0482009-09-30 16:55:273409 return webview()->mainFrame();
[email protected]dd7daa82009-08-10 05:46:453410
3411 // xpath string can represent a frame deep down the tree (across multiple
3412 // frame DOMs).
3413 // Example, /html/body/table/tbody/tr/td/iframe\n/frameset/frame[0]
3414 // should break into 2 xpaths
3415 // /html/body/table/tbody/tr/td/iframe & /frameset/frame[0]
3416
[email protected]26aa0482009-09-30 16:55:273417 WebFrame* frame = webview()->mainFrame();
[email protected]dd7daa82009-08-10 05:46:453418
3419 std::wstring xpath_remaining = xpath;
3420 while (!xpath_remaining.empty()) {
3421 std::wstring::size_type delim_pos = xpath_remaining.find_first_of(L'\n');
3422 std::wstring xpath_child;
3423 if (delim_pos != std::wstring::npos) {
3424 xpath_child = xpath_remaining.substr(0, delim_pos);
3425 xpath_remaining.erase(0, delim_pos + 1);
3426 } else {
3427 xpath_remaining.swap(xpath_child);
3428 }
3429 frame = frame->findChildByExpression(WideToUTF16Hack(xpath_child));
initial.commit09911bf2008-07-26 23:55:293430 }
3431
[email protected]dd7daa82009-08-10 05:46:453432 return frame;
initial.commit09911bf2008-07-26 23:55:293433}
3434
[email protected]f29acf52008-11-03 20:08:333435void RenderView::EvaluateScript(const std::wstring& frame_xpath,
3436 const std::wstring& script) {
initial.commit09911bf2008-07-26 23:55:293437 WebFrame* web_frame = GetChildFrame(frame_xpath);
3438 if (!web_frame)
3439 return;
3440
[email protected]dd7daa82009-08-10 05:46:453441 web_frame->executeScript(WebScriptSource(WideToUTF16Hack(script)));
initial.commit09911bf2008-07-26 23:55:293442}
3443
[email protected]1810e132009-03-24 23:35:483444void RenderView::InsertCSS(const std::wstring& frame_xpath,
[email protected]ffaef0c2009-09-15 17:08:083445 const std::string& css,
3446 const std::string& id) {
[email protected]1810e132009-03-24 23:35:483447 WebFrame* web_frame = GetChildFrame(frame_xpath);
3448 if (!web_frame)
3449 return;
3450
[email protected]ffaef0c2009-09-15 17:08:083451 web_frame->insertStyleText(WebString::fromUTF8(css), WebString::fromUTF8(id));
[email protected]1810e132009-03-24 23:35:483452}
3453
[email protected]00c39612010-03-06 02:53:283454void RenderView::OnPepperPluginDestroy(
3455 WebPluginDelegatePepper* pepper_plugin) {
3456 std::set<WebPluginDelegatePepper*>::iterator found_pepper =
3457 current_pepper_plugins_.find(pepper_plugin);
3458 if (found_pepper == current_pepper_plugins_.end()) {
3459 NOTREACHED();
3460 return;
3461 }
3462 current_pepper_plugins_.erase(found_pepper);
3463}
3464
initial.commit09911bf2008-07-26 23:55:293465void RenderView::OnScriptEvalRequest(const std::wstring& frame_xpath,
3466 const std::wstring& jscript) {
[email protected]f29acf52008-11-03 20:08:333467 EvaluateScript(frame_xpath, jscript);
initial.commit09911bf2008-07-26 23:55:293468}
3469
[email protected]1810e132009-03-24 23:35:483470void RenderView::OnCSSInsertRequest(const std::wstring& frame_xpath,
[email protected]ffaef0c2009-09-15 17:08:083471 const std::string& css,
3472 const std::string& id) {
3473 InsertCSS(frame_xpath, css, id);
[email protected]ae461542009-06-19 19:03:413474
3475 // Notify RenderViewHost that css has been inserted into the frame.
3476 Send(new ViewHostMsg_OnCSSInserted(routing_id_));
[email protected]1810e132009-03-24 23:35:483477}
3478
[email protected]7ea066a2009-04-06 20:21:593479void RenderView::OnAddMessageToConsole(
3480 const string16& frame_xpath,
3481 const string16& message,
3482 const WebConsoleMessage::Level& level) {
3483 WebFrame* web_frame = GetChildFrame(UTF16ToWideHack(frame_xpath));
[email protected]0dea3ea2009-03-31 23:30:593484 if (web_frame)
[email protected]dd7daa82009-08-10 05:46:453485 web_frame->addMessageToConsole(WebConsoleMessage(level, message));
initial.commit09911bf2008-07-26 23:55:293486}
3487
[email protected]81e63782009-02-27 19:35:093488void RenderView::OnAllowBindings(int enabled_bindings_flags) {
3489 enabled_bindings_ |= enabled_bindings_flags;
initial.commit09911bf2008-07-26 23:55:293490}
3491
3492void RenderView::OnSetDOMUIProperty(const std::string& name,
3493 const std::string& value) {
[email protected]81e63782009-02-27 19:35:093494 DCHECK(BindingsPolicy::is_dom_ui_enabled(enabled_bindings_));
initial.commit09911bf2008-07-26 23:55:293495 dom_ui_bindings_.SetProperty(name, value);
3496}
3497
3498void RenderView::OnReservePageIDRange(int size_of_range) {
3499 next_page_id_ += size_of_range + 1;
3500}
3501
[email protected]e80c73b2009-04-07 23:24:583502void RenderView::OnDragSourceEndedOrMoved(const gfx::Point& client_point,
3503 const gfx::Point& screen_point,
[email protected]1d9f4132009-09-08 17:29:253504 bool ended,
3505 WebDragOperation op) {
[email protected]5f9ae6c2009-07-08 02:38:033506 if (ended) {
[email protected]26aa0482009-09-30 16:55:273507 webview()->dragSourceEndedAt(client_point, screen_point, op);
[email protected]5f9ae6c2009-07-08 02:38:033508 }
initial.commit09911bf2008-07-26 23:55:293509}
3510
3511void RenderView::OnDragSourceSystemDragEnded() {
[email protected]26aa0482009-09-30 16:55:273512 webview()->dragSourceSystemDragEnded();
initial.commit09911bf2008-07-26 23:55:293513}
3514
initial.commit09911bf2008-07-26 23:55:293515void RenderView::OnFillPasswordForm(
[email protected]daa8c58e2009-06-15 17:21:103516 const webkit_glue::PasswordFormDomManager::FillData& form_data) {
initial.commit09911bf2008-07-26 23:55:293517 webkit_glue::FillPasswordForm(this->webview(), form_data);
3518}
3519
3520void RenderView::OnDragTargetDragEnter(const WebDropData& drop_data,
[email protected]e80c73b2009-04-07 23:24:583521 const gfx::Point& client_point,
[email protected]1d9f4132009-09-08 17:29:253522 const gfx::Point& screen_point,
3523 WebDragOperationsMask ops) {
[email protected]26aa0482009-09-30 16:55:273524 WebDragOperation operation = webview()->dragTargetDragEnter(
[email protected]e80c73b2009-04-07 23:24:583525 drop_data.ToDragData(),
3526 drop_data.identity,
3527 client_point,
[email protected]1d9f4132009-09-08 17:29:253528 screen_point,
3529 ops);
initial.commit09911bf2008-07-26 23:55:293530
[email protected]1d9f4132009-09-08 17:29:253531 Send(new ViewHostMsg_UpdateDragCursor(routing_id_, operation));
initial.commit09911bf2008-07-26 23:55:293532}
3533
[email protected]e80c73b2009-04-07 23:24:583534void RenderView::OnDragTargetDragOver(const gfx::Point& client_point,
[email protected]1d9f4132009-09-08 17:29:253535 const gfx::Point& screen_point,
3536 WebDragOperationsMask ops) {
[email protected]26aa0482009-09-30 16:55:273537 WebDragOperation operation = webview()->dragTargetDragOver(
[email protected]1d9f4132009-09-08 17:29:253538 client_point,
3539 screen_point,
3540 ops);
initial.commit09911bf2008-07-26 23:55:293541
[email protected]1d9f4132009-09-08 17:29:253542 Send(new ViewHostMsg_UpdateDragCursor(routing_id_, operation));
initial.commit09911bf2008-07-26 23:55:293543}
3544
3545void RenderView::OnDragTargetDragLeave() {
[email protected]26aa0482009-09-30 16:55:273546 webview()->dragTargetDragLeave();
initial.commit09911bf2008-07-26 23:55:293547}
3548
[email protected]e80c73b2009-04-07 23:24:583549void RenderView::OnDragTargetDrop(const gfx::Point& client_point,
3550 const gfx::Point& screen_point) {
[email protected]26aa0482009-09-30 16:55:273551 webview()->dragTargetDrop(client_point, screen_point);
initial.commit09911bf2008-07-26 23:55:293552}
3553
3554void RenderView::OnUpdateWebPreferences(const WebPreferences& prefs) {
[email protected]2fab253a2009-08-17 23:00:593555 webkit_preferences_ = prefs;
3556 webkit_preferences_.Apply(webview());
initial.commit09911bf2008-07-26 23:55:293557}
3558
3559void RenderView::OnSetAltErrorPageURL(const GURL& url) {
3560 alternate_error_page_url_ = url;
3561}
3562
[email protected]a0c7153e2009-12-09 14:36:333563void RenderView::OnCustomContextMenuAction(unsigned action) {
3564 webview()->performCustomContextMenuAction(action);
3565}
3566
[email protected]d4a00a72010-01-29 01:44:423567void RenderView::OnTranslatePage(int page_id,
3568 const std::string& source_lang,
3569 const std::string& target_lang) {
3570 if (page_id != page_id_)
3571 return; // Not the page we expected, nothing to do.
3572
3573 WebFrame* main_frame = webview()->mainFrame();
3574 if (!main_frame)
3575 return;
[email protected]9e84a872010-02-09 18:23:423576
3577 page_translator_->TranslatePage(page_id, main_frame,
3578 source_lang, target_lang);
[email protected]d4a00a72010-01-29 01:44:423579}
3580
[email protected]0bedb8a2010-01-14 19:36:323581void RenderView::OnTranslateTextResponse(
3582 int work_id, int error_id, const std::vector<string16>& text_chunks) {
[email protected]d4a00a72010-01-29 01:44:423583 text_translator_.OnTranslationResponse(work_id, error_id, text_chunks);
[email protected]0bedb8a2010-01-14 19:36:323584}
3585
initial.commit09911bf2008-07-26 23:55:293586void RenderView::OnInstallMissingPlugin() {
3587 // This could happen when the first default plugin is deleted.
[email protected]f103ab72009-09-02 17:10:593588 if (first_default_plugin_)
3589 first_default_plugin_->InstallMissingPlugin();
initial.commit09911bf2008-07-26 23:55:293590}
3591
[email protected]b62d1a8c2009-01-13 23:54:573592void RenderView::OnFileChooserResponse(
[email protected]561abe62009-04-06 18:08:343593 const std::vector<FilePath>& file_names) {
[email protected]8029f5672009-03-20 22:33:363594 // This could happen if we navigated to a different page before the user
3595 // closed the chooser.
[email protected]a1128322009-10-06 18:38:463596 if (!file_chooser_completion_)
[email protected]8029f5672009-03-20 22:33:363597 return;
3598
[email protected]6069da8c2009-10-20 20:33:493599 WebVector<WebString> ws_file_names(file_names.size());
[email protected]a1128322009-10-06 18:38:463600 for (size_t i = 0; i < file_names.size(); ++i) {
3601 ws_file_names[i] = webkit_glue::FilePathToWebString(file_names[i]);
3602 }
3603
3604 file_chooser_completion_->didChooseFile(ws_file_names);
3605 // Reset the chooser pointer
3606 file_chooser_completion_ = NULL;
initial.commit09911bf2008-07-26 23:55:293607}
3608
3609void RenderView::OnEnableViewSourceMode() {
3610 if (!webview())
3611 return;
[email protected]26aa0482009-09-30 16:55:273612 WebFrame* main_frame = webview()->mainFrame();
initial.commit09911bf2008-07-26 23:55:293613 if (!main_frame)
3614 return;
3615
[email protected]dd7daa82009-08-10 05:46:453616 main_frame->enableViewSourceMode(true);
initial.commit09911bf2008-07-26 23:55:293617}
3618
[email protected]ab32b16c2009-10-16 14:57:253619void RenderView::OnEnablePreferredSizeChangedMode() {
3620 send_preferred_size_changes_ = true;
[email protected]e8014aa52010-03-03 14:30:063621
3622 if (ViewType::ShouldAutoResize(view_type_))
[email protected]d8a179c2010-01-31 00:58:143623 preferred_size_change_timer_.Start(TimeDelta::FromMilliseconds(10), this,
3624 &RenderView::CheckPreferredSize);
[email protected]0666aef2009-05-13 19:48:083625}
3626
[email protected]cda45c02010-02-25 19:28:103627void RenderView::OnDisableScrollbarsForSmallWindows(
3628 const gfx::Size& disable_scrollbar_size_limit) {
3629 disable_scrollbars_size_limit_ = disable_scrollbar_size_limit;
3630}
3631
[email protected]80d96fa2009-06-10 22:34:513632void RenderView::OnSetRendererPrefs(const RendererPreferences& renderer_prefs) {
3633 renderer_preferences_ = renderer_prefs;
[email protected]6e282c92009-07-24 01:19:373634 UpdateFontRenderingFromRendererPrefs();
[email protected]033970a2009-10-14 16:45:053635#if defined(OS_LINUX) && !defined(TOOLKIT_VIEWS)
[email protected]1c83eb42009-09-11 21:08:413636 WebColorName name = WebKit::WebColorWebkitFocusRingColor;
3637 WebKit::setNamedColors(&name, &renderer_prefs.focus_ring_color, 1);
[email protected]39cd64ed2010-02-05 02:18:463638 WebKit::setCaretBlinkInterval(renderer_prefs.caret_blink_interval);
[email protected]93623c5d2009-12-10 21:40:323639
[email protected]644d77e2010-01-27 01:03:103640 if (webview()) {
[email protected]93623c5d2009-12-10 21:40:323641 webview()->setScrollbarColors(
3642 renderer_prefs.thumb_inactive_color,
3643 renderer_prefs.thumb_active_color,
3644 renderer_prefs.track_color);
[email protected]644d77e2010-01-27 01:03:103645 webview()->setSelectionColors(
3646 renderer_prefs.active_selection_bg_color,
3647 renderer_prefs.active_selection_fg_color,
3648 renderer_prefs.inactive_selection_bg_color,
3649 renderer_prefs.inactive_selection_fg_color);
3650 }
[email protected]7a74e102009-09-03 00:16:563651#endif
[email protected]80d96fa2009-06-10 22:34:513652}
3653
[email protected]952cb702009-10-07 05:50:283654void RenderView::OnMediaPlayerActionAt(const gfx::Point& location,
3655 const WebMediaPlayerAction& action) {
3656 if (webview())
3657 webview()->performMediaPlayerAction(action, location);
[email protected]581b87eb2009-07-23 23:06:563658}
3659
[email protected]7b291f92009-08-14 05:43:533660void RenderView::OnNotifyRendererViewType(ViewType::Type type) {
[email protected]078b34612009-09-19 19:31:513661 // When this is first set, the bindings aren't fully loaded. We only need
3662 // to call through this API after the page has already been loaded. It's
3663 // also called in didCreateDocumentElement to bootstrap.
3664 if (view_type_ != ViewType::INVALID) {
3665 if (type == ViewType::EXTENSION_MOLE ||
3666 type == ViewType::EXTENSION_TOOLSTRIP) {
3667 ExtensionProcessBindings::SetViewType(webview(), type);
3668 }
3669 }
[email protected]7b291f92009-08-14 05:43:533670 view_type_ = type;
3671}
3672
3673void RenderView::OnUpdateBrowserWindowId(int window_id) {
3674 browser_window_id_ = window_id;
3675}
3676
initial.commit09911bf2008-07-26 23:55:293677void RenderView::OnUpdateBackForwardListCount(int back_list_count,
3678 int forward_list_count) {
3679 history_back_list_count_ = back_list_count;
3680 history_forward_list_count_ = forward_list_count;
3681}
3682
[email protected]266eb6f2008-09-30 23:56:503683void RenderView::OnGetAccessibilityInfo(
[email protected]6a983b42009-03-20 20:12:253684 const webkit_glue::WebAccessibility::InParams& in_params,
3685 webkit_glue::WebAccessibility::OutParams* out_params) {
[email protected]6c8afae52009-01-22 02:24:573686#if defined(OS_WIN)
[email protected]c7287a92009-11-04 20:06:153687 if (!accessibility_.get()) {
3688 // TODO(dglazkov): Once implemented for all ports, remove lazy
3689 // instantiation of accessibility_.
3690 accessibility_.reset(WebAccessibilityCache::create());
3691 accessibility_->initialize(webview());
[email protected]6a983b42009-03-20 20:12:253692 }
[email protected]266eb6f2008-09-30 23:56:503693
[email protected]17455962010-02-24 01:39:353694 out_params->return_code =
3695 webkit_glue::WebAccessibility::GetAccObjInfo(accessibility_.get(),
3696 in_params,
3697 out_params);
[email protected]c7287a92009-11-04 20:06:153698
[email protected]6c8afae52009-01-22 02:24:573699#else // defined(OS_WIN)
3700 // TODO(port): accessibility not yet implemented
3701 NOTIMPLEMENTED();
3702#endif
[email protected]266eb6f2008-09-30 23:56:503703}
3704
[email protected]6a983b42009-03-20 20:12:253705void RenderView::OnClearAccessibilityInfo(int acc_obj_id, bool clear_all) {
[email protected]6c8afae52009-01-22 02:24:573706#if defined(OS_WIN)
[email protected]c7287a92009-11-04 20:06:153707 if (!accessibility_.get()) {
[email protected]266eb6f2008-09-30 23:56:503708 // If accessibility is not activated, ignore clearing message.
3709 return;
3710 }
[email protected]e846d0d2009-05-20 00:53:063711
[email protected]c7287a92009-11-04 20:06:153712 if (clear_all) {
3713 accessibility_->clear();
[email protected]266eb6f2008-09-30 23:56:503714 return;
[email protected]c7287a92009-11-04 20:06:153715 }
3716
3717 accessibility_->remove(acc_obj_id);
[email protected]e846d0d2009-05-20 00:53:063718
[email protected]6c8afae52009-01-22 02:24:573719#else // defined(OS_WIN)
3720 // TODO(port): accessibility not yet implemented
3721 NOTIMPLEMENTED();
3722#endif
[email protected]266eb6f2008-09-30 23:56:503723}
3724
initial.commit09911bf2008-07-26 23:55:293725void RenderView::OnGetAllSavableResourceLinksForCurrentPage(
3726 const GURL& page_url) {
3727 // Prepare list to storage all savable resource links.
3728 std::vector<GURL> resources_list;
3729 std::vector<GURL> referrers_list;
3730 std::vector<GURL> frames_list;
3731 webkit_glue::SavableResourcesResult result(&resources_list,
3732 &referrers_list,
3733 &frames_list);
3734
[email protected]dbeb3952009-10-13 18:01:183735 if (!webkit_glue::GetAllSavableResourceLinksForCurrentPage(
3736 webview(),
3737 page_url,
3738 &result,
3739 chrome::kSavableSchemes)) {
initial.commit09911bf2008-07-26 23:55:293740 // If something is wrong when collecting all savable resource links,
3741 // send empty list to embedder(browser) to tell it failed.
3742 referrers_list.clear();
3743 resources_list.clear();
3744 frames_list.clear();
3745 }
3746
3747 // Send result of all savable resource links to embedder.
3748 Send(new ViewHostMsg_SendCurrentPageAllSavableResourceLinks(routing_id_,
3749 resources_list,
3750 referrers_list,
3751 frames_list));
3752}
3753
3754void RenderView::OnGetSerializedHtmlDataForCurrentPageWithLocalLinks(
[email protected]f6b48532009-02-12 01:56:323755 const std::vector<GURL>& links,
[email protected]fde6714d12009-02-18 22:39:313756 const std::vector<FilePath>& local_paths,
3757 const FilePath& local_directory_name) {
[email protected]d9ec5c0f2009-12-23 11:55:073758
3759 // Convert std::vector of GURLs to WebVector<WebURL>
3760 WebVector<WebURL> weburl_links(links);
3761
3762 // Convert std::vector of std::strings to WebVector<WebString>
3763 WebVector<WebString> webstring_paths(local_paths.size());
3764 for (size_t i = 0; i < local_paths.size(); i++)
3765 webstring_paths[i] = webkit_glue::FilePathToWebString(local_paths[i]);
3766
3767 WebPageSerializer::serialize(webview()->mainFrame(),
3768 true, this, weburl_links, webstring_paths,
3769 webkit_glue::FilePathToWebString(
3770 local_directory_name));
initial.commit09911bf2008-07-26 23:55:293771}
3772
[email protected]d9ec5c0f2009-12-23 11:55:073773void RenderView::didSerializeDataForFrame(const WebURL& frame_url,
3774 const WebCString& data,
3775 WebPageSerializerClient::PageSerializationStatus status) {
3776 Send(new ViewHostMsg_SendSerializedHtmlData(
3777 routing_id_,
3778 frame_url,
3779 data.data(),
3780 static_cast<int32>(status)));
initial.commit09911bf2008-07-26 23:55:293781}
3782
[email protected]04b4a6c2008-08-02 00:44:473783void RenderView::OnMsgShouldClose() {
[email protected]26aa0482009-09-30 16:55:273784 bool should_close = webview()->dispatchBeforeUnloadEvent();
[email protected]04b4a6c2008-08-02 00:44:473785 Send(new ViewHostMsg_ShouldClose_ACK(routing_id_, should_close));
initial.commit09911bf2008-07-26 23:55:293786}
3787
[email protected]eb6b87a2009-07-24 15:57:393788void RenderView::OnClosePage(const ViewMsg_ClosePage_Params& params) {
initial.commit09911bf2008-07-26 23:55:293789 // TODO(creis): We'd rather use webview()->Close() here, but that currently
3790 // sets the WebView's delegate_ to NULL, preventing any JavaScript dialogs
3791 // in the onunload handler from appearing. For now, we're bypassing that and
3792 // calling the FrameLoader's CloseURL method directly. This should be
3793 // revisited to avoid having two ways to close a page. Having a single way
3794 // to close that can run onunload is also useful for fixing
3795 // http://b/issue?id=753080.
[email protected]26aa0482009-09-30 16:55:273796 WebFrame* main_frame = webview()->mainFrame();
[email protected]7a9b51f2009-06-29 21:28:293797 if (main_frame) {
[email protected]dd7daa82009-08-10 05:46:453798 const GURL& url = main_frame->url();
[email protected]3d9689372009-09-10 04:29:173799 // TODO(davemoore) this code should be removed once willClose() gets
[email protected]7a9b51f2009-06-29 21:28:293800 // called when a page is destroyed. DumpLoadHistograms() is safe to call
3801 // multiple times for the same frame, but it will simplify things.
[email protected]dd7daa82009-08-10 05:46:453802 if (url.SchemeIs(chrome::kHttpScheme) ||
3803 url.SchemeIs(chrome::kHttpsScheme))
[email protected]7a9b51f2009-06-29 21:28:293804 DumpLoadHistograms();
[email protected]7a9b51f2009-06-29 21:28:293805 }
[email protected]26aa0482009-09-30 16:55:273806 webview()->dispatchUnloadEvent();
initial.commit09911bf2008-07-26 23:55:293807
[email protected]eb6b87a2009-07-24 15:57:393808 // Just echo back the params in the ACK.
3809 Send(new ViewHostMsg_ClosePage_ACK(routing_id_, params));
initial.commit09911bf2008-07-26 23:55:293810}
3811
3812void RenderView::OnThemeChanged() {
[email protected]6c8afae52009-01-22 02:24:573813#if defined(OS_WIN)
initial.commit09911bf2008-07-26 23:55:293814 gfx::NativeTheme::instance()->CloseHandles();
3815 gfx::Rect view_rect(0, 0, size_.width(), size_.height());
[email protected]4873c7d2009-07-16 06:36:283816 didInvalidateRect(view_rect);
[email protected]6c8afae52009-01-22 02:24:573817#else // defined(OS_WIN)
3818 // TODO(port): we don't support theming on non-Windows platforms yet
3819 NOTIMPLEMENTED();
3820#endif
initial.commit09911bf2008-07-26 23:55:293821}
3822
[email protected]28790922009-03-09 19:48:373823void RenderView::OnMessageFromExternalHost(const std::string& message,
3824 const std::string& origin,
3825 const std::string& target) {
[email protected]3ac14a052008-08-15 21:22:153826 if (message.empty())
3827 return;
3828
[email protected]28790922009-03-09 19:48:373829 external_host_bindings_.ForwardMessageFromExternalHost(message, origin,
3830 target);
[email protected]3ac14a052008-08-15 21:22:153831}
3832
[email protected]0aa55312008-10-17 21:53:083833void RenderView::OnDisassociateFromPopupCount() {
3834 if (decrement_shared_popup_at_destruction_)
3835 shared_popup_counter_->data--;
3836 shared_popup_counter_ = new SharedRenderViewCounter(0);
3837 decrement_shared_popup_at_destruction_ = false;
3838}
3839
[email protected]15d79e12009-08-02 19:23:453840bool RenderView::MaybeLoadAlternateErrorPage(WebFrame* frame,
3841 const WebURLError& error,
3842 bool replace) {
3843 // We only show alternate error pages in the main frame. They are
3844 // intended to assist the user when navigating, so there is not much
3845 // value in showing them for failed subframes. Ideally, we would be
3846 // able to use the TYPED transition type for this, but that flag is
3847 // not preserved across page reloads.
[email protected]dd7daa82009-08-10 05:46:453848 if (frame->parent())
[email protected]15d79e12009-08-02 19:23:453849 return false;
3850
3851 // Use the alternate error page service if this is a DNS failure or
[email protected]c53976d52009-08-07 18:58:373852 // connection failure.
[email protected]15d79e12009-08-02 19:23:453853 int ec = error.reason;
3854 if (ec != net::ERR_NAME_NOT_RESOLVED &&
3855 ec != net::ERR_CONNECTION_FAILED &&
3856 ec != net::ERR_CONNECTION_REFUSED &&
3857 ec != net::ERR_ADDRESS_UNREACHABLE &&
[email protected]c53976d52009-08-07 18:58:373858 ec != net::ERR_CONNECTION_TIMED_OUT)
[email protected]15d79e12009-08-02 19:23:453859 return false;
3860
3861 const GURL& error_page_url = GetAlternateErrorPageURL(error.unreachableURL,
[email protected]7ccddb8c2009-08-04 17:36:553862 ec == net::ERR_NAME_NOT_RESOLVED ? DNS_ERROR : CONNECTION_ERROR);
[email protected]15d79e12009-08-02 19:23:453863 if (!error_page_url.is_valid())
3864 return false;
3865
3866 // Load an empty page first so there is an immediate response to the error,
3867 // and then kick off a request for the alternate error page.
[email protected]dd7daa82009-08-10 05:46:453868 frame->loadHTMLString(std::string(),
[email protected]15d79e12009-08-02 19:23:453869 GURL(kUnreachableWebDataURL),
3870 error.unreachableURL,
3871 replace);
3872
3873 // Now, create a fetcher for the error page and associate it with the data
3874 // source we just created via the LoadHTMLString call. That way if another
3875 // navigation occurs, the fetcher will get destroyed.
3876 NavigationState* navigation_state =
[email protected]dd7daa82009-08-10 05:46:453877 NavigationState::FromDataSource(frame->provisionalDataSource());
[email protected]15d79e12009-08-02 19:23:453878 navigation_state->set_alt_error_page_fetcher(
3879 new AltErrorPageResourceFetcher(
3880 error_page_url, frame, error,
3881 NewCallback(this, &RenderView::AltErrorPageFinished)));
3882 return true;
3883}
3884
initial.commit09911bf2008-07-26 23:55:293885std::string RenderView::GetAltHTMLForTemplate(
3886 const DictionaryValue& error_strings, int template_resource_id) const {
[email protected]8a16266e2009-09-10 21:08:393887 const base::StringPiece template_html(
initial.commit09911bf2008-07-26 23:55:293888 ResourceBundle::GetSharedInstance().GetRawDataResource(
3889 template_resource_id));
3890
3891 if (template_html.empty()) {
3892 NOTREACHED() << "unable to load template. ID: " << template_resource_id;
3893 return "";
3894 }
[email protected]7cd22a52009-07-14 00:40:253895
initial.commit09911bf2008-07-26 23:55:293896 // "t" is the id of the templates root node.
[email protected]7cd22a52009-07-14 00:40:253897 return jstemplate_builder::GetTemplatesHtml(
initial.commit09911bf2008-07-26 23:55:293898 template_html, &error_strings, "t");
3899}
[email protected]0e79b9e2009-02-13 04:20:483900
[email protected]15d79e12009-08-02 19:23:453901void RenderView::AltErrorPageFinished(WebFrame* frame,
3902 const WebURLError& original_error,
3903 const std::string& html) {
3904 // Here, we replace the blank page we loaded previously.
[email protected]7ccddb8c2009-08-04 17:36:553905
3906 // If we failed to download the alternate error page, fall back to the
3907 // original error page if present. Otherwise, LoadNavigationErrorPage
3908 // will simply display a default error page.
3909 const std::string* html_to_load = &html;
3910 if (html.empty()) {
3911 NavigationState* navigation_state =
[email protected]dd7daa82009-08-10 05:46:453912 NavigationState::FromDataSource(frame->dataSource());
[email protected]7ccddb8c2009-08-04 17:36:553913 html_to_load = &navigation_state->postponed_data();
3914 }
3915 LoadNavigationErrorPage(
3916 frame, WebURLRequest(), original_error, *html_to_load, true);
[email protected]15d79e12009-08-02 19:23:453917}
3918
[email protected]30f75e62009-02-25 22:01:003919void RenderView::OnMoveOrResizeStarted() {
3920 if (webview())
[email protected]4605325d2010-02-08 23:46:043921 webview()->hideSuggestionsPopup();
[email protected]30f75e62009-02-25 22:01:003922}
3923
[email protected]30f75e62009-02-25 22:01:003924void RenderView::OnResize(const gfx::Size& new_size,
3925 const gfx::Rect& resizer_rect) {
[email protected]cda45c02010-02-25 19:28:103926 if (webview()) {
[email protected]4605325d2010-02-08 23:46:043927 webview()->hideSuggestionsPopup();
[email protected]cda45c02010-02-25 19:28:103928
3929 if (send_preferred_size_changes_) {
3930 // If resizing to a size larger than |disable_scrollbars_size_limit_| in
3931 // either width or height, allow scroll bars.
3932 bool allow_scrollbars = (
3933 disable_scrollbars_size_limit_.width() <= new_size.width() ||
3934 disable_scrollbars_size_limit_.height() <= new_size.height()
3935 );
3936 webview()->mainFrame()->setCanHaveScrollbars(allow_scrollbars);
3937 }
3938 }
3939
[email protected]30f75e62009-02-25 22:01:003940 RenderWidget::OnResize(new_size, resizer_rect);
3941}
[email protected]0aa477bd2009-03-23 22:21:433942
[email protected]00c39612010-03-06 02:53:283943void RenderView::DidInitiatePaint() {
3944 // Notify any pepper plugins that we started painting. The plugin "should"
3945 // never notified that we started painting, this is used for internal
3946 // bookkeeping only, so we know that the set can not change under us.
3947 for (std::set<WebPluginDelegatePepper*>::iterator i =
3948 current_pepper_plugins_.begin();
3949 i != current_pepper_plugins_.end(); ++i)
3950 (*i)->RenderViewInitiatedPaint();
3951}
3952
3953void RenderView::DidFlushPaint() {
3954 // Notify any pepper plugins that we painted. This will call into the plugin,
3955 // and we it may ask to close itself as a result. This will, in turn, modify
3956 // our set, possibly invalidating the iterator. So we iterate on a copy that
3957 // won't change out from under us.
3958 std::set<WebPluginDelegatePepper*> plugins = current_pepper_plugins_;
3959 for (std::set<WebPluginDelegatePepper*>::iterator i = plugins.begin();
3960 i != plugins.end(); ++i) {
3961 // The copy above makes sure our iterator is never invalid if some plugins
3962 // are destroyed. But some plugin may decide to close all of its views in
3963 // response to a paint in one of them, so we need to make sure each one is
3964 // still "current" before using it.
3965 if (current_pepper_plugins_.find(*i) != current_pepper_plugins_.end())
3966 (*i)->RenderViewFlushedPaint();
3967 }
3968
3969 WebFrame* main_frame = webview()->mainFrame();
3970
3971 // If we have a provisional frame we are between the start and commit stages
3972 // of loading and we don't want to save stats.
3973 if (!main_frame->provisionalDataSource()) {
3974 WebDataSource* ds = main_frame->dataSource();
3975 NavigationState* navigation_state = NavigationState::FromDataSource(ds);
3976 DCHECK(navigation_state);
3977
3978 Time now = Time::Now();
3979 if (navigation_state->first_paint_time().is_null()) {
3980 navigation_state->set_first_paint_time(now);
3981 }
3982 if (navigation_state->first_paint_after_load_time().is_null() &&
3983 !navigation_state->finish_load_time().is_null()) {
3984 navigation_state->set_first_paint_after_load_time(now);
3985 }
3986 }
3987}
3988
3989
[email protected]05d478752009-04-08 23:38:163990void RenderView::OnClearFocusedNode() {
3991 if (webview())
[email protected]26aa0482009-09-30 16:55:273992 webview()->clearFocusedNode();
[email protected]05d478752009-04-08 23:38:163993}
3994
[email protected]699ab0d2009-04-23 23:19:143995void RenderView::OnSetBackground(const SkBitmap& background) {
3996 if (webview())
[email protected]b4bb2502009-10-01 22:35:273997 webview()->setIsTransparent(!background.empty());
[email protected]699ab0d2009-04-23 23:19:143998
3999 SetBackground(background);
4000}
4001
[email protected]8c66c5a2009-07-22 17:26:344002void RenderView::OnSetActive(bool active) {
4003 if (webview())
[email protected]b4bb2502009-10-01 22:35:274004 webview()->setIsActive(active);
[email protected]d8fd6fa2010-02-01 15:54:264005
4006#if defined(OS_MACOSX)
4007 std::set<WebPluginDelegateProxy*>::iterator plugin_it;
4008 for (plugin_it = plugin_delegates_.begin();
4009 plugin_it != plugin_delegates_.end(); ++plugin_it) {
4010 (*plugin_it)->SetWindowFocus(active);
4011 }
4012#endif
[email protected]8c66c5a2009-07-22 17:26:344013}
4014
[email protected]6ce7abc52010-02-02 18:40:144015#if defined(OS_MACOSX)
4016void RenderView::OnSetWindowVisibility(bool visible) {
4017 // Inform plugins that their container has changed visibility.
4018 std::set<WebPluginDelegateProxy*>::iterator plugin_it;
4019 for (plugin_it = plugin_delegates_.begin();
4020 plugin_it != plugin_delegates_.end(); ++plugin_it) {
4021 (*plugin_it)->SetContainerVisibility(visible);
4022 }
4023}
[email protected]1e6e3c992010-02-08 15:52:134024
4025void RenderView::OnWindowFrameChanged(gfx::Rect window_frame,
4026 gfx::Rect view_frame) {
4027 // Inform plugins that their window's frame has changed.
4028 std::set<WebPluginDelegateProxy*>::iterator plugin_it;
4029 for (plugin_it = plugin_delegates_.begin();
4030 plugin_it != plugin_delegates_.end(); ++plugin_it) {
4031 (*plugin_it)->WindowFrameChanged(window_frame, view_frame);
4032 }
4033}
[email protected]6ce7abc52010-02-02 18:40:144034#endif // OS_MACOSX
4035
[email protected]309d7a282009-03-24 09:18:274036void RenderView::SendExtensionRequest(const std::string& name,
[email protected]e4dad9fb2009-10-06 18:15:584037 const ListValue& args,
[email protected]c6619182009-05-12 14:59:324038 int request_id,
[email protected]2f25d7b92009-06-10 00:06:474039 bool has_callback) {
[email protected]c6619182009-05-12 14:59:324040 Send(new ViewHostMsg_ExtensionRequest(routing_id_, name, args, request_id,
[email protected]2f25d7b92009-06-10 00:06:474041 has_callback));
[email protected]309d7a282009-03-24 09:18:274042}
4043
[email protected]c6619182009-05-12 14:59:324044void RenderView::OnExtensionResponse(int request_id,
4045 bool success,
4046 const std::string& response,
4047 const std::string& error) {
[email protected]0f6053962009-07-09 19:26:354048 ExtensionProcessBindings::HandleResponse(
4049 request_id, success, response, error);
[email protected]309d7a282009-03-24 09:18:274050}
[email protected]c20210e62009-04-03 21:39:264051
[email protected]078b34612009-09-19 19:31:514052void RenderView::InjectToolstripCSS() {
4053 if (view_type_ != ViewType::EXTENSION_TOOLSTRIP)
4054 return;
4055
4056 static const base::StringPiece toolstrip_css(
4057 ResourceBundle::GetSharedInstance().GetRawDataResource(
4058 IDR_EXTENSION_TOOLSTRIP_CSS));
4059 std::string css = toolstrip_css.as_string();
4060 InsertCSS(L"", css, "ToolstripDefaultCSS");
4061}
4062
[email protected]7120f132009-07-20 21:05:374063void RenderView::OnExtensionMessageInvoke(const std::string& function_name,
4064 const ListValue& args) {
4065 RendererExtensionBindings::Invoke(function_name, args, this);
4066}
4067
[email protected]e7e4f3c2009-04-21 15:24:084068// Dump all load time histograms.
[email protected]c20210e62009-04-03 21:39:264069//
[email protected]7a9b51f2009-06-29 21:28:294070// There are 13 histograms measuring various times.
[email protected]c20210e62009-04-03 21:39:264071// The time points we keep are
4072// request: time document was requested by user
4073// start: time load of document started
[email protected]a2f6bc112009-06-27 16:27:254074// commit: time load of document started
[email protected]7a9b51f2009-06-29 21:28:294075// finish_document: main document loaded, before onload()
[email protected]c20210e62009-04-03 21:39:264076// finish: after onload() and all resources are loaded
[email protected]7a9b51f2009-06-29 21:28:294077// first_paint: first paint performed
4078// first_paint_after_load: first paint performed after load is finished
4079// begin: request if it was user requested, start otherwise
4080//
[email protected]c20210e62009-04-03 21:39:264081// The times that we histogram are
[email protected]a2f6bc112009-06-27 16:27:254082// request->start,
[email protected]7a9b51f2009-06-29 21:28:294083// start->commit,
4084// commit->finish_document,
4085// finish_document->finish,
4086// begin->commit,
4087// begin->finishDoc,
4088// begin->finish,
4089// begin->first_paint,
4090// begin->first_paint_after_load
4091// commit->finishDoc,
4092// commit->first_paint,
4093// commit->first_paint_after_load,
4094// finish->first_paint_after_load,
[email protected]c20210e62009-04-03 21:39:264095//
[email protected]e7e4f3c2009-04-21 15:24:084096// It's possible for the request time not to be set, if a client
4097// redirect had been done (the user never requested the page)
4098// Also, it's possible to load a page without ever laying it out
[email protected]7a9b51f2009-06-29 21:28:294099// so first_paint and first_paint_after_load can be 0.
[email protected]c20210e62009-04-03 21:39:264100void RenderView::DumpLoadHistograms() const {
[email protected]26aa0482009-09-30 16:55:274101 WebFrame* main_frame = webview()->mainFrame();
[email protected]ed3fb032009-06-16 19:50:564102 NavigationState* navigation_state =
[email protected]dd7daa82009-08-10 05:46:454103 NavigationState::FromDataSource(main_frame->dataSource());
[email protected]7a9b51f2009-06-29 21:28:294104 Time finish = navigation_state->finish_load_time();
[email protected]ed3fb032009-06-16 19:50:564105
[email protected]7a9b51f2009-06-29 21:28:294106 // If we've already dumped or we haven't finished loading, do nothing.
4107 if (navigation_state->load_histograms_recorded() || finish.is_null())
4108 return;
[email protected]ed3fb032009-06-16 19:50:564109
[email protected]f8999642009-10-27 21:39:424110 LogNavigationState(navigation_state, main_frame->dataSource());
4111
[email protected]a7ccc4d2010-01-27 08:14:484112 NavigationState::LoadType load_type = navigation_state->load_type();
4113 UMA_HISTOGRAM_ENUMERATION("Renderer4.LoadType", load_type,
[email protected]4c1b6f0b2010-02-07 16:38:184114 NavigationState::kLoadTypeMax);
[email protected]a7ccc4d2010-01-27 08:14:484115
[email protected]7a9b51f2009-06-29 21:28:294116 Time request = navigation_state->request_time();
4117 Time start = navigation_state->start_load_time();
4118 Time commit = navigation_state->commit_load_time();
4119 Time finish_doc = navigation_state->finish_document_load_time();
4120 Time first_paint = navigation_state->first_paint_time();
4121 Time first_paint_after_load =
4122 navigation_state->first_paint_after_load_time();
[email protected]c20210e62009-04-03 21:39:264123
[email protected]7a9b51f2009-06-29 21:28:294124 Time begin;
4125 // Client side redirects will have no request time.
4126 if (request.is_null()) {
4127 begin = start;
4128 } else {
4129 begin = request;
4130 UMA_HISTOGRAM_MEDIUM_TIMES("Renderer4.RequestToStart", start - request);
[email protected]e7e4f3c2009-04-21 15:24:084131 }
[email protected]7a9b51f2009-06-29 21:28:294132 UMA_HISTOGRAM_MEDIUM_TIMES("Renderer4.StartToCommit", commit - start);
4133 UMA_HISTOGRAM_MEDIUM_TIMES(
4134 "Renderer4.CommitToFinishDoc", finish_doc - commit);
4135 UMA_HISTOGRAM_MEDIUM_TIMES(
4136 "Renderer4.FinishDocToFinish", finish - finish_doc);
4137
4138 UMA_HISTOGRAM_MEDIUM_TIMES("Renderer4.BeginToCommit", commit - begin);
[email protected]a7ccc4d2010-01-27 08:14:484139
4140 static const TimeDelta kBeginToFinishDocMin(TimeDelta::FromMilliseconds(10));
4141 static const TimeDelta kBeginToFinishDocMax(TimeDelta::FromMinutes(10));
4142 static const size_t kBeginToFinishDocBucketCount(100);
[email protected]a7ccc4d2010-01-27 08:14:484143 TimeDelta begin_to_finish_doc = finish_doc - begin;
4144 UMA_HISTOGRAM_MEDIUM_TIMES("Renderer4.BeginToFinishDoc", begin_to_finish_doc);
[email protected]4c1b6f0b2010-02-07 16:38:184145
4146 static const TimeDelta kBeginToFinishMin(TimeDelta::FromMilliseconds(10));
4147 static const TimeDelta kBeginToFinishMax(TimeDelta::FromMinutes(10));
4148 static const size_t kBeginToFinishBucketCount(100);
4149 TimeDelta begin_to_finish = finish_doc - begin;
4150 UMA_HISTOGRAM_CUSTOM_TIMES("Renderer4.BeginToFinish", begin_to_finish,
4151 kBeginToFinishMin, kBeginToFinishMax, kBeginToFinishBucketCount);
4152
[email protected]a7ccc4d2010-01-27 08:14:484153 switch (load_type) {
4154 case NavigationState::UNDEFINED_LOAD:
4155 UMA_HISTOGRAM_CUSTOM_TIMES("Renderer4.BeginToFinishDoc_UndefLoad",
4156 begin_to_finish_doc, kBeginToFinishDocMin, kBeginToFinishDocMax,
4157 kBeginToFinishDocBucketCount);
[email protected]4c1b6f0b2010-02-07 16:38:184158 UMA_HISTOGRAM_CUSTOM_TIMES("Renderer4.BeginToFinish_UndefLoad",
4159 begin_to_finish, kBeginToFinishMin, kBeginToFinishMax,
4160 kBeginToFinishBucketCount);
[email protected]a7ccc4d2010-01-27 08:14:484161 break;
4162 case NavigationState::RELOAD:
4163 UMA_HISTOGRAM_CUSTOM_TIMES("Renderer4.BeginToFinishDoc_Reload",
4164 begin_to_finish_doc, kBeginToFinishDocMin, kBeginToFinishDocMax,
4165 kBeginToFinishDocBucketCount);
[email protected]4c1b6f0b2010-02-07 16:38:184166 UMA_HISTOGRAM_CUSTOM_TIMES("Renderer4.BeginToFinish_Reload",
4167 begin_to_finish, kBeginToFinishMin, kBeginToFinishMax,
4168 kBeginToFinishBucketCount);
[email protected]a7ccc4d2010-01-27 08:14:484169 break;
4170 case NavigationState::HISTORY_LOAD:
4171 UMA_HISTOGRAM_CUSTOM_TIMES("Renderer4.BeginToFinishDoc_HistoryLoad",
4172 begin_to_finish_doc, kBeginToFinishDocMin, kBeginToFinishDocMax,
4173 kBeginToFinishDocBucketCount);
[email protected]4c1b6f0b2010-02-07 16:38:184174 UMA_HISTOGRAM_CUSTOM_TIMES("Renderer4.BeginToFinish_HistoryLoad",
4175 begin_to_finish, kBeginToFinishMin, kBeginToFinishMax,
4176 kBeginToFinishBucketCount);
[email protected]a7ccc4d2010-01-27 08:14:484177 break;
4178 case NavigationState::NORMAL_LOAD:
4179 UMA_HISTOGRAM_CUSTOM_TIMES("Renderer4.BeginToFinishDoc_NormalLoad",
4180 begin_to_finish_doc, kBeginToFinishDocMin, kBeginToFinishDocMax,
4181 kBeginToFinishDocBucketCount);
[email protected]4c1b6f0b2010-02-07 16:38:184182 UMA_HISTOGRAM_CUSTOM_TIMES("Renderer4.BeginToFinish_NormalLoad",
4183 begin_to_finish, kBeginToFinishMin, kBeginToFinishMax,
4184 kBeginToFinishBucketCount);
[email protected]a7ccc4d2010-01-27 08:14:484185 break;
[email protected]4c1b6f0b2010-02-07 16:38:184186 case NavigationState::LINK_LOAD_NORMAL:
4187 UMA_HISTOGRAM_CUSTOM_TIMES("Renderer4.BeginToFinishDoc_LinkLoadNormal",
[email protected]a7ccc4d2010-01-27 08:14:484188 begin_to_finish_doc, kBeginToFinishDocMin, kBeginToFinishDocMax,
4189 kBeginToFinishDocBucketCount);
[email protected]4c1b6f0b2010-02-07 16:38:184190 UMA_HISTOGRAM_CUSTOM_TIMES("Renderer4.BeginToFinish_LinkLoadNormal",
4191 begin_to_finish, kBeginToFinishMin, kBeginToFinishMax,
4192 kBeginToFinishBucketCount);
4193 break;
4194 case NavigationState::LINK_LOAD_RELOAD:
4195 UMA_HISTOGRAM_CUSTOM_TIMES("Renderer4.BeginToFinishDoc_LinkLoadReload",
4196 begin_to_finish_doc, kBeginToFinishDocMin, kBeginToFinishDocMax,
4197 kBeginToFinishDocBucketCount);
4198 UMA_HISTOGRAM_CUSTOM_TIMES("Renderer4.BeginToFinish_LinkLoadReload",
4199 begin_to_finish, kBeginToFinishMin, kBeginToFinishMax,
4200 kBeginToFinishBucketCount);
4201 break;
4202 case NavigationState::LINK_LOAD_CACHE_STALE_OK:
4203 UMA_HISTOGRAM_CUSTOM_TIMES("Renderer4.BeginToFinishDoc_LinkLoadStaleOk",
4204 begin_to_finish_doc, kBeginToFinishDocMin, kBeginToFinishDocMax,
4205 kBeginToFinishDocBucketCount);
4206 UMA_HISTOGRAM_CUSTOM_TIMES("Renderer4.BeginToFinish_LinkLoadStaleOk",
4207 begin_to_finish, kBeginToFinishMin, kBeginToFinishMax,
4208 kBeginToFinishBucketCount);
4209 break;
4210 case NavigationState::LINK_LOAD_CACHE_ONLY:
4211 UMA_HISTOGRAM_CUSTOM_TIMES("Renderer4.BeginToFinishDoc_LinkLoadCacheOnly",
4212 begin_to_finish_doc, kBeginToFinishDocMin, kBeginToFinishDocMax,
4213 kBeginToFinishDocBucketCount);
4214 UMA_HISTOGRAM_CUSTOM_TIMES("Renderer4.BeginToFinish_LinkLoadCacheOnly",
4215 begin_to_finish, kBeginToFinishMin, kBeginToFinishMax,
4216 kBeginToFinishBucketCount);
[email protected]a7ccc4d2010-01-27 08:14:484217 break;
4218 default:
4219 break;
4220 }
4221
4222 static bool use_dns_histogram(FieldTrialList::Find("DnsImpact") &&
4223 !FieldTrialList::Find("DnsImpact")->group_name().empty());
4224 if (use_dns_histogram) {
[email protected]fd11f1752010-02-23 22:35:484225 UMA_HISTOGRAM_ENUMERATION(FieldTrial::MakeName(
4226 "Renderer4.LoadType", "DnsImpact"),
4227 load_type, NavigationState::kLoadTypeMax);
[email protected]a7ccc4d2010-01-27 08:14:484228 switch (load_type) {
4229 case NavigationState::NORMAL_LOAD:
4230 UMA_HISTOGRAM_CUSTOM_TIMES(FieldTrial::MakeName(
[email protected]4c1b6f0b2010-02-07 16:38:184231 "Renderer4.BeginToFinish_NormalLoad", "DnsImpact"),
4232 begin_to_finish, kBeginToFinishMin, kBeginToFinishMax,
4233 kBeginToFinishBucketCount);
4234 break;
4235 case NavigationState::LINK_LOAD_NORMAL:
4236 UMA_HISTOGRAM_CUSTOM_TIMES(FieldTrial::MakeName(
[email protected]4c1b6f0b2010-02-07 16:38:184237 "Renderer4.BeginToFinish_LinkLoadNormal", "DnsImpact"),
4238 begin_to_finish, kBeginToFinishMin, kBeginToFinishMax,
4239 kBeginToFinishBucketCount);
4240 break;
4241 case NavigationState::LINK_LOAD_RELOAD:
4242 UMA_HISTOGRAM_CUSTOM_TIMES(FieldTrial::MakeName(
[email protected]4c1b6f0b2010-02-07 16:38:184243 "Renderer4.BeginToFinish_LinkLoadReload", "DnsImpact"),
4244 begin_to_finish, kBeginToFinishMin, kBeginToFinishMax,
4245 kBeginToFinishBucketCount);
4246 break;
4247 case NavigationState::LINK_LOAD_CACHE_STALE_OK:
4248 UMA_HISTOGRAM_CUSTOM_TIMES(FieldTrial::MakeName(
[email protected]4c1b6f0b2010-02-07 16:38:184249 "Renderer4.BeginToFinish_LinkLoadStaleOk", "DnsImpact"),
4250 begin_to_finish, kBeginToFinishMin, kBeginToFinishMax,
4251 kBeginToFinishBucketCount);
[email protected]a7ccc4d2010-01-27 08:14:484252 break;
4253 default:
4254 break;
4255 }
4256 }
4257
4258 static bool use_sdch_histogram(FieldTrialList::Find("GlobalSdch") &&
4259 !FieldTrialList::Find("GlobalSdch")->group_name().empty());
4260 if (use_sdch_histogram) {
[email protected]fd11f1752010-02-23 22:35:484261 UMA_HISTOGRAM_ENUMERATION(
4262 FieldTrial::MakeName("Renderer4.LoadType", "GlobalSdch"),
4263 load_type, NavigationState::kLoadTypeMax);
[email protected]a7ccc4d2010-01-27 08:14:484264 switch (load_type) {
4265 case NavigationState::NORMAL_LOAD:
4266 UMA_HISTOGRAM_CUSTOM_TIMES(FieldTrial::MakeName(
[email protected]fd11f1752010-02-23 22:35:484267 "Renderer4.BeginToFinish_NormalLoad", "GlobalSdch"),
4268 begin_to_finish, kBeginToFinishMin, kBeginToFinishMax,
4269 kBeginToFinishBucketCount);
[email protected]a7ccc4d2010-01-27 08:14:484270 break;
[email protected]4c1b6f0b2010-02-07 16:38:184271 case NavigationState::LINK_LOAD_NORMAL:
[email protected]a7ccc4d2010-01-27 08:14:484272 UMA_HISTOGRAM_CUSTOM_TIMES(FieldTrial::MakeName(
[email protected]fd11f1752010-02-23 22:35:484273 "Renderer4.BeginToFinish_LinkLoadNormal", "GlobalSdch"),
4274 begin_to_finish, kBeginToFinishMin, kBeginToFinishMax,
4275 kBeginToFinishBucketCount);
[email protected]4c1b6f0b2010-02-07 16:38:184276 break;
4277 case NavigationState::LINK_LOAD_RELOAD:
4278 UMA_HISTOGRAM_CUSTOM_TIMES(FieldTrial::MakeName(
[email protected]fd11f1752010-02-23 22:35:484279 "Renderer4.BeginToFinish_LinkLoadReload", "GlobalSdch"),
4280 begin_to_finish, kBeginToFinishMin, kBeginToFinishMax,
4281 kBeginToFinishBucketCount);
[email protected]4c1b6f0b2010-02-07 16:38:184282 break;
4283 case NavigationState::LINK_LOAD_CACHE_STALE_OK:
4284 UMA_HISTOGRAM_CUSTOM_TIMES(FieldTrial::MakeName(
[email protected]fd11f1752010-02-23 22:35:484285 "Renderer4.BeginToFinish_LinkLoadStaleOk", "GlobalSdch"),
4286 begin_to_finish, kBeginToFinishMin, kBeginToFinishMax,
4287 kBeginToFinishBucketCount);
[email protected]4c1b6f0b2010-02-07 16:38:184288 break;
4289 case NavigationState::LINK_LOAD_CACHE_ONLY:
4290 UMA_HISTOGRAM_CUSTOM_TIMES(FieldTrial::MakeName(
[email protected]fd11f1752010-02-23 22:35:484291 "Renderer4.BeginToFinish_LinkLoadCacheOnly", "GlobalSdch"),
4292 begin_to_finish, kBeginToFinishMin, kBeginToFinishMax,
4293 kBeginToFinishBucketCount);
[email protected]a7ccc4d2010-01-27 08:14:484294 break;
4295 default:
4296 break;
4297 }
4298 }
4299
4300 static bool use_cache_histogram1(FieldTrialList::Find("CacheSize") &&
4301 !FieldTrialList::Find("CacheSize")->group_name().empty());
[email protected]4c1b6f0b2010-02-07 16:38:184302 if (use_cache_histogram1 && NavigationState::LINK_LOAD_NORMAL <= load_type &&
4303 NavigationState::LINK_LOAD_CACHE_ONLY >= load_type)
[email protected]a7ccc4d2010-01-27 08:14:484304 UMA_HISTOGRAM_CUSTOM_TIMES(FieldTrial::MakeName(
4305 "Renderer4.BeginToFinishDoc_LinkLoad", "CacheSize"),
4306 begin_to_finish_doc, kBeginToFinishDocMin, kBeginToFinishDocMax,
4307 kBeginToFinishDocBucketCount);
[email protected]e695fbd62009-06-30 16:31:544308
[email protected]0a32257a2009-07-09 18:10:414309 UMA_HISTOGRAM_CUSTOM_TIMES("Renderer4.StartToFinish",
4310 finish - start, kBeginToFinishMin,
4311 kBeginToFinishMax, kBeginToFinishBucketCount);
4312 if (!request.is_null())
4313 UMA_HISTOGRAM_CUSTOM_TIMES("Renderer4.RequestToFinish",
4314 finish - request, kBeginToFinishMin,
4315 kBeginToFinishMax, kBeginToFinishBucketCount);
[email protected]e695fbd62009-06-30 16:31:544316
[email protected]7a9b51f2009-06-29 21:28:294317 UMA_HISTOGRAM_MEDIUM_TIMES("Renderer4.CommitToFinish", finish - commit);
4318
4319 if (!first_paint.is_null()) {
4320 UMA_HISTOGRAM_MEDIUM_TIMES(
4321 "Renderer4.BeginToFirstPaint", first_paint - begin);
4322 UMA_HISTOGRAM_MEDIUM_TIMES(
4323 "Renderer4.CommitToFirstPaint", first_paint - commit);
[email protected]c20210e62009-04-03 21:39:264324 }
[email protected]7a9b51f2009-06-29 21:28:294325
4326 if (!first_paint_after_load.is_null()) {
4327 UMA_HISTOGRAM_MEDIUM_TIMES(
4328 "Renderer4.BeginToFirstPaintAfterLoad", first_paint_after_load - begin);
4329 UMA_HISTOGRAM_MEDIUM_TIMES(
4330 "Renderer4.CommitToFirstPaintAfterLoad",
4331 first_paint_after_load - commit);
4332 UMA_HISTOGRAM_MEDIUM_TIMES(
4333 "Renderer4.FinishToFirstPaintAfterLoad",
4334 first_paint_after_load - finish);
4335 }
4336
4337 navigation_state->set_load_histograms_recorded(true);
[email protected]1f4fc8e8c2010-01-02 00:46:414338
4339 // Since there are currently no guarantees that renderer histograms will be
4340 // sent to the browser, we initiate a PostTask here to be sure that we send
4341 // the histograms we generated. Without this call, pages that don't have an
4342 // on-close-handler might generate data that is lost when the renderer is
4343 // shutdown abruptly (perchance because the user closed the tab).
[email protected]a7ccc4d2010-01-27 08:14:484344 // TODO(jar) BUG=33233: This needs to be moved to a PostDelayedTask, and it
4345 // should post when the onload is complete, so that it doesn't interfere with
4346 // the next load.
[email protected]1f4fc8e8c2010-01-02 00:46:414347 if (RenderThread::current()) {
4348 RenderThread::current()->SendHistograms(
[email protected]7c927b62010-02-24 09:54:134349 chrome::kHistogramSynchronizerReservedSequenceNumber);
[email protected]1f4fc8e8c2010-01-02 00:46:414350 }
[email protected]c20210e62009-04-03 21:39:264351}
[email protected]e846d0d2009-05-20 00:53:064352
[email protected]f8999642009-10-27 21:39:424353void RenderView::LogNavigationState(const NavigationState* state,
4354 const WebDataSource* ds) const {
4355 // Because this function gets called on every page load,
4356 // take extra care to optimize it away if logging is turned off.
4357 if (logging::LOG_INFO < logging::GetMinLogLevel())
4358 return;
4359
4360 DCHECK(state);
4361 DCHECK(ds);
4362 GURL url(ds->request().url());
4363 Time start = state->start_load_time();
4364 Time finish = state->finish_load_time();
4365 // TODO(mbelshe): should we log more stats?
4366 LOG(INFO) << "PLT: "
4367 << (finish - start).InMilliseconds()
4368 << "ms "
4369 << url.spec();
4370}
4371
[email protected]cc0445f2009-10-13 16:09:084372void RenderView::focusAccessibilityObject(
4373 const WebAccessibilityObject& acc_obj) {
[email protected]e846d0d2009-05-20 00:53:064374#if defined(OS_WIN)
[email protected]c7287a92009-11-04 20:06:154375 // TODO(dglazkov): Current logic implies that focus change can only be made
4376 // after at least one call to RenderView::OnGetAccessibilityInfo, which is
4377 // where accessibility is initialized. We should determine whether that's
4378 // right.
4379 if (!accessibility_.get())
4380 return;
[email protected]e846d0d2009-05-20 00:53:064381
4382 // Retrieve the accessibility object id of the AccessibilityObject.
[email protected]c7287a92009-11-04 20:06:154383 int acc_obj_id = accessibility_->addOrGetId(acc_obj);
[email protected]e846d0d2009-05-20 00:53:064384
4385 // If id is valid, alert the browser side that an accessibility focus change
4386 // occurred.
4387 if (acc_obj_id >= 0)
4388 Send(new ViewHostMsg_AccessibilityFocusChange(routing_id_, acc_obj_id));
4389
4390#else // defined(OS_WIN)
4391 // TODO(port): accessibility not yet implemented
4392 NOTIMPLEMENTED();
4393#endif
4394}
[email protected]daa8c58e2009-06-15 17:21:104395
[email protected]e9e07992010-02-17 21:04:364396void RenderView::SendForms(WebFrame* frame) {
4397 WebVector<WebFormElement> web_forms;
4398 frame->forms(web_forms);
4399
4400 std::vector<FormFieldValues> forms;
4401 for (size_t i = 0; i < web_forms.size(); ++i) {
4402 const WebFormElement& web_form = web_forms[i];
4403
4404 if (web_form.autoComplete()) {
4405 scoped_ptr<FormFieldValues> form(FormFieldValues::Create(web_form));
4406 if (form.get())
4407 forms.push_back(*form);
4408 }
4409 }
4410
4411 if (!forms.empty())
4412 Send(new ViewHostMsg_FormsSeen(routing_id_, forms));
4413}
4414
[email protected]daa8c58e2009-06-15 17:21:104415void RenderView::SendPasswordForms(WebFrame* frame) {
[email protected]979c28b2009-11-07 01:30:484416 WebVector<WebFormElement> forms;
[email protected]dd7daa82009-08-10 05:46:454417 frame->forms(forms);
[email protected]daa8c58e2009-06-15 17:21:104418
4419 std::vector<PasswordForm> password_forms;
4420 for (size_t i = 0; i < forms.size(); ++i) {
[email protected]979c28b2009-11-07 01:30:484421 const WebFormElement& form = forms[i];
[email protected]daa8c58e2009-06-15 17:21:104422
4423 // Respect autocomplete=off.
[email protected]979c28b2009-11-07 01:30:484424 if (form.autoComplete()) {
[email protected]daa8c58e2009-06-15 17:21:104425 scoped_ptr<PasswordForm> password_form(
4426 PasswordFormDomManager::CreatePasswordForm(form));
4427 if (password_form.get())
4428 password_forms.push_back(*password_form);
4429 }
4430 }
4431
4432 if (!password_forms.empty())
4433 Send(new ViewHostMsg_PasswordFormsSeen(routing_id_, password_forms));
4434}
[email protected]0fda7272009-06-26 15:49:334435
4436void RenderView::Print(WebFrame* frame, bool script_initiated) {
4437 DCHECK(frame);
4438 if (print_helper_.get() == NULL) {
4439 print_helper_.reset(new PrintWebViewHelper(this));
4440 }
4441 print_helper_->Print(frame, script_initiated);
4442}
[email protected]446705872009-09-10 07:22:484443
4444void RenderView::OnSetEditCommandsForNextKeyEvent(
4445 const EditCommands& edit_commands) {
4446 edit_commands_ = edit_commands;
4447}
4448
[email protected]61f5a7b2009-12-22 22:21:204449void RenderView::OnExecuteCode(const ViewMsg_ExecuteCode_Params& params) {
[email protected]26aa0482009-09-30 16:55:274450 WebFrame* main_frame = webview() ? webview()->mainFrame() : NULL;
[email protected]912256b32009-09-18 09:47:354451 if (!main_frame) {
[email protected]61f5a7b2009-12-22 22:21:204452 Send(new ViewMsg_ExecuteCodeFinished(routing_id_, params.request_id,
4453 false));
[email protected]912256b32009-09-18 09:47:354454 return;
4455 }
4456
[email protected]fa7b6b542009-11-03 05:02:304457 WebDataSource* ds = main_frame->dataSource();
4458 NavigationState* navigation_state = NavigationState::FromDataSource(ds);
4459 if (!navigation_state->user_script_idle_scheduler()->has_run()) {
[email protected]61f5a7b2009-12-22 22:21:204460 pending_code_execution_queue_.push(
4461 linked_ptr<ViewMsg_ExecuteCode_Params>(
4462 new ViewMsg_ExecuteCode_Params(params)));
[email protected]fa7b6b542009-11-03 05:02:304463 return;
4464 }
4465
[email protected]61f5a7b2009-12-22 22:21:204466 ExecuteCodeImpl(main_frame, params);
[email protected]fa7b6b542009-11-03 05:02:304467}
4468
4469void RenderView::ExecuteCodeImpl(WebFrame* frame,
[email protected]61f5a7b2009-12-22 22:21:204470 const ViewMsg_ExecuteCode_Params& params) {
[email protected]d146b832009-12-23 02:45:484471 // Don't execute scripts in gallery pages.
4472 GURL frame_url = GURL(frame->url());
4473 if (frame_url.host() == GURL(extension_urls::kGalleryBrowsePrefix).host()) {
4474 Send(new ViewMsg_ExecuteCodeFinished(routing_id_, params.request_id, true));
4475 return;
4476 }
4477
[email protected]20ad2692009-11-20 18:27:204478 std::vector<WebFrame*> frame_vector;
4479 frame_vector.push_back(frame);
[email protected]61f5a7b2009-12-22 22:21:204480 if (params.all_frames)
[email protected]20ad2692009-11-20 18:27:204481 GetAllChildFrames(frame, &frame_vector);
4482
4483 for (std::vector<WebFrame*>::iterator frame_it = frame_vector.begin();
4484 frame_it != frame_vector.end(); ++frame_it) {
4485 WebFrame* frame = *frame_it;
[email protected]61f5a7b2009-12-22 22:21:204486 if (params.is_javascript) {
4487 if (!UrlMatchesPermissions(frame->url(), params.host_permissions))
4488 continue;
4489
[email protected]20ad2692009-11-20 18:27:204490 std::vector<WebScriptSource> sources;
4491 sources.push_back(
[email protected]61f5a7b2009-12-22 22:21:204492 WebScriptSource(WebString::fromUTF8(params.code)));
4493 UserScriptSlave::InsertInitExtensionCode(&sources, params.extension_id);
[email protected]20ad2692009-11-20 18:27:204494 frame->executeScriptInIsolatedWorld(
[email protected]61f5a7b2009-12-22 22:21:204495 UserScriptSlave::GetIsolatedWorldId(params.extension_id),
[email protected]20ad2692009-11-20 18:27:204496 &sources.front(), sources.size(), EXTENSION_GROUP_CONTENT_SCRIPTS);
4497 } else {
[email protected]61f5a7b2009-12-22 22:21:204498 frame->insertStyleText(WebString::fromUTF8(params.code), WebString());
[email protected]20ad2692009-11-20 18:27:204499 }
[email protected]912256b32009-09-18 09:47:354500 }
4501
[email protected]61f5a7b2009-12-22 22:21:204502 Send(new ViewMsg_ExecuteCodeFinished(routing_id_, params.request_id, true));
[email protected]912256b32009-09-18 09:47:354503}
4504
[email protected]60c42a8c72009-10-09 04:08:594505void RenderView::Close() {
4506 // We need to grab a pointer to the doomed WebView before we destroy it.
4507 WebView* doomed = webview();
4508 RenderWidget::Close();
4509 Singleton<ViewMap>::get()->erase(doomed);
4510}
4511
[email protected]446705872009-09-10 07:22:484512void RenderView::DidHandleKeyEvent() {
4513 edit_commands_.clear();
4514}
4515
[email protected]941e4552010-02-01 21:23:434516#if defined(OS_MACOSX)
4517void RenderView::OnWasHidden() {
4518 RenderWidget::OnWasHidden();
4519
4520 // Inform plugins that their container is no longer visible.
4521 std::set<WebPluginDelegateProxy*>::iterator plugin_it;
4522 for (plugin_it = plugin_delegates_.begin();
4523 plugin_it != plugin_delegates_.end(); ++plugin_it) {
4524 (*plugin_it)->SetContainerVisibility(false);
4525 }
4526}
4527
4528void RenderView::OnWasRestored(bool needs_repainting) {
4529 RenderWidget::OnWasRestored(needs_repainting);
4530
4531 // Inform plugins that their container is now visible.
4532 std::set<WebPluginDelegateProxy*>::iterator plugin_it;
4533 for (plugin_it = plugin_delegates_.begin();
4534 plugin_it != plugin_delegates_.end(); ++plugin_it) {
4535 (*plugin_it)->SetContainerVisibility(true);
4536 }
4537}
[email protected]1e6e3c992010-02-08 15:52:134538
4539void RenderView::OnSetFocus(bool enable) {
4540 RenderWidget::OnSetFocus(enable);
4541
4542 // RenderWidget's call to setFocus can cause the underlying webview's
4543 // activation state to change just like a call to setIsActive.
4544 if (enable && webview() && webview()->isActive()) {
4545 std::set<WebPluginDelegateProxy*>::iterator plugin_it;
4546 for (plugin_it = plugin_delegates_.begin();
4547 plugin_it != plugin_delegates_.end(); ++plugin_it) {
4548 (*plugin_it)->SetWindowFocus(true);
4549 }
4550 }
4551}
[email protected]941e4552010-02-01 21:23:434552#endif // OS_MACOSX
4553
[email protected]83dde542009-09-11 20:59:554554void RenderView::EnsureDocumentTag() {
4555 // TODO(darin): There's actually no reason for this to be here. We should
4556 // have the browser side manage the document tag.
4557#if defined(OS_MACOSX)
4558 if (!has_document_tag_) {
4559 // Make the call to get the tag.
4560 Send(new ViewHostMsg_GetDocumentTag(routing_id_, &document_tag_));
4561 has_document_tag_ = true;
4562 }
4563#endif
4564}
[email protected]12636df2009-09-28 22:32:214565
[email protected]43f28f832010-02-03 02:28:484566#if defined(OS_MACOSX)
4567gfx::PluginWindowHandle RenderView::AllocateFakePluginWindowHandle() {
4568 gfx::PluginWindowHandle window = NULL;
4569 Send(new ViewHostMsg_AllocateFakePluginWindowHandle(
4570 routing_id(), &window));
4571 return window;
4572}
4573
4574void RenderView::DestroyFakePluginWindowHandle(gfx::PluginWindowHandle window) {
4575 if (window)
4576 Send(new ViewHostMsg_DestroyFakePluginWindowHandle(routing_id(), window));
4577}
4578
4579void RenderView::GPUPluginSetIOSurface(gfx::PluginWindowHandle window,
4580 int32 width,
4581 int32 height,
4582 uint64 io_surface_identifier) {
4583 Send(new ViewHostMsg_GPUPluginSetIOSurface(
4584 routing_id(), window, width, height, io_surface_identifier));
4585}
4586
[email protected]1aef98132010-02-23 18:00:074587void RenderView::GPUPluginSetTransportDIB(gfx::PluginWindowHandle window,
4588 int32 width,
4589 int32 height,
4590 TransportDIB::Handle transport_dib) {
4591 Send(new ViewHostMsg_GPUPluginSetTransportDIB(
4592 routing_id(), window, width, height, transport_dib));
4593}
4594
4595TransportDIB::Handle RenderView::GPUPluginAllocTransportDIB(size_t size) {
4596 TransportDIB::Handle dib_handle;
4597 // Assume this is a synchronous RPC.
4598 if (Send(new ViewHostMsg_AllocTransportDIB(size, &dib_handle)))
4599 return dib_handle;
4600 // Return an invalid handle if Send() fails.
4601 return TransportDIB::DefaultHandleValue();
4602}
4603
4604void RenderView::GPUPluginFreeTransportDIB(TransportDIB::Id dib_id) {
4605 Send(new ViewHostMsg_FreeTransportDIB(dib_id));
4606}
4607
[email protected]43f28f832010-02-03 02:28:484608void RenderView::GPUPluginBuffersSwapped(gfx::PluginWindowHandle window) {
4609 Send(new ViewHostMsg_GPUPluginBuffersSwapped(routing_id(), window));
4610}
4611#endif
[email protected]58c321d2010-02-19 12:11:284612
4613WebKit::WebGeolocationServiceInterface* RenderView::getGeolocationService() {
4614 if (!geolocation_dispatcher_.get())
4615 geolocation_dispatcher_.reset(new GeolocationDispatcher(this));
4616 return geolocation_dispatcher_.get();
4617}