blob: 818cbd0f558fe905637c51ee74e2d70acf5b6c37 [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]a92b8642009-05-05 23:38:5613#include "app/l10n_util.h"
[email protected]37126212009-05-06 02:23:3114#include "app/message_box_flags.h"
[email protected]9929da92009-05-05 02:05:1115#include "app/resource_bundle.h"
[email protected]2041cf342010-02-19 03:15:5916#include "base/callback.h"
initial.commit09911bf2008-07-26 23:55:2917#include "base/command_line.h"
[email protected]bb063b72009-03-27 23:18:5018#include "base/compiler_specific.h"
[email protected]4646f292009-05-20 03:49:0519#include "base/field_trial.h"
[email protected]30507922010-01-15 16:48:2320#include "base/histogram.h"
[email protected]8380c092009-06-25 17:45:5121#include "base/process_util.h"
[email protected]7b291f92009-08-14 05:43:5322#include "base/singleton.h"
initial.commit09911bf2008-07-26 23:55:2923#include "base/string_piece.h"
24#include "base/string_util.h"
[email protected]30507922010-01-15 16:48:2325#include "base/time.h"
[email protected]6c8afae52009-01-22 02:24:5726#include "build/build_config.h"
[email protected]81e63782009-02-27 19:35:0927#include "chrome/common/bindings_policy.h"
[email protected]ef916272009-07-08 21:40:5528#include "chrome/common/child_process_logging.h"
initial.commit09911bf2008-07-26 23:55:2929#include "chrome/common/chrome_switches.h"
[email protected]f0af6a72009-05-30 05:25:1730#include "chrome/common/chrome_constants.h"
[email protected]d146b832009-12-23 02:45:4831#include "chrome/common/extensions/extension_constants.h"
initial.commit09911bf2008-07-26 23:55:2932#include "chrome/common/jstemplate_builder.h"
[email protected]630e26b2008-10-14 22:55:1733#include "chrome/common/page_zoom.h"
[email protected]e09ba552009-02-05 03:26:2934#include "chrome/common/render_messages.h"
[email protected]9b6f40e2009-06-11 15:54:2635#include "chrome/common/renderer_preferences.h"
initial.commit09911bf2008-07-26 23:55:2936#include "chrome/common/thumbnail_score.h"
[email protected]6de74452009-02-25 18:04:5937#include "chrome/common/url_constants.h"
initial.commit09911bf2008-07-26 23:55:2938#include "chrome/renderer/about_handler.h"
[email protected]5fb88962009-04-16 19:03:2539#include "chrome/renderer/audio_message_filter.h"
[email protected]e4ac5df2009-03-17 15:33:1140#include "chrome/renderer/devtools_agent.h"
41#include "chrome/renderer/devtools_client.h"
[email protected]912256b32009-09-18 09:47:3542#include "chrome/renderer/extension_groups.h"
[email protected]f816c012009-06-26 21:48:3243#include "chrome/renderer/extensions/event_bindings.h"
[email protected]0f6053962009-07-09 19:26:3544#include "chrome/renderer/extensions/extension_process_bindings.h"
[email protected]7120f132009-07-20 21:05:3745#include "chrome/renderer/extensions/renderer_extension_bindings.h"
[email protected]58c321d2010-02-19 12:11:2846#include "chrome/renderer/geolocation_dispatcher.h"
initial.commit09911bf2008-07-26 23:55:2947#include "chrome/renderer/localized_error.h"
[email protected]6f56d482009-02-20 05:02:5648#include "chrome/renderer/media/audio_renderer_impl.h"
[email protected]8400e032010-02-26 18:50:1149#include "chrome/renderer/media/ipc_video_renderer.h"
[email protected]ed3fb032009-06-16 19:50:5650#include "chrome/renderer/navigation_state.h"
[email protected]90e908552009-10-05 01:40:1251#include "chrome/renderer/notification_provider.h"
[email protected]8beff0762009-09-29 02:18:3052#include "chrome/renderer/plugin_channel_host.h"
[email protected]d81c1e52009-06-03 22:09:5053#include "chrome/renderer/print_web_view_helper.h"
[email protected]39008c02009-02-11 23:59:2554#include "chrome/renderer/render_process.h"
[email protected]00c39612010-03-06 02:53:2855#include "chrome/renderer/render_thread.h"
[email protected]bd92c3a2010-01-13 05:02:3456#include "chrome/renderer/renderer_webstoragenamespace_impl.h"
[email protected]85c55dc2009-11-06 03:05:4657#include "chrome/renderer/spellchecker/spellcheck.h"
[email protected]0938d3c2009-01-09 20:37:3558#include "chrome/renderer/user_script_slave.h"
initial.commit09911bf2008-07-26 23:55:2959#include "chrome/renderer/visitedlink_slave.h"
[email protected]d439ba072009-10-17 22:32:2960#include "chrome/renderer/webplugin_delegate_pepper.h"
[email protected]ba4b17f2009-02-11 21:32:2961#include "chrome/renderer/webplugin_delegate_proxy.h"
[email protected]9c00f002009-11-05 22:37:4262#include "chrome/renderer/websharedworker_proxy.h"
[email protected]eb47a132009-03-04 00:39:5663#include "chrome/renderer/webworker_proxy.h"
[email protected]5c7293a2010-03-17 06:40:5764#include "gfx/native_widget_types.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]c27ae592010-03-18 15:24:4185#include "third_party/WebKit/WebKit/chromium/public/WebImage.h"
[email protected]95056b582010-02-18 01:29:2486#include "third_party/WebKit/WebKit/chromium/public/WebInputElement.h"
[email protected]418ed5ab2009-11-12 01:14:4987#include "third_party/WebKit/WebKit/chromium/public/WebNode.h"
[email protected]0bedb8a2010-01-14 19:36:3288#include "third_party/WebKit/WebKit/chromium/public/WebNodeList.h"
[email protected]d9ec5c0f2009-12-23 11:55:0789#include "third_party/WebKit/WebKit/chromium/public/WebPageSerializer.h"
[email protected]418ed5ab2009-11-12 01:14:4990#include "third_party/WebKit/WebKit/chromium/public/WebPoint.h"
91#include "third_party/WebKit/WebKit/chromium/public/WebRange.h"
92#include "third_party/WebKit/WebKit/chromium/public/WebRect.h"
93#include "third_party/WebKit/WebKit/chromium/public/WebScriptSource.h"
94#include "third_party/WebKit/WebKit/chromium/public/WebSearchableFormData.h"
95#include "third_party/WebKit/WebKit/chromium/public/WebSecurityOrigin.h"
96#include "third_party/WebKit/WebKit/chromium/public/WebSize.h"
[email protected]bd92c3a2010-01-13 05:02:3497#include "third_party/WebKit/WebKit/chromium/public/WebStorageNamespace.h"
[email protected]418ed5ab2009-11-12 01:14:4998#include "third_party/WebKit/WebKit/chromium/public/WebString.h"
99#include "third_party/WebKit/WebKit/chromium/public/WebURL.h"
100#include "third_party/WebKit/WebKit/chromium/public/WebURLError.h"
101#include "third_party/WebKit/WebKit/chromium/public/WebURLRequest.h"
102#include "third_party/WebKit/WebKit/chromium/public/WebURLResponse.h"
103#include "third_party/WebKit/WebKit/chromium/public/WebVector.h"
[email protected]80f584d92010-01-21 03:59:04104#include "webkit/appcache/web_application_cache_host_impl.h"
[email protected]ba4b17f2009-02-11 21:32:29105#include "webkit/default_plugin/default_plugin_shared.h"
initial.commit09911bf2008-07-26 23:55:29106#include "webkit/glue/dom_operations.h"
[email protected]95056b582010-02-18 01:29:24107#include "webkit/glue/form_field.h"
108#include "webkit/glue/form_field_values.h"
109#include "webkit/glue/glue_serialize.h"
[email protected]f11ca0732009-04-11 00:09:34110#include "webkit/glue/image_decoder.h"
[email protected]8e296bbd2009-07-22 21:37:17111#include "webkit/glue/media/buffered_data_source.h"
[email protected]8380c092009-06-25 17:45:51112#include "webkit/glue/media/simple_data_source.h"
initial.commit09911bf2008-07-26 23:55:29113#include "webkit/glue/password_form.h"
[email protected]ba4b17f2009-02-11 21:32:29114#include "webkit/glue/plugins/plugin_list.h"
[email protected]8a3b7962009-09-04 05:53:23115#include "webkit/glue/plugins/webplugin_delegate_impl.h"
[email protected]8400e032010-02-26 18:50:11116#include "webkit/glue/media/video_renderer_impl.h"
initial.commit09911bf2008-07-26 23:55:29117#include "webkit/glue/webdropdata.h"
initial.commit09911bf2008-07-26 23:55:29118#include "webkit/glue/webkit_glue.h"
[email protected]add51772009-06-11 18:25:17119#include "webkit/glue/webmediaplayer_impl.h"
[email protected]f103ab72009-09-02 17:10:59120#include "webkit/glue/webplugin_impl.h"
initial.commit09911bf2008-07-26 23:55:29121
[email protected]6c8afae52009-01-22 02:24:57122#if defined(OS_WIN)
123// TODO(port): these files are currently Windows only because they concern:
[email protected]6c8afae52009-01-22 02:24:57124// * theming
[email protected]86281ad2009-10-07 20:07:17125#include "app/gfx/native_theme_win.h"
[email protected]6981f7f2010-03-09 00:53:03126#elif defined(USE_X11)
[email protected]39cd64ed2010-02-05 02:18:46127#include "third_party/WebKit/WebKit/chromium/public/linux/WebRenderTheme.h"
[email protected]6c8afae52009-01-22 02:24:57128#endif
129
[email protected]80f584d92010-01-21 03:59:04130using appcache::WebApplicationCacheHostImpl;
[email protected]c20210e62009-04-03 21:39:26131using base::Time;
[email protected]e1acf6f2008-10-27 20:43:33132using base::TimeDelta;
[email protected]15d79e12009-08-02 19:23:45133using webkit_glue::AltErrorPageResourceFetcher;
[email protected]95056b582010-02-18 01:29:24134using webkit_glue::FormField;
[email protected]51bd36612009-10-20 22:49:47135using webkit_glue::FormFieldValues;
[email protected]b0950a72009-09-29 23:16:17136using webkit_glue::ImageResourceFetcher;
[email protected]ed3fb032009-06-16 19:50:56137using webkit_glue::PasswordForm;
[email protected]daa8c58e2009-06-15 17:21:10138using webkit_glue::PasswordFormDomManager;
[email protected]c7287a92009-11-04 20:06:15139using WebKit::WebAccessibilityCache;
[email protected]cc0445f2009-10-13 16:09:08140using WebKit::WebAccessibilityObject;
[email protected]1c83eb42009-09-11 21:08:41141using WebKit::WebColor;
142using WebKit::WebColorName;
[email protected]0dea3ea2009-03-31 23:30:59143using WebKit::WebConsoleMessage;
[email protected]79e37442009-10-09 18:17:44144using WebKit::WebContextMenuData;
[email protected]b921cfd22010-02-25 16:57:51145using WebKit::WebCookieJar;
[email protected]d9ec5c0f2009-12-23 11:55:07146using WebKit::WebCString;
[email protected]e6f546c32009-07-01 17:12:55147using WebKit::WebData;
[email protected]726985e22009-06-18 21:09:28148using WebKit::WebDataSource;
[email protected]2661b332009-11-03 18:42:29149using WebKit::WebDevToolsAgent;
[email protected]5bc8fe92010-03-11 18:19:00150using WebKit::WebDocument;
[email protected]e80c73b2009-04-07 23:24:58151using WebKit::WebDragData;
[email protected]1d9f4132009-09-08 17:29:25152using WebKit::WebDragOperation;
153using WebKit::WebDragOperationsMask;
[email protected]79dbc662009-09-04 05:42:51154using WebKit::WebEditingAction;
[email protected]6069da8c2009-10-20 20:33:49155using WebKit::WebFindOptions;
[email protected]979c28b2009-11-07 01:30:48156using WebKit::WebFormElement;
[email protected]dd7daa82009-08-10 05:46:45157using WebKit::WebFrame;
[email protected]ca948a22009-06-25 19:36:17158using WebKit::WebHistoryItem;
[email protected]c27ae592010-03-18 15:24:41159using WebKit::WebImage;
[email protected]95056b582010-02-18 01:29:24160using WebKit::WebInputElement;
[email protected]3d9689372009-09-10 04:29:17161using WebKit::WebMediaPlayer;
[email protected]952cb702009-10-07 05:50:28162using WebKit::WebMediaPlayerAction;
[email protected]3d9689372009-09-10 04:29:17163using WebKit::WebMediaPlayerClient;
[email protected]4873c7d2009-07-16 06:36:28164using WebKit::WebNavigationPolicy;
[email protected]726985e22009-06-18 21:09:28165using WebKit::WebNavigationType;
[email protected]79dbc662009-09-04 05:42:51166using WebKit::WebNode;
[email protected]d9ec5c0f2009-12-23 11:55:07167using WebKit::WebPageSerializer;
168using WebKit::WebPageSerializerClient;
[email protected]3d9689372009-09-10 04:29:17169using WebKit::WebPlugin;
170using WebKit::WebPluginParams;
[email protected]48c9cf2d2009-09-16 16:47:52171using WebKit::WebPoint;
[email protected]88efb7ec2009-07-14 16:32:59172using WebKit::WebPopupMenuInfo;
[email protected]79dbc662009-09-04 05:42:51173using WebKit::WebRange;
[email protected]b3f2b912009-04-09 16:18:52174using WebKit::WebRect;
[email protected]4f999132009-03-31 18:08:40175using WebKit::WebScriptSource;
[email protected]ce0e250d2009-10-23 21:00:35176using WebKit::WebSearchableFormData;
[email protected]e3d60e5d2009-09-25 21:08:29177using WebKit::WebSecurityOrigin;
[email protected]2fab253a2009-08-17 23:00:59178using WebKit::WebSettings;
[email protected]9c00f002009-11-05 22:37:42179using WebKit::WebSharedWorker;
[email protected]8649fb32009-06-26 17:51:02180using WebKit::WebSize;
[email protected]bd92c3a2010-01-13 05:02:34181using WebKit::WebStorageNamespace;
[email protected]726985e22009-06-18 21:09:28182using WebKit::WebString;
[email protected]79dbc662009-09-04 05:42:51183using WebKit::WebTextAffinity;
[email protected]de570ef2009-07-29 18:27:52184using WebKit::WebTextDirection;
[email protected]726985e22009-06-18 21:09:28185using WebKit::WebURL;
186using WebKit::WebURLError;
187using WebKit::WebURLRequest;
188using WebKit::WebURLResponse;
[email protected]4873c7d2009-07-16 06:36:28189using WebKit::WebVector;
[email protected]50ae00ef2009-10-19 05:11:03190using WebKit::WebView;
[email protected]4873c7d2009-07-16 06:36:28191using WebKit::WebWidget;
[email protected]27ba8532009-04-24 20:22:43192using WebKit::WebWorker;
193using WebKit::WebWorkerClient;
[email protected]e1acf6f2008-10-27 20:43:33194
initial.commit09911bf2008-07-26 23:55:29195//-----------------------------------------------------------------------------
196
197// define to write the time necessary for thumbnail/DOM text retrieval,
198// respectively, into the system debug log
initial.commit09911bf2008-07-26 23:55:29199// #define TIME_TEXT_RETRIEVAL
200
201// maximum number of characters in the document to index, any text beyond this
202// point will be clipped
[email protected]6c8afae52009-01-22 02:24:57203static const size_t kMaxIndexChars = 65535;
initial.commit09911bf2008-07-26 23:55:29204
205// Size of the thumbnails that we'll generate
[email protected]8b4f4892009-09-04 21:52:37206static const int kThumbnailWidth = 212;
207static const int kThumbnailHeight = 132;
initial.commit09911bf2008-07-26 23:55:29208
209// Delay in milliseconds that we'll wait before capturing the page contents
210// and thumbnail.
211static const int kDelayForCaptureMs = 500;
212
213// Typically, we capture the page data once the page is loaded.
214// Sometimes, the page never finishes to load, preventing the page capture
215// To workaround this problem, we always perform a capture after the following
216// delay.
217static const int kDelayForForcedCaptureMs = 6000;
218
[email protected]882daa92009-11-05 16:31:31219// Time, in seconds, we delay before sending content state changes (such as form
220// state and scroll position) to the browser. We delay sending changes to avoid
221// spamming the browser.
222// To avoid having tab/session restore require sending a message to get the
223// current content state during tab closing we use a shorter timeout for the
224// foreground renderer. This means there is a small window of time from which
225// content state is modified and not sent to session restore, but this is
226// better than having to wake up all renderers during shutdown.
227static const int kDelaySecondsForContentStateSyncHidden = 5;
228static const int kDelaySecondsForContentStateSync = 1;
initial.commit09911bf2008-07-26 23:55:29229
[email protected]0aa55312008-10-17 21:53:08230// The maximum number of popups that can be spawned from one page.
231static const int kMaximumNumberOfUnacknowledgedPopups = 25;
232
initial.commit09911bf2008-07-26 23:55:29233static const char* const kUnreachableWebDataURL =
[email protected]60e448982009-05-06 04:21:16234 "chrome://chromewebdata/";
initial.commit09911bf2008-07-26 23:55:29235
[email protected]50b691c2008-10-31 19:08:35236static const char* const kBackForwardNavigationScheme = "history";
237
[email protected]8c4cdd42010-01-12 21:31:13238// The string returned in DetectLanguage if we failed to detect the language.
[email protected]8dc5a2052010-01-19 21:32:42239static const char* const kUnknownLanguageCode = "und";
[email protected]8c4cdd42010-01-12 21:31:13240
[email protected]726985e22009-06-18 21:09:28241static void GetRedirectChain(WebDataSource* ds, std::vector<GURL>* result) {
242 WebVector<WebURL> urls;
243 ds->redirectChain(urls);
244 result->reserve(urls.size());
245 for (size_t i = 0; i < urls.size(); ++i)
246 result->push_back(urls[i]);
247}
248
[email protected]61f5a7b2009-12-22 22:21:20249static bool UrlMatchesPermissions(
250 const GURL& url, const std::vector<URLPattern>& host_permissions) {
251 for (size_t i = 0; i < host_permissions.size(); ++i) {
252 if (host_permissions[i].MatchesUrl(url))
253 return true;
254 }
255
256 return false;
257}
258
[email protected]30507922010-01-15 16:48:23259static bool PaintViewIntoCanvas(WebView* view,
260 skia::PlatformCanvas& canvas) {
261 view->layout();
262 const WebSize& size = view->size();
263
264 if (!canvas.initialize(size.width, size.height, true))
265 return false;
266
267 view->paint(webkit_glue::ToWebCanvas(&canvas),
268 WebRect(0, 0, size.width, size.height));
269 // TODO: Add a way to snapshot the whole page, not just the currently
270 // visible part.
271
272 return true;
273}
274
275// Calculates how "boring" a thumbnail is. The boring score is the
276// 0,1 ranged percentage of pixels that are the most common
277// luma. Higher boring scores indicate that a higher percentage of a
278// bitmap are all the same brightness.
279static double CalculateBoringScore(SkBitmap* bitmap) {
280 int histogram[256] = {0};
281 color_utils::BuildLumaHistogram(bitmap, histogram);
282
283 int color_count = *std::max_element(histogram, histogram + 256);
284 int pixel_count = bitmap->width() * bitmap->height();
285 return static_cast<double>(color_count) / pixel_count;
286}
287
initial.commit09911bf2008-07-26 23:55:29288///////////////////////////////////////////////////////////////////////////////
289
[email protected]60c42a8c72009-10-09 04:08:59290int32 RenderView::next_page_id_ = 1;
291
[email protected]2fab253a2009-08-17 23:00:59292RenderView::RenderView(RenderThreadBase* render_thread,
[email protected]4e6419c2010-01-15 04:50:34293 const WebPreferences& webkit_preferences,
294 int64 session_storage_namespace_id)
[email protected]81a34412009-01-05 19:17:24295 : RenderWidget(render_thread, true),
[email protected]81e63782009-02-27 19:35:09296 enabled_bindings_(0),
[email protected]e75cb49e2009-01-05 23:13:21297 target_url_status_(TARGET_NONE),
[email protected]81a34412009-01-05 19:17:24298 is_loading_(false),
[email protected]e75cb49e2009-01-05 23:13:21299 navigation_gesture_(NavigationGestureUnknown),
[email protected]81a34412009-01-05 19:17:24300 page_id_(-1),
301 last_page_id_sent_to_browser_(-1),
302 last_indexed_page_id_(-1),
[email protected]81a34412009-01-05 19:17:24303 opened_by_user_gesture_(true),
[email protected]007a848b2009-10-26 15:55:46304 opener_suppressed_(false),
[email protected]bb063b72009-03-27 23:18:50305 ALLOW_THIS_IN_INITIALIZER_LIST(method_factory_(this)),
[email protected]e4ac5df2009-03-17 15:33:11306 devtools_agent_(NULL),
307 devtools_client_(NULL),
[email protected]a1128322009-10-06 18:38:46308 file_chooser_completion_(NULL),
[email protected]81a34412009-01-05 19:17:24309 history_back_list_count_(0),
310 history_forward_list_count_(0),
[email protected]81a34412009-01-05 19:17:24311 has_unload_listener_(false),
312 decrement_shared_popup_at_destruction_(false),
[email protected]acca2a12009-10-16 03:53:39313 autofill_query_id_(0),
[email protected]81a34412009-01-05 19:17:24314 popup_notification_visible_(false),
[email protected]8922e1f2009-10-03 05:01:26315 spelling_panel_visible_(false),
[email protected]882daa92009-11-05 16:31:31316 send_content_state_immediately_(false),
[email protected]ab32b16c2009-10-16 14:57:25317 send_preferred_size_changes_(false),
[email protected]b6849bda2009-10-14 23:59:26318 ALLOW_THIS_IN_INITIALIZER_LIST(
319 notification_provider_(new NotificationProvider(this))),
[email protected]7b291f92009-08-14 05:43:53320 view_type_(ViewType::INVALID),
321 browser_window_id_(-1),
[email protected]83dde542009-09-11 20:59:55322 last_top_level_navigation_page_id_(-1),
323#if defined(OS_MACOSX)
324 has_document_tag_(false),
325#endif
[email protected]98324892009-09-09 21:16:05326 document_tag_(0),
[email protected]0bedb8a2010-01-14 19:36:32327 webkit_preferences_(webkit_preferences),
[email protected]4e6419c2010-01-15 04:50:34328 session_storage_namespace_id_(session_storage_namespace_id),
[email protected]b921cfd22010-02-25 16:57:51329 ALLOW_THIS_IN_INITIALIZER_LIST(text_translator_(this)),
[email protected]ab9eabac2010-03-16 16:54:10330 ALLOW_THIS_IN_INITIALIZER_LIST(cookie_jar_(this)),
331 cross_origin_access_count_(0),
332 same_origin_access_count_(0) {
[email protected]71b0d5d2010-02-15 05:43:07333 ClearBlockedContentSettings();
[email protected]7e0831b2010-02-01 08:45:15334 page_translator_.reset(new PageTranslator(&text_translator_, this));
initial.commit09911bf2008-07-26 23:55:29335}
336
337RenderView::~RenderView() {
[email protected]0aa55312008-10-17 21:53:08338 if (decrement_shared_popup_at_destruction_)
339 shared_popup_counter_->data--;
340
[email protected]b0950a72009-09-29 23:16:17341 // Dispose of un-disposed image fetchers.
342 for (ImageResourceFetcherSet::iterator i = image_fetchers_.begin();
343 i != image_fetchers_.end(); ++i) {
344 delete *i;
345 }
346
[email protected]a1128322009-10-06 18:38:46347 // If file chooser is still waiting for answer, dispatch empty answer.
348 if (file_chooser_completion_)
349 file_chooser_completion_->didChooseFile(WebVector<WebString>());
350
[email protected]83dde542009-09-11 20:59:55351#if defined(OS_MACOSX)
[email protected]98324892009-09-09 21:16:05352 // Tell the spellchecker that the document is closed.
[email protected]83dde542009-09-11 20:59:55353 if (has_document_tag_)
354 Send(new ViewHostMsg_DocumentWithTagClosed(routing_id_, document_tag_));
355#endif
[email protected]98324892009-09-09 21:16:05356
[email protected]5fb88962009-04-16 19:03:25357 render_thread_->RemoveFilter(audio_message_filter_);
[email protected]60c42a8c72009-10-09 04:08:59358
359#ifndef NDEBUG
360 // Make sure we are no longer referenced by the ViewMap.
361 ViewMap* views = Singleton<ViewMap>::get();
362 for (ViewMap::iterator it = views->begin(); it != views->end(); ++it)
363 DCHECK_NE(this, it->second) << "Failed to call Close?";
364#endif
365}
366
367/*static*/
368void RenderView::ForEach(RenderViewVisitor* visitor) {
369 ViewMap* views = Singleton<ViewMap>::get();
370 for (ViewMap::iterator it = views->begin(); it != views->end(); ++it) {
371 if (!visitor->Visit(it->second))
372 return;
373 }
374}
375
376/*static*/
377RenderView* RenderView::FromWebView(WebView* webview) {
378 ViewMap* views = Singleton<ViewMap>::get();
379 ViewMap::iterator it = views->find(webview);
380 return it == views->end() ? NULL : it->second;
initial.commit09911bf2008-07-26 23:55:29381}
382
383/*static*/
[email protected]0aa55312008-10-17 21:53:08384RenderView* RenderView::Create(
[email protected]81a34412009-01-05 19:17:24385 RenderThreadBase* render_thread,
[email protected]18bcc3c2009-01-27 21:39:15386 gfx::NativeViewId parent_hwnd,
[email protected]0aa55312008-10-17 21:53:08387 int32 opener_id,
[email protected]80d96fa2009-06-10 22:34:51388 const RendererPreferences& renderer_prefs,
[email protected]0aa55312008-10-17 21:53:08389 const WebPreferences& webkit_prefs,
390 SharedRenderViewCounter* counter,
[email protected]4e6419c2010-01-15 04:50:34391 int32 routing_id,
392 int64 session_storage_namespace_id) {
initial.commit09911bf2008-07-26 23:55:29393 DCHECK(routing_id != MSG_ROUTING_NONE);
[email protected]4e6419c2010-01-15 04:50:34394 scoped_refptr<RenderView> view = new RenderView(render_thread, webkit_prefs,
395 session_storage_namespace_id);
initial.commit09911bf2008-07-26 23:55:29396 view->Init(parent_hwnd,
initial.commit09911bf2008-07-26 23:55:29397 opener_id,
[email protected]80d96fa2009-06-10 22:34:51398 renderer_prefs,
[email protected]0aa55312008-10-17 21:53:08399 counter,
initial.commit09911bf2008-07-26 23:55:29400 routing_id); // adds reference
401 return view;
402}
403
404/*static*/
405void RenderView::SetNextPageID(int32 next_page_id) {
406 // This method should only be called during process startup, and the given
407 // page id had better not exceed our current next page id!
[email protected]4646f292009-05-20 03:49:05408 DCHECK_EQ(next_page_id_, 1);
initial.commit09911bf2008-07-26 23:55:29409 DCHECK(next_page_id >= next_page_id_);
410 next_page_id_ = next_page_id;
411}
412
[email protected]afe3a1672009-11-17 19:04:12413void RenderView::UserMetricsRecordAction(const std::string& action) {
[email protected]1dbafaf72009-09-23 19:43:56414 Send(new ViewHostMsg_UserMetricsRecordAction(routing_id_, action));
415}
416
[email protected]a3a8fb6d2009-10-22 20:12:51417void RenderView::PluginCrashed(const FilePath& plugin_path) {
418 Send(new ViewHostMsg_CrashedPlugin(routing_id_, plugin_path));
initial.commit09911bf2008-07-26 23:55:29419}
420
[email protected]d8fd6fa2010-02-01 15:54:26421#if defined(OS_MACOSX)
422void RenderView::RegisterPluginDelegate(WebPluginDelegateProxy* delegate) {
423 plugin_delegates_.insert(delegate);
424}
425
426void RenderView::UnregisterPluginDelegate(WebPluginDelegateProxy* delegate) {
427 plugin_delegates_.erase(delegate);
428}
429#endif
430
[email protected]18bcc3c2009-01-27 21:39:15431void RenderView::Init(gfx::NativeViewId parent_hwnd,
initial.commit09911bf2008-07-26 23:55:29432 int32 opener_id,
[email protected]80d96fa2009-06-10 22:34:51433 const RendererPreferences& renderer_prefs,
[email protected]0aa55312008-10-17 21:53:08434 SharedRenderViewCounter* counter,
initial.commit09911bf2008-07-26 23:55:29435 int32 routing_id) {
436 DCHECK(!webview());
437
438 if (opener_id != MSG_ROUTING_NONE)
439 opener_id_ = opener_id;
440
[email protected]0aa55312008-10-17 21:53:08441 if (counter) {
442 shared_popup_counter_ = counter;
443 shared_popup_counter_->data++;
444 decrement_shared_popup_at_destruction_ = true;
445 } else {
446 shared_popup_counter_ = new SharedRenderViewCounter(0);
447 decrement_shared_popup_at_destruction_ = false;
448 }
449
[email protected]58bfc6b2009-06-24 09:45:02450 devtools_agent_.reset(new DevToolsAgent(routing_id, this));
[email protected]9b9d7282009-04-08 14:13:04451
[email protected]50ae00ef2009-10-19 05:11:03452 webwidget_ = WebView::create(this);
[email protected]60c42a8c72009-10-09 04:08:59453 Singleton<ViewMap>::get()->insert(std::make_pair(webview(), this));
[email protected]2fab253a2009-08-17 23:00:59454 webkit_preferences_.Apply(webview());
[email protected]b4bb2502009-10-01 22:35:27455 webview()->initializeMainFrame(this);
[email protected]2661b332009-11-03 18:42:29456 webview()->setDevToolsAgent(
457 WebDevToolsAgent::create(webview(), devtools_agent_.get()));
initial.commit09911bf2008-07-26 23:55:29458
[email protected]d3ba77272009-09-03 00:06:09459 OnSetRendererPrefs(renderer_prefs);
460
initial.commit09911bf2008-07-26 23:55:29461 routing_id_ = routing_id;
[email protected]81a34412009-01-05 19:17:24462 render_thread_->AddRoute(routing_id_, this);
initial.commit09911bf2008-07-26 23:55:29463 // Take a reference on behalf of the RenderThread. This will be balanced
464 // when we receive ViewMsg_Close.
465 AddRef();
466
467 // If this is a popup, we must wait for the CreatingNew_ACK message before
468 // completing initialization. Otherwise, we can finish it now.
469 if (opener_id == MSG_ROUTING_NONE) {
470 did_show_ = true;
471 CompleteInit(parent_hwnd);
472 }
473
474 host_window_ = parent_hwnd;
initial.commit09911bf2008-07-26 23:55:29475
[email protected]58bfc6b2009-06-24 09:45:02476 const CommandLine& command_line = *CommandLine::ForCurrentProcess();
[email protected]81e63782009-02-27 19:35:09477 if (command_line.HasSwitch(switches::kDomAutomationController))
478 enabled_bindings_ |= BindingsPolicy::DOM_AUTOMATION;
initial.commit09911bf2008-07-26 23:55:29479
[email protected]5fb88962009-04-16 19:03:25480 audio_message_filter_ = new AudioMessageFilter(routing_id_);
481 render_thread_->AddFilter(audio_message_filter_);
initial.commit09911bf2008-07-26 23:55:29482}
483
484void RenderView::OnMessageReceived(const IPC::Message& message) {
[email protected]26aa0482009-09-30 16:55:27485 WebFrame* main_frame = webview() ? webview()->mainFrame() : NULL;
[email protected]a9f607e2009-10-23 19:59:27486 if (main_frame)
487 child_process_logging::SetActiveURL(main_frame->url());
[email protected]f8b6b6f2009-03-10 16:48:26488
[email protected]b2abac72009-02-26 12:39:28489 // If this is developer tools renderer intercept tools messages first.
[email protected]e4ac5df2009-03-17 15:33:11490 if (devtools_client_.get() && devtools_client_->OnMessageReceived(message))
[email protected]b2abac72009-02-26 12:39:28491 return;
[email protected]b4b967e2009-04-22 11:33:05492 if (devtools_agent_.get() && devtools_agent_->OnMessageReceived(message))
493 return;
[email protected]b6849bda2009-10-14 23:59:26494 if (notification_provider_->OnMessageReceived(message))
495 return;
[email protected]58c321d2010-02-19 12:11:28496 if (geolocation_dispatcher_.get() &&
497 geolocation_dispatcher_->OnMessageReceived(message)) {
498 return;
499 }
[email protected]b2abac72009-02-26 12:39:28500
initial.commit09911bf2008-07-26 23:55:29501 IPC_BEGIN_MESSAGE_MAP(RenderView, message)
initial.commit09911bf2008-07-26 23:55:29502 IPC_MESSAGE_HANDLER(ViewMsg_CaptureThumbnail, SendThumbnail)
[email protected]30507922010-01-15 16:48:23503 IPC_MESSAGE_HANDLER(ViewMsg_CaptureSnapshot, SendSnapshot)
initial.commit09911bf2008-07-26 23:55:29504 IPC_MESSAGE_HANDLER(ViewMsg_PrintPages, OnPrintPages)
[email protected]82270452009-06-19 15:58:01505 IPC_MESSAGE_HANDLER(ViewMsg_PrintingDone, OnPrintingDone)
initial.commit09911bf2008-07-26 23:55:29506 IPC_MESSAGE_HANDLER(ViewMsg_Navigate, OnNavigate)
507 IPC_MESSAGE_HANDLER(ViewMsg_Stop, OnStop)
[email protected]1dda4022010-01-28 18:24:56508 IPC_MESSAGE_HANDLER(ViewMsg_ReloadFrame, OnReloadFrame)
initial.commit09911bf2008-07-26 23:55:29509 IPC_MESSAGE_HANDLER(ViewMsg_LoadAlternateHTMLText, OnLoadAlternateHTMLText)
510 IPC_MESSAGE_HANDLER(ViewMsg_StopFinding, OnStopFinding)
511 IPC_MESSAGE_HANDLER(ViewMsg_Undo, OnUndo)
512 IPC_MESSAGE_HANDLER(ViewMsg_Redo, OnRedo)
513 IPC_MESSAGE_HANDLER(ViewMsg_Cut, OnCut)
514 IPC_MESSAGE_HANDLER(ViewMsg_Copy, OnCopy)
[email protected]c0cc3092009-09-12 08:27:27515#if defined(OS_MACOSX)
[email protected]a954bf72009-09-12 07:30:35516 IPC_MESSAGE_HANDLER(ViewMsg_CopyToFindPboard, OnCopyToFindPboard)
[email protected]c0cc3092009-09-12 08:27:27517#endif
initial.commit09911bf2008-07-26 23:55:29518 IPC_MESSAGE_HANDLER(ViewMsg_Paste, OnPaste)
519 IPC_MESSAGE_HANDLER(ViewMsg_Replace, OnReplace)
[email protected]98324892009-09-09 21:16:05520 IPC_MESSAGE_HANDLER(ViewMsg_ToggleSpellPanel, OnToggleSpellPanel)
521 IPC_MESSAGE_HANDLER(ViewMsg_AdvanceToNextMisspelling,
522 OnAdvanceToNextMisspelling)
[email protected]bbbd545c2008-12-15 20:18:04523 IPC_MESSAGE_HANDLER(ViewMsg_ToggleSpellCheck, OnToggleSpellCheck)
initial.commit09911bf2008-07-26 23:55:29524 IPC_MESSAGE_HANDLER(ViewMsg_Delete, OnDelete)
525 IPC_MESSAGE_HANDLER(ViewMsg_SelectAll, OnSelectAll)
526 IPC_MESSAGE_HANDLER(ViewMsg_CopyImageAt, OnCopyImageAt)
[email protected]4b59ae602009-06-23 20:58:15527 IPC_MESSAGE_HANDLER(ViewMsg_ExecuteEditCommand, OnExecuteEditCommand)
initial.commit09911bf2008-07-26 23:55:29528 IPC_MESSAGE_HANDLER(ViewMsg_Find, OnFind)
[email protected]630e26b2008-10-14 22:55:17529 IPC_MESSAGE_HANDLER(ViewMsg_Zoom, OnZoom)
[email protected]f85f0702010-01-30 09:31:01530 IPC_MESSAGE_HANDLER(ViewMsg_SetContentSettingsForLoadingHost,
531 OnSetContentSettingsForLoadingHost)
[email protected]40bd6582009-12-04 23:49:51532 IPC_MESSAGE_HANDLER(ViewMsg_SetZoomLevelForLoadingHost,
533 OnSetZoomLevelForLoadingHost)
initial.commit09911bf2008-07-26 23:55:29534 IPC_MESSAGE_HANDLER(ViewMsg_SetPageEncoding, OnSetPageEncoding)
[email protected]a697f4c2009-09-14 22:30:18535 IPC_MESSAGE_HANDLER(ViewMsg_ResetPageEncodingToDefault,
536 OnResetPageEncodingToDefault)
[email protected]b2abac72009-02-26 12:39:28537 IPC_MESSAGE_HANDLER(ViewMsg_SetupDevToolsClient, OnSetupDevToolsClient)
[email protected]bf5c2ff392009-07-08 16:24:33538 IPC_MESSAGE_HANDLER(ViewMsg_DownloadFavIcon, OnDownloadFavIcon)
initial.commit09911bf2008-07-26 23:55:29539 IPC_MESSAGE_HANDLER(ViewMsg_ScriptEvalRequest, OnScriptEvalRequest)
[email protected]1810e132009-03-24 23:35:48540 IPC_MESSAGE_HANDLER(ViewMsg_CSSInsertRequest, OnCSSInsertRequest)
initial.commit09911bf2008-07-26 23:55:29541 IPC_MESSAGE_HANDLER(ViewMsg_AddMessageToConsole, OnAddMessageToConsole)
initial.commit09911bf2008-07-26 23:55:29542 IPC_MESSAGE_HANDLER(ViewMsg_ReservePageIDRange, OnReservePageIDRange)
initial.commit09911bf2008-07-26 23:55:29543 IPC_MESSAGE_HANDLER(ViewMsg_FillPasswordForm, OnFillPasswordForm)
544 IPC_MESSAGE_HANDLER(ViewMsg_DragTargetDragEnter, OnDragTargetDragEnter)
545 IPC_MESSAGE_HANDLER(ViewMsg_DragTargetDragOver, OnDragTargetDragOver)
546 IPC_MESSAGE_HANDLER(ViewMsg_DragTargetDragLeave, OnDragTargetDragLeave)
547 IPC_MESSAGE_HANDLER(ViewMsg_DragTargetDrop, OnDragTargetDrop)
[email protected]18cb2572008-08-21 20:34:45548 IPC_MESSAGE_HANDLER(ViewMsg_AllowBindings, OnAllowBindings)
initial.commit09911bf2008-07-26 23:55:29549 IPC_MESSAGE_HANDLER(ViewMsg_SetDOMUIProperty, OnSetDOMUIProperty)
[email protected]266eb6f2008-09-30 23:56:50550 IPC_MESSAGE_HANDLER(ViewMsg_DragSourceEndedOrMoved,
551 OnDragSourceEndedOrMoved)
initial.commit09911bf2008-07-26 23:55:29552 IPC_MESSAGE_HANDLER(ViewMsg_DragSourceSystemDragEnded,
553 OnDragSourceSystemDragEnded)
554 IPC_MESSAGE_HANDLER(ViewMsg_SetInitialFocus, OnSetInitialFocus)
555 IPC_MESSAGE_HANDLER(ViewMsg_FindReplyACK, OnFindReplyAck)
556 IPC_MESSAGE_HANDLER(ViewMsg_UpdateTargetURL_ACK, OnUpdateTargetURLAck)
557 IPC_MESSAGE_HANDLER(ViewMsg_UpdateWebPreferences, OnUpdateWebPreferences)
558 IPC_MESSAGE_HANDLER(ViewMsg_SetAltErrorPageURL, OnSetAltErrorPageURL)
559 IPC_MESSAGE_HANDLER(ViewMsg_InstallMissingPlugin, OnInstallMissingPlugin)
560 IPC_MESSAGE_HANDLER(ViewMsg_RunFileChooserResponse, OnFileChooserResponse)
561 IPC_MESSAGE_HANDLER(ViewMsg_EnableViewSourceMode, OnEnableViewSourceMode)
562 IPC_MESSAGE_HANDLER(ViewMsg_UpdateBackForwardListCount,
563 OnUpdateBackForwardListCount)
564 IPC_MESSAGE_HANDLER(ViewMsg_GetAllSavableResourceLinksForCurrentPage,
565 OnGetAllSavableResourceLinksForCurrentPage)
[email protected]f09c7182009-03-10 12:54:04566 IPC_MESSAGE_HANDLER(
567 ViewMsg_GetSerializedHtmlDataForCurrentPageWithLocalLinks,
568 OnGetSerializedHtmlDataForCurrentPageWithLocalLinks)
initial.commit09911bf2008-07-26 23:55:29569 IPC_MESSAGE_HANDLER(ViewMsg_GetApplicationInfo, OnGetApplicationInfo)
[email protected]266eb6f2008-09-30 23:56:50570 IPC_MESSAGE_HANDLER(ViewMsg_GetAccessibilityInfo, OnGetAccessibilityInfo)
571 IPC_MESSAGE_HANDLER(ViewMsg_ClearAccessibilityInfo,
572 OnClearAccessibilityInfo)
initial.commit09911bf2008-07-26 23:55:29573 IPC_MESSAGE_HANDLER(ViewMsg_ShouldClose, OnMsgShouldClose)
574 IPC_MESSAGE_HANDLER(ViewMsg_ClosePage, OnClosePage)
575 IPC_MESSAGE_HANDLER(ViewMsg_ThemeChanged, OnThemeChanged)
[email protected]18cb2572008-08-21 20:34:45576 IPC_MESSAGE_HANDLER(ViewMsg_HandleMessageFromExternalHost,
577 OnMessageFromExternalHost)
[email protected]0aa55312008-10-17 21:53:08578 IPC_MESSAGE_HANDLER(ViewMsg_DisassociateFromPopupCount,
579 OnDisassociateFromPopupCount)
[email protected]95056b582010-02-18 01:29:24580 IPC_MESSAGE_HANDLER(ViewMsg_AutoFillSuggestionsReturned,
581 OnAutoFillSuggestionsReturned)
582 IPC_MESSAGE_HANDLER(ViewMsg_AutocompleteSuggestionsReturned,
583 OnAutocompleteSuggestionsReturned)
[email protected]c83641732010-02-20 01:04:48584 IPC_MESSAGE_HANDLER(ViewMsg_AutoFillFormDataFilled,
585 OnAutoFillFormDataFilled)
[email protected]2c4410d2009-05-06 23:46:22586 IPC_MESSAGE_HANDLER(ViewMsg_PopupNotificationVisibilityChanged,
587 OnPopupNotificationVisibilityChanged)
[email protected]30f75e62009-02-25 22:01:00588 IPC_MESSAGE_HANDLER(ViewMsg_MoveOrResizeStarted, OnMoveOrResizeStarted)
[email protected]309d7a282009-03-24 09:18:27589 IPC_MESSAGE_HANDLER(ViewMsg_ExtensionResponse, OnExtensionResponse)
[email protected]7120f132009-07-20 21:05:37590 IPC_MESSAGE_HANDLER(ViewMsg_ExtensionMessageInvoke,
591 OnExtensionMessageInvoke)
[email protected]05d478752009-04-08 23:38:16592 IPC_MESSAGE_HANDLER(ViewMsg_ClearFocusedNode, OnClearFocusedNode)
[email protected]699ab0d2009-04-23 23:19:14593 IPC_MESSAGE_HANDLER(ViewMsg_SetBackground, OnSetBackground)
[email protected]ab32b16c2009-10-16 14:57:25594 IPC_MESSAGE_HANDLER(ViewMsg_EnablePreferredSizeChangedMode,
595 OnEnablePreferredSizeChangedMode)
[email protected]cda45c02010-02-25 19:28:10596 IPC_MESSAGE_HANDLER(ViewMsg_DisableScrollbarsForSmallWindows,
597 OnDisableScrollbarsForSmallWindows)
[email protected]80d96fa2009-06-10 22:34:51598 IPC_MESSAGE_HANDLER(ViewMsg_SetRendererPrefs, OnSetRendererPrefs)
[email protected]7b291f92009-08-14 05:43:53599 IPC_MESSAGE_HANDLER(ViewMsg_UpdateBrowserWindowId,
600 OnUpdateBrowserWindowId)
601 IPC_MESSAGE_HANDLER(ViewMsg_NotifyRenderViewType,
602 OnNotifyRendererViewType)
[email protected]581b87eb2009-07-23 23:06:56603 IPC_MESSAGE_HANDLER(ViewMsg_MediaPlayerActionAt, OnMediaPlayerActionAt)
[email protected]8c66c5a2009-07-22 17:26:34604 IPC_MESSAGE_HANDLER(ViewMsg_SetActive, OnSetActive)
[email protected]6ce7abc52010-02-02 18:40:14605#if defined(OS_MACOSX)
606 IPC_MESSAGE_HANDLER(ViewMsg_SetWindowVisibility, OnSetWindowVisibility)
[email protected]1e6e3c992010-02-08 15:52:13607 IPC_MESSAGE_HANDLER(ViewMsg_WindowFrameChanged, OnWindowFrameChanged)
[email protected]6ce7abc52010-02-02 18:40:14608#endif
[email protected]446705872009-09-10 07:22:48609 IPC_MESSAGE_HANDLER(ViewMsg_SetEditCommandsForNextKeyEvent,
[email protected]a0c7153e2009-12-09 14:36:33610 OnSetEditCommandsForNextKeyEvent)
[email protected]912256b32009-09-18 09:47:35611 IPC_MESSAGE_HANDLER(ViewMsg_ExecuteCode,
612 OnExecuteCode)
[email protected]a0c7153e2009-12-09 14:36:33613 IPC_MESSAGE_HANDLER(ViewMsg_CustomContextMenuAction,
614 OnCustomContextMenuAction)
[email protected]d4a00a72010-01-29 01:44:42615 IPC_MESSAGE_HANDLER(ViewMsg_TranslatePage, OnTranslatePage)
[email protected]0bedb8a2010-01-14 19:36:32616 IPC_MESSAGE_HANDLER(ViewMsg_TranslateTextReponse, OnTranslateTextResponse)
[email protected]634a6f92008-12-01 21:39:31617
initial.commit09911bf2008-07-26 23:55:29618 // Have the super handle all other messages.
619 IPC_MESSAGE_UNHANDLED(RenderWidget::OnMessageReceived(message))
620 IPC_END_MESSAGE_MAP()
621}
622
initial.commit09911bf2008-07-26 23:55:29623void RenderView::SendThumbnail() {
[email protected]26aa0482009-09-30 16:55:27624 WebFrame* main_frame = webview()->mainFrame();
initial.commit09911bf2008-07-26 23:55:29625 if (!main_frame)
626 return;
627
628 // get the URL for this page
[email protected]dd7daa82009-08-10 05:46:45629 GURL url(main_frame->url());
initial.commit09911bf2008-07-26 23:55:29630 if (url.is_empty())
631 return;
632
633 if (size_.IsEmpty())
634 return; // Don't create an empty thumbnail!
635
636 ThumbnailScore score;
637 SkBitmap thumbnail;
[email protected]8649fb32009-06-26 17:51:02638 if (!CaptureThumbnail(webview(), kThumbnailWidth, kThumbnailHeight,
[email protected]b6e4bec2008-11-12 01:17:15639 &thumbnail, &score))
640 return;
641
initial.commit09911bf2008-07-26 23:55:29642 // send the thumbnail message to the browser process
[email protected]674741932009-02-04 23:44:46643 Send(new ViewHostMsg_Thumbnail(routing_id_, url, score, thumbnail));
initial.commit09911bf2008-07-26 23:55:29644}
645
[email protected]30507922010-01-15 16:48:23646void RenderView::SendSnapshot() {
647 SkBitmap snapshot;
648 bool error = false;
649
650 WebFrame* main_frame = webview()->mainFrame();
651 if (!main_frame)
652 error = true;
653
654 if (!error && !CaptureSnapshot(webview(), &snapshot))
655 error = true;
656
657 DCHECK(error == snapshot.empty()) <<
658 "Snapshot should be empty on error, non-empty otherwise.";
659
660 // Send the snapshot to the browser process.
661 Send(new ViewHostMsg_Snapshot(routing_id_, snapshot));
662}
663
[email protected]068637222009-01-29 16:58:07664void RenderView::OnPrintPages() {
initial.commit09911bf2008-07-26 23:55:29665 DCHECK(webview());
[email protected]aa82249f2009-07-16 17:23:58666 if (webview()) {
667 // If the user has selected text in the currently focused frame we print
668 // only that frame (this makes print selection work for multiple frames).
[email protected]26aa0482009-09-30 16:55:27669 if (webview()->focusedFrame()->hasSelection())
670 Print(webview()->focusedFrame(), false);
[email protected]aa82249f2009-07-16 17:23:58671 else
[email protected]26aa0482009-09-30 16:55:27672 Print(webview()->mainFrame(), false);
[email protected]aa82249f2009-07-16 17:23:58673 }
initial.commit09911bf2008-07-26 23:55:29674}
675
[email protected]82270452009-06-19 15:58:01676void RenderView::OnPrintingDone(int document_cookie, bool success) {
677 // Ignoring document cookie here since only one print job can be outstanding
678 // per renderer and document_cookie is 0 when printing is successful.
679 DCHECK(print_helper_.get());
680 if (print_helper_.get() != NULL) {
681 print_helper_->DidFinishPrinting(success);
682 }
683}
684
initial.commit09911bf2008-07-26 23:55:29685void RenderView::CapturePageInfo(int load_id, bool preliminary_capture) {
686 if (load_id != page_id_)
687 return; // this capture call is no longer relevant due to navigation
688 if (load_id == last_indexed_page_id_)
689 return; // we already indexed this page
690
691 if (!webview())
692 return;
693
[email protected]26aa0482009-09-30 16:55:27694 WebFrame* main_frame = webview()->mainFrame();
initial.commit09911bf2008-07-26 23:55:29695 if (!main_frame)
696 return;
697
698 // Don't index/capture pages that are in view source mode.
[email protected]dd7daa82009-08-10 05:46:45699 if (main_frame->isViewSourceModeEnabled())
initial.commit09911bf2008-07-26 23:55:29700 return;
701
702 // Don't index/capture pages that failed to load. This only checks the top
703 // level frame so the thumbnail may contain a frame that failed to load.
[email protected]dd7daa82009-08-10 05:46:45704 WebDataSource* ds = main_frame->dataSource();
[email protected]726985e22009-06-18 21:09:28705 if (ds && ds->hasUnreachableURL())
initial.commit09911bf2008-07-26 23:55:29706 return;
707
708 if (!preliminary_capture)
709 last_indexed_page_id_ = load_id;
710
[email protected]a8a81292010-01-21 00:32:45711 // Get the URL for this page.
[email protected]dd7daa82009-08-10 05:46:45712 GURL url(main_frame->url());
initial.commit09911bf2008-07-26 23:55:29713 if (url.is_empty())
714 return;
715
[email protected]a8a81292010-01-21 00:32:45716 // Retrieve the frame's full text.
initial.commit09911bf2008-07-26 23:55:29717 std::wstring contents;
718 CaptureText(main_frame, &contents);
719 if (contents.size()) {
[email protected]a8a81292010-01-21 00:32:45720 base::TimeTicks begin_time = base::TimeTicks::Now();
721 std::string language = DetermineTextLanguage(contents);
722 UMA_HISTOGRAM_MEDIUM_TIMES("Renderer4.LanguageDetection",
723 base::TimeTicks::Now() - begin_time);
[email protected]7893a982010-01-07 23:25:52724
[email protected]a8a81292010-01-21 00:32:45725 // Send the text to the browser for indexing (the browser might decide not
726 // to index, if the URL is HTTPS for instance) and language discovery.
727 Send(new ViewHostMsg_PageContents(routing_id_, url, load_id, contents,
728 language));
[email protected]5c4266922009-07-10 16:41:27729 }
730
initial.commit09911bf2008-07-26 23:55:29731 // thumbnail
732 SendThumbnail();
733}
734
735void RenderView::CaptureText(WebFrame* frame, std::wstring* contents) {
736 contents->clear();
737 if (!frame)
738 return;
739
740#ifdef TIME_TEXT_RETRIEVAL
741 double begin = time_util::GetHighResolutionTimeNow();
742#endif
743
744 // get the contents of the frame
[email protected]dd7daa82009-08-10 05:46:45745 *contents = UTF16ToWideHack(frame->contentAsText(kMaxIndexChars));
initial.commit09911bf2008-07-26 23:55:29746
747#ifdef TIME_TEXT_RETRIEVAL
748 double end = time_util::GetHighResolutionTimeNow();
749 char buf[128];
750 sprintf_s(buf, "%d chars retrieved for indexing in %gms\n",
751 contents.size(), (end - begin)*1000);
752 OutputDebugStringA(buf);
753#endif
754
755 // When the contents are clipped to the maximum, we don't want to have a
756 // partial word indexed at the end that might have been clipped. Therefore,
757 // terminate the string at the last space to ensure no words are clipped.
758 if (contents->size() == kMaxIndexChars) {
759 size_t last_space_index = contents->find_last_of(kWhitespaceWide);
760 if (last_space_index == std::wstring::npos)
761 return; // don't index if we got a huge block of text with no spaces
762 contents->resize(last_space_index);
763 }
764}
765
[email protected]8649fb32009-06-26 17:51:02766bool RenderView::CaptureThumbnail(WebView* view,
initial.commit09911bf2008-07-26 23:55:29767 int w,
768 int h,
769 SkBitmap* thumbnail,
770 ThumbnailScore* score) {
[email protected]30507922010-01-15 16:48:23771 base::TimeTicks beginning_time = base::TimeTicks::Now();
[email protected]b6e4bec2008-11-12 01:17:15772
[email protected]8649fb32009-06-26 17:51:02773 skia::PlatformCanvas canvas;
[email protected]30507922010-01-15 16:48:23774
775 // Paint |view| into |canvas|.
776 if (!PaintViewIntoCanvas(view, canvas))
[email protected]8649fb32009-06-26 17:51:02777 return false;
[email protected]8649fb32009-06-26 17:51:02778
779 skia::BitmapPlatformDevice& device =
780 static_cast<skia::BitmapPlatformDevice&>(canvas.getTopPlatformDevice());
781
782 const SkBitmap& src_bmp = device.accessBitmap(false);
initial.commit09911bf2008-07-26 23:55:29783
[email protected]cab34d6a2009-09-24 01:14:52784 SkRect dest_rect = { 0, 0, SkIntToScalar(w), SkIntToScalar(h) };
initial.commit09911bf2008-07-26 23:55:29785 float dest_aspect = dest_rect.width() / dest_rect.height();
786
787 // Get the src rect so that we can preserve the aspect ratio while filling
788 // the destination.
789 SkIRect src_rect;
790 if (src_bmp.width() < dest_rect.width() ||
791 src_bmp.height() < dest_rect.height()) {
792 // Source image is smaller: we clip the part of source image within the
793 // dest rect, and then stretch it to fill the dest rect. We don't respect
794 // the aspect ratio in this case.
795 src_rect.set(0, 0, static_cast<S16CPU>(dest_rect.width()),
796 static_cast<S16CPU>(dest_rect.height()));
797 score->good_clipping = false;
798 } else {
799 float src_aspect = static_cast<float>(src_bmp.width()) / src_bmp.height();
800 if (src_aspect > dest_aspect) {
801 // Wider than tall, clip horizontally: we center the smaller thumbnail in
802 // the wider screen.
803 S16CPU new_width = static_cast<S16CPU>(src_bmp.height() * dest_aspect);
804 S16CPU x_offset = (src_bmp.width() - new_width) / 2;
805 src_rect.set(x_offset, 0, new_width + x_offset, src_bmp.height());
806 score->good_clipping = false;
807 } else {
808 src_rect.set(0, 0, src_bmp.width(),
809 static_cast<S16CPU>(src_bmp.width() / dest_aspect));
810 score->good_clipping = true;
811 }
812 }
813
[email protected]26aa0482009-09-30 16:55:27814 score->at_top = (view->mainFrame()->scrollOffset().height == 0);
initial.commit09911bf2008-07-26 23:55:29815
816 SkBitmap subset;
[email protected]8649fb32009-06-26 17:51:02817 device.accessBitmap(false).extractSubset(&subset, src_rect);
initial.commit09911bf2008-07-26 23:55:29818
819 // Resample the subset that we want to get it the right size.
[email protected]465b34b72008-12-12 20:19:14820 *thumbnail = skia::ImageOperations::Resize(
821 subset, skia::ImageOperations::RESIZE_LANCZOS3, w, h);
initial.commit09911bf2008-07-26 23:55:29822
823 score->boring_score = CalculateBoringScore(thumbnail);
824
[email protected]30507922010-01-15 16:48:23825 HISTOGRAM_TIMES("Renderer4.Thumbnail",
826 base::TimeTicks::Now() - beginning_time);
[email protected]b6e4bec2008-11-12 01:17:15827 return true;
initial.commit09911bf2008-07-26 23:55:29828}
829
[email protected]30507922010-01-15 16:48:23830bool RenderView::CaptureSnapshot(WebView* view, SkBitmap* snapshot) {
831 base::TimeTicks beginning_time = base::TimeTicks::Now();
initial.commit09911bf2008-07-26 23:55:29832
[email protected]30507922010-01-15 16:48:23833 skia::PlatformCanvas canvas;
834 if (!PaintViewIntoCanvas(view, canvas))
835 return false;
836
837 skia::BitmapPlatformDevice& device =
838 static_cast<skia::BitmapPlatformDevice&>(canvas.getTopPlatformDevice());
839
840 const SkBitmap& bitmap = device.accessBitmap(false);
841 if (!bitmap.copyTo(snapshot, SkBitmap::kARGB_8888_Config))
842 return false;
843
844 HISTOGRAM_TIMES("Renderer4.Snapshot",
845 base::TimeTicks::Now() - beginning_time);
846 return true;
initial.commit09911bf2008-07-26 23:55:29847}
848
849void RenderView::OnNavigate(const ViewMsg_Navigate_Params& params) {
850 if (!webview())
851 return;
852
[email protected]8c785c62009-07-13 14:20:15853 if (devtools_agent_.get())
854 devtools_agent_->OnNavigate();
855
[email protected]422197532010-01-25 17:38:23856 if (notification_provider_.get())
857 notification_provider_->OnNavigate();
858
[email protected]a9f607e2009-10-23 19:59:27859 child_process_logging::SetActiveURL(params.url);
[email protected]f8b6b6f2009-03-10 16:48:26860
initial.commit09911bf2008-07-26 23:55:29861 AboutHandler::MaybeHandle(params.url);
862
[email protected]ecbf10d2010-02-18 13:03:29863 bool is_reload =
864 params.navigation_type == ViewMsg_Navigate_Params::RELOAD ||
865 params.navigation_type == ViewMsg_Navigate_Params::RELOAD_IGNORING_CACHE;
initial.commit09911bf2008-07-26 23:55:29866
[email protected]26aa0482009-09-30 16:55:27867 WebFrame* main_frame = webview()->mainFrame();
[email protected]dd7daa82009-08-10 05:46:45868 if (is_reload && main_frame->currentHistoryItem().isNull()) {
initial.commit09911bf2008-07-26 23:55:29869 // We cannot reload if we do not have any history state. This happens, for
870 // example, when recovering from a crash. Our workaround here is a bit of
871 // a hack since it means that reload after a crashed tab does not cause an
872 // end-to-end cache validation.
873 is_reload = false;
874 }
875
[email protected]77f17a82009-05-21 04:42:54876 // A navigation resulting from loading a javascript URL should not be treated
877 // as a browser initiated event. Instead, we want it to look as if the page
878 // initiated any load resulting from JS execution.
879 if (!params.url.SchemeIs(chrome::kJavaScriptScheme)) {
[email protected]5e369672009-11-03 23:48:30880 NavigationState* state = NavigationState::CreateBrowserInitiated(
881 params.page_id, params.transition, params.request_time);
882 if (params.navigation_type == ViewMsg_Navigate_Params::RESTORE) {
883 // We're doing a load of a page that was restored from the last session.
884 // By default this prefers the cache over loading (LOAD_PREFERRING_CACHE)
885 // which can result in stale data for pages that are set to expire. We
886 // explicitly override that by setting the policy here so that as
887 // necessary we load from the network.
888 state->set_cache_policy_override(WebURLRequest::UseProtocolCachePolicy);
889 }
890 pending_navigation_state_.reset(state);
[email protected]77f17a82009-05-21 04:42:54891 }
initial.commit09911bf2008-07-26 23:55:29892
[email protected]a7ccc4d2010-01-27 08:14:48893 NavigationState* navigation_state = pending_navigation_state_.get();
894
[email protected]04d3c6e2009-05-22 17:00:13895 // If we are reloading, then WebKit will use the history state of the current
896 // page, so we should just ignore any given history state. Otherwise, if we
897 // have history state, then we need to navigate to it, which corresponds to a
898 // back/forward navigation event.
[email protected]e6f546c32009-07-01 17:12:55899 if (is_reload) {
[email protected]a7ccc4d2010-01-27 08:14:48900 if (navigation_state)
901 navigation_state->set_load_type(NavigationState::RELOAD);
[email protected]ecbf10d2010-02-18 13:03:29902 bool ignore_cache = (params.navigation_type ==
903 ViewMsg_Navigate_Params::RELOAD_IGNORING_CACHE);
904 main_frame->reload(ignore_cache);
[email protected]e6f546c32009-07-01 17:12:55905 } else if (!params.state.empty()) {
[email protected]04d3c6e2009-05-22 17:00:13906 // We must know the page ID of the page we are navigating back to.
[email protected]f929f2f22009-06-12 16:56:58907 DCHECK_NE(params.page_id, -1);
[email protected]a7ccc4d2010-01-27 08:14:48908 if (navigation_state)
909 navigation_state->set_load_type(NavigationState::HISTORY_LOAD);
[email protected]dd7daa82009-08-10 05:46:45910 main_frame->loadHistoryItem(
[email protected]ca948a22009-06-25 19:36:17911 webkit_glue::HistoryItemFromString(params.state));
[email protected]04d3c6e2009-05-22 17:00:13912 } else {
913 // Navigate to the given URL.
[email protected]726985e22009-06-18 21:09:28914 WebURLRequest request(params.url);
initial.commit09911bf2008-07-26 23:55:29915
[email protected]e6f546c32009-07-01 17:12:55916 // A session history navigation should have been accompanied by state.
917 DCHECK_EQ(params.page_id, -1);
[email protected]04d3c6e2009-05-22 17:00:13918
[email protected]dd7daa82009-08-10 05:46:45919 if (main_frame->isViewSourceModeEnabled())
[email protected]e6f546c32009-07-01 17:12:55920 request.setCachePolicy(WebURLRequest::ReturnCacheDataElseLoad);
[email protected]04d3c6e2009-05-22 17:00:13921
[email protected]726985e22009-06-18 21:09:28922 if (params.referrer.is_valid()) {
923 request.setHTTPHeaderField(WebString::fromUTF8("Referer"),
924 WebString::fromUTF8(params.referrer.spec()));
925 }
[email protected]04d3c6e2009-05-22 17:00:13926
[email protected]a7ccc4d2010-01-27 08:14:48927 if (navigation_state)
928 navigation_state->set_load_type(NavigationState::NORMAL_LOAD);
[email protected]dd7daa82009-08-10 05:46:45929 main_frame->loadRequest(request);
[email protected]c0588052008-10-27 23:01:50930 }
931
[email protected]77f17a82009-05-21 04:42:54932 // In case LoadRequest failed before DidCreateDataSource was called.
933 pending_navigation_state_.reset();
initial.commit09911bf2008-07-26 23:55:29934}
935
936// Stop loading the current page
937void RenderView::OnStop() {
938 if (webview())
[email protected]b4bb2502009-10-01 22:35:27939 webview()->mainFrame()->stopLoading();
initial.commit09911bf2008-07-26 23:55:29940}
941
[email protected]ecbf10d2010-02-18 13:03:29942// Reload current focused frame.
943// E.g. called by right-clicking on the frame and picking "reload this frame".
[email protected]1dda4022010-01-28 18:24:56944void RenderView::OnReloadFrame() {
[email protected]ecbf10d2010-02-18 13:03:29945 if (webview() && webview()->focusedFrame()) {
946 // We always obey the cache (ignore_cache=false) here.
947 // TODO(evanm): perhaps we could allow shift-clicking the menu item to do
948 // a cache-ignoring reload of the frame.
949 webview()->focusedFrame()->reload(false);
950 }
[email protected]1dda4022010-01-28 18:24:56951}
952
[email protected]e6f546c32009-07-01 17:12:55953void RenderView::OnLoadAlternateHTMLText(const std::string& html,
initial.commit09911bf2008-07-26 23:55:29954 bool new_navigation,
955 const GURL& display_url,
956 const std::string& security_info) {
957 if (!webview())
958 return;
959
[email protected]e6f546c32009-07-01 17:12:55960 pending_navigation_state_.reset(NavigationState::CreateBrowserInitiated(
961 new_navigation ? -1 : page_id_, PageTransition::LINK, Time::Now()));
962 pending_navigation_state_->set_security_info(security_info);
initial.commit09911bf2008-07-26 23:55:29963
[email protected]26aa0482009-09-30 16:55:27964 webview()->mainFrame()->loadHTMLString(
965 html, GURL(kUnreachableWebDataURL), display_url, !new_navigation);
[email protected]e6f546c32009-07-01 17:12:55966
967 pending_navigation_state_.reset();
initial.commit09911bf2008-07-26 23:55:29968}
969
970void RenderView::OnCopyImageAt(int x, int y) {
[email protected]26aa0482009-09-30 16:55:27971 webview()->copyImageAt(WebPoint(x, y));
initial.commit09911bf2008-07-26 23:55:29972}
973
[email protected]68b1e922009-06-23 16:00:25974void RenderView::OnExecuteEditCommand(const std::string& name,
975 const std::string& value) {
[email protected]26aa0482009-09-30 16:55:27976 if (!webview() || !webview()->focusedFrame())
[email protected]68b1e922009-06-23 16:00:25977 return;
978
[email protected]26aa0482009-09-30 16:55:27979 webview()->focusedFrame()->executeCommand(
[email protected]dd7daa82009-08-10 05:46:45980 WebString::fromUTF8(name), WebString::fromUTF8(value));
[email protected]68b1e922009-06-23 16:00:25981}
982
[email protected]b2abac72009-02-26 12:39:28983void RenderView::OnSetupDevToolsClient() {
[email protected]e4ac5df2009-03-17 15:33:11984 DCHECK(!devtools_client_.get());
985 devtools_client_.reset(new DevToolsClient(this));
[email protected]b2abac72009-02-26 12:39:28986}
987
[email protected]5bc8fe92010-03-11 18:19:00988void RenderView::OnStopFinding(const ViewMsg_StopFinding_Params& params) {
initial.commit09911bf2008-07-26 23:55:29989 WebView* view = webview();
990 if (!view)
991 return;
992
[email protected]5bc8fe92010-03-11 18:19:00993 bool clear_selection =
994 params.action == ViewMsg_StopFinding_Params::kClearSelection;
initial.commit09911bf2008-07-26 23:55:29995 if (clear_selection)
[email protected]26aa0482009-09-30 16:55:27996 view->focusedFrame()->executeCommand(WebString::fromUTF8("Unselect"));
initial.commit09911bf2008-07-26 23:55:29997
[email protected]26aa0482009-09-30 16:55:27998 WebFrame* frame = view->mainFrame();
initial.commit09911bf2008-07-26 23:55:29999 while (frame) {
[email protected]dd7daa82009-08-10 05:46:451000 frame->stopFinding(clear_selection);
[email protected]b4bb2502009-10-01 22:35:271001 frame = frame->traverseNext(false);
initial.commit09911bf2008-07-26 23:55:291002 }
[email protected]5bc8fe92010-03-11 18:19:001003
1004 if (params.action == ViewMsg_StopFinding_Params::kActivateSelection) {
1005 WebFrame* focused_frame = view->focusedFrame();
1006 if (focused_frame) {
1007 WebDocument doc = focused_frame->document();
1008 if (!doc.isNull()) {
1009 WebNode node = doc.focusedNode();
1010 if (!node.isNull())
1011 node.simulateClick();
1012 }
1013 }
1014 }
initial.commit09911bf2008-07-26 23:55:291015}
1016
1017void RenderView::OnFindReplyAck() {
1018 // Check if there is any queued up request waiting to be sent.
1019 if (queued_find_reply_message_.get()) {
1020 // Send the search result over to the browser process.
1021 Send(queued_find_reply_message_.get());
1022 queued_find_reply_message_.release();
1023 }
1024}
1025
1026void RenderView::OnUpdateTargetURLAck() {
1027 // Check if there is a targeturl waiting to be sent.
1028 if (target_url_status_ == TARGET_PENDING) {
1029 Send(new ViewHostMsg_UpdateTargetURL(routing_id_, page_id_,
1030 pending_target_url_));
1031 }
1032
1033 target_url_status_ = TARGET_NONE;
1034}
1035
1036void RenderView::OnUndo() {
1037 if (!webview())
1038 return;
1039
[email protected]26aa0482009-09-30 16:55:271040 webview()->focusedFrame()->executeCommand(WebString::fromUTF8("Undo"));
[email protected]afe3a1672009-11-17 19:04:121041 UserMetricsRecordAction("Undo");
initial.commit09911bf2008-07-26 23:55:291042}
1043
1044void RenderView::OnRedo() {
1045 if (!webview())
1046 return;
1047
[email protected]26aa0482009-09-30 16:55:271048 webview()->focusedFrame()->executeCommand(WebString::fromUTF8("Redo"));
[email protected]afe3a1672009-11-17 19:04:121049 UserMetricsRecordAction("Redo");
initial.commit09911bf2008-07-26 23:55:291050}
1051
1052void RenderView::OnCut() {
1053 if (!webview())
1054 return;
1055
[email protected]26aa0482009-09-30 16:55:271056 webview()->focusedFrame()->executeCommand(WebString::fromUTF8("Cut"));
[email protected]afe3a1672009-11-17 19:04:121057 UserMetricsRecordAction("Cut");
initial.commit09911bf2008-07-26 23:55:291058}
1059
1060void RenderView::OnCopy() {
1061 if (!webview())
1062 return;
1063
[email protected]26aa0482009-09-30 16:55:271064 webview()->focusedFrame()->executeCommand(WebString::fromUTF8("Copy"));
[email protected]afe3a1672009-11-17 19:04:121065 UserMetricsRecordAction("Copy");
initial.commit09911bf2008-07-26 23:55:291066}
1067
[email protected]c0cc3092009-09-12 08:27:271068#if defined(OS_MACOSX)
[email protected]a954bf72009-09-12 07:30:351069void RenderView::OnCopyToFindPboard() {
1070 if (!webview())
1071 return;
1072
1073 // Since the find pasteboard supports only plain text, this can be simpler
1074 // than the |OnCopy()| case.
[email protected]26aa0482009-09-30 16:55:271075 WebFrame* frame = webview()->focusedFrame();
[email protected]a954bf72009-09-12 07:30:351076 if (frame->hasSelection()) {
1077 string16 selection = frame->selectionAsText();
1078 RenderThread::current()->Send(
1079 new ViewHostMsg_ClipboardFindPboardWriteStringAsync(selection));
1080 }
1081
[email protected]afe3a1672009-11-17 19:04:121082 UserMetricsRecordAction("CopyToFindPboard");
[email protected]a954bf72009-09-12 07:30:351083}
[email protected]c0cc3092009-09-12 08:27:271084#endif
[email protected]a954bf72009-09-12 07:30:351085
initial.commit09911bf2008-07-26 23:55:291086void RenderView::OnPaste() {
1087 if (!webview())
1088 return;
1089
[email protected]26aa0482009-09-30 16:55:271090 webview()->focusedFrame()->executeCommand(WebString::fromUTF8("Paste"));
[email protected]afe3a1672009-11-17 19:04:121091 UserMetricsRecordAction("Paste");
initial.commit09911bf2008-07-26 23:55:291092}
1093
[email protected]2a3a7762009-10-19 19:17:321094void RenderView::OnReplace(const string16& text) {
initial.commit09911bf2008-07-26 23:55:291095 if (!webview())
1096 return;
1097
[email protected]1ff7a032010-02-03 02:46:031098 WebFrame* frame = webview()->focusedFrame();
1099 if (!frame->hasSelection())
1100 frame->selectWordAroundCaret();
1101 frame->replaceSelection(text);
initial.commit09911bf2008-07-26 23:55:291102}
1103
[email protected]98324892009-09-09 21:16:051104void RenderView::OnAdvanceToNextMisspelling() {
1105 if (!webview())
1106 return;
[email protected]26aa0482009-09-30 16:55:271107 webview()->focusedFrame()->executeCommand(
[email protected]98324892009-09-09 21:16:051108 WebString::fromUTF8("AdvanceToNextMisspelling"));
1109}
1110
1111void RenderView::OnToggleSpellPanel(bool is_currently_visible) {
1112 if (!webview())
1113 return;
1114 // We need to tell the webView whether the spelling panel is visible or not so
1115 // that it won't need to make ipc calls later.
[email protected]8922e1f2009-10-03 05:01:261116 spelling_panel_visible_ = is_currently_visible;
[email protected]26aa0482009-09-30 16:55:271117 webview()->focusedFrame()->executeCommand(
[email protected]98324892009-09-09 21:16:051118 WebString::fromUTF8("ToggleSpellPanel"));
1119}
1120
[email protected]bbbd545c2008-12-15 20:18:041121void RenderView::OnToggleSpellCheck() {
1122 if (!webview())
1123 return;
1124
[email protected]26aa0482009-09-30 16:55:271125 WebFrame* frame = webview()->focusedFrame();
[email protected]dd7daa82009-08-10 05:46:451126 frame->enableContinuousSpellChecking(
1127 !frame->isContinuousSpellCheckingEnabled());
[email protected]bbbd545c2008-12-15 20:18:041128}
1129
initial.commit09911bf2008-07-26 23:55:291130void RenderView::OnDelete() {
1131 if (!webview())
1132 return;
1133
[email protected]26aa0482009-09-30 16:55:271134 webview()->focusedFrame()->executeCommand(WebString::fromUTF8("Delete"));
[email protected]afe3a1672009-11-17 19:04:121135 UserMetricsRecordAction("DeleteSelection");
initial.commit09911bf2008-07-26 23:55:291136}
1137
1138void RenderView::OnSelectAll() {
1139 if (!webview())
1140 return;
1141
[email protected]26aa0482009-09-30 16:55:271142 webview()->focusedFrame()->executeCommand(
[email protected]a100d76bb2009-08-14 17:50:221143 WebString::fromUTF8("SelectAll"));
[email protected]afe3a1672009-11-17 19:04:121144 UserMetricsRecordAction("SelectAll");
initial.commit09911bf2008-07-26 23:55:291145}
1146
1147void RenderView::OnSetInitialFocus(bool reverse) {
1148 if (!webview())
1149 return;
[email protected]26aa0482009-09-30 16:55:271150 webview()->setInitialFocus(reverse);
initial.commit09911bf2008-07-26 23:55:291151}
1152
1153///////////////////////////////////////////////////////////////////////////////
1154
[email protected]433819d2010-01-30 20:20:011155void RenderView::SetContentSettings(const ContentSettings& settings) {
1156 current_content_settings_ = settings;
[email protected]f85f0702010-01-30 09:31:011157}
1158
initial.commit09911bf2008-07-26 23:55:291159// Tell the embedding application that the URL of the active page has changed
1160void RenderView::UpdateURL(WebFrame* frame) {
[email protected]dd7daa82009-08-10 05:46:451161 WebDataSource* ds = frame->dataSource();
initial.commit09911bf2008-07-26 23:55:291162 DCHECK(ds);
1163
[email protected]726985e22009-06-18 21:09:281164 const WebURLRequest& request = ds->request();
1165 const WebURLRequest& original_request = ds->originalRequest();
1166 const WebURLResponse& response = ds->response();
initial.commit09911bf2008-07-26 23:55:291167
[email protected]daa8c58e2009-06-15 17:21:101168 NavigationState* navigation_state = NavigationState::FromDataSource(ds);
1169 DCHECK(navigation_state);
initial.commit09911bf2008-07-26 23:55:291170
1171 ViewHostMsg_FrameNavigate_Params params;
[email protected]726985e22009-06-18 21:09:281172 params.http_status_code = response.httpStatusCode();
initial.commit09911bf2008-07-26 23:55:291173 params.is_post = false;
1174 params.page_id = page_id_;
[email protected]726985e22009-06-18 21:09:281175 params.is_content_filtered = response.isContentFiltered();
[email protected]e6f546c32009-07-01 17:12:551176 if (!navigation_state->security_info().empty()) {
initial.commit09911bf2008-07-26 23:55:291177 // SSL state specified in the request takes precedence over the one in the
1178 // response.
1179 // So far this is only intended for error pages that are not expected to be
1180 // over ssl, so we should not get any clash.
[email protected]726985e22009-06-18 21:09:281181 DCHECK(response.securityInfo().isEmpty());
[email protected]e6f546c32009-07-01 17:12:551182 params.security_info = navigation_state->security_info();
initial.commit09911bf2008-07-26 23:55:291183 } else {
[email protected]726985e22009-06-18 21:09:281184 params.security_info = response.securityInfo();
initial.commit09911bf2008-07-26 23:55:291185 }
1186
1187 // Set the URL to be displayed in the browser UI to the user.
[email protected]726985e22009-06-18 21:09:281188 if (ds->hasUnreachableURL()) {
1189 params.url = ds->unreachableURL();
initial.commit09911bf2008-07-26 23:55:291190 } else {
[email protected]726985e22009-06-18 21:09:281191 params.url = request.url();
initial.commit09911bf2008-07-26 23:55:291192 }
1193
[email protected]726985e22009-06-18 21:09:281194 GetRedirectChain(ds, &params.redirects);
[email protected]d94dc1e2010-03-04 09:29:241195 params.should_update_history = !ds->hasUnreachableURL() &&
1196 !response.isMultipartPayload();
initial.commit09911bf2008-07-26 23:55:291197
[email protected]ce0e250d2009-10-23 21:00:351198 params.searchable_form_url = navigation_state->searchable_form_url();
1199 params.searchable_form_encoding =
1200 navigation_state->searchable_form_encoding();
initial.commit09911bf2008-07-26 23:55:291201
1202 const PasswordForm* password_form_data =
[email protected]daa8c58e2009-06-15 17:21:101203 navigation_state->password_form_data();
initial.commit09911bf2008-07-26 23:55:291204 if (password_form_data)
1205 params.password_form = *password_form_data;
1206
1207 params.gesture = navigation_gesture_;
1208 navigation_gesture_ = NavigationGestureUnknown;
1209
[email protected]dd7daa82009-08-10 05:46:451210 if (!frame->parent()) {
initial.commit09911bf2008-07-26 23:55:291211 // Top-level navigation.
1212
[email protected]71b0d5d2010-02-15 05:43:071213 // Clear "block" flags for the new page. This needs to happen before any of
1214 // allowScripts(), allowImages(), allowPlugins() is called for the new page
1215 // so that these functions can correctly detect that a piece of content
1216 // flipped from "not blocked" to "blocked".
1217 ClearBlockedContentSettings();
1218
[email protected]f85f0702010-01-30 09:31:011219 // Set content settings.
1220 HostContentSettings::iterator host_content_settings =
1221 host_content_settings_.find(GURL(request.url()).host());
1222 if (host_content_settings != host_content_settings_.end()) {
[email protected]433819d2010-01-30 20:20:011223 SetContentSettings(host_content_settings->second);
[email protected]f85f0702010-01-30 09:31:011224
1225 // These content settings were merely recorded transiently for this load.
1226 // We can erase them now. If at some point we reload this page, the
1227 // browser will send us new, up-to-date content settings.
1228 host_content_settings_.erase(host_content_settings);
1229 }
1230
[email protected]40bd6582009-12-04 23:49:511231 // Set zoom level.
[email protected]f85f0702010-01-30 09:31:011232 HostZoomLevels::iterator host_zoom =
[email protected]40bd6582009-12-04 23:49:511233 host_zoom_levels_.find(GURL(request.url()).host());
[email protected]f85f0702010-01-30 09:31:011234 if (host_zoom != host_zoom_levels_.end()) {
1235 webview()->setZoomLevel(false, host_zoom->second);
[email protected]40bd6582009-12-04 23:49:511236 // This zoom level was merely recorded transiently for this load. We can
1237 // erase it now. If at some point we reload this page, the browser will
1238 // send us a new, up-to-date zoom level.
[email protected]f85f0702010-01-30 09:31:011239 host_zoom_levels_.erase(host_zoom);
[email protected]40bd6582009-12-04 23:49:511240 }
1241
initial.commit09911bf2008-07-26 23:55:291242 // Update contents MIME type for main frame.
[email protected]9c5645b2009-08-11 03:37:551243 params.contents_mime_type = ds->response().mimeType().utf8();
initial.commit09911bf2008-07-26 23:55:291244
[email protected]daa8c58e2009-06-15 17:21:101245 params.transition = navigation_state->transition_type();
initial.commit09911bf2008-07-26 23:55:291246 if (!PageTransition::IsMainFrame(params.transition)) {
1247 // If the main frame does a load, it should not be reported as a subframe
1248 // navigation. This can occur in the following case:
1249 // 1. You're on a site with frames.
1250 // 2. You do a subframe navigation. This is stored with transition type
1251 // MANUAL_SUBFRAME.
1252 // 3. You navigate to some non-frame site, say, google.com.
1253 // 4. You navigate back to the page from step 2. Since it was initially
1254 // MANUAL_SUBFRAME, it will be that same transition type here.
1255 // We don't want that, because any navigation that changes the toplevel
1256 // frame should be tracked as a toplevel navigation (this allows us to
1257 // update the URL bar, etc).
1258 params.transition = PageTransition::LINK;
1259 }
1260
initial.commit09911bf2008-07-26 23:55:291261 // If we have a valid consumed client redirect source,
1262 // the page contained a client redirect (meta refresh, document.loc...),
1263 // so we set the referrer and transition to match.
1264 if (completed_client_redirect_src_.is_valid()) {
[email protected]77e09a92008-08-01 18:11:041265 DCHECK(completed_client_redirect_src_ == params.redirects[0]);
initial.commit09911bf2008-07-26 23:55:291266 params.referrer = completed_client_redirect_src_;
1267 params.transition = static_cast<PageTransition::Type>(
1268 params.transition | PageTransition::CLIENT_REDIRECT);
1269 } else {
1270 // Bug 654101: the referrer will be empty on https->http transitions. It
1271 // would be nice if we could get the real referrer from somewhere.
[email protected]726985e22009-06-18 21:09:281272 params.referrer = GURL(
1273 original_request.httpHeaderField(WebString::fromUTF8("Referer")));
initial.commit09911bf2008-07-26 23:55:291274 }
1275
[email protected]726985e22009-06-18 21:09:281276 string16 method = request.httpMethod();
1277 if (EqualsASCII(method, "POST"))
initial.commit09911bf2008-07-26 23:55:291278 params.is_post = true;
1279
[email protected]c2a797d2009-09-21 16:46:321280 // Save some histogram data so we can compute the average memory used per
1281 // page load of the glyphs.
1282 UMA_HISTOGRAM_COUNTS_10000("Memory.GlyphPagesPerLoad",
1283 webkit_glue::GetGlyphPageCount());
1284
[email protected]15cf526b2010-02-12 06:33:491285 // This message needs to be sent before any of allowScripts(),
1286 // allowImages(), allowPlugins() is called for the new page, so that when
1287 // these functions send a ViewHostMsg_ContentBlocked message, it arrives
1288 // after the ViewHostMsg_FrameNavigate message.
initial.commit09911bf2008-07-26 23:55:291289 Send(new ViewHostMsg_FrameNavigate(routing_id_, params));
1290 } else {
1291 // Subframe navigation: the type depends on whether this navigation
1292 // generated a new session history entry. When they do generate a session
1293 // history entry, it means the user initiated the navigation and we should
1294 // mark it as such. This test checks if this is the first time UpdateURL
1295 // has been called since WillNavigateToURL was called to initiate the load.
1296 if (page_id_ > last_page_id_sent_to_browser_)
1297 params.transition = PageTransition::MANUAL_SUBFRAME;
1298 else
1299 params.transition = PageTransition::AUTO_SUBFRAME;
1300
initial.commit09911bf2008-07-26 23:55:291301 Send(new ViewHostMsg_FrameNavigate(routing_id_, params));
1302 }
1303
1304 last_page_id_sent_to_browser_ =
1305 std::max(last_page_id_sent_to_browser_, page_id_);
1306
1307 // If we end up reusing this WebRequest (for example, due to a #ref click),
[email protected]daa8c58e2009-06-15 17:21:101308 // we don't want the transition type to persist. Just clear it.
1309 navigation_state->set_transition_type(PageTransition::LINK);
[email protected]266eb6f2008-09-30 23:56:501310
[email protected]6c8afae52009-01-22 02:24:571311#if defined(OS_WIN)
[email protected]c7287a92009-11-04 20:06:151312 if (accessibility_.get()) {
[email protected]17455962010-02-24 01:39:351313 // Remove accessibility info cache.
1314 accessibility_.reset();
[email protected]266eb6f2008-09-30 23:56:501315 }
[email protected]6c8afae52009-01-22 02:24:571316#else
[email protected]7d926f92009-03-03 14:26:541317 // TODO(port): accessibility not yet implemented. See http://crbug.com/8288.
[email protected]6c8afae52009-01-22 02:24:571318#endif
initial.commit09911bf2008-07-26 23:55:291319}
1320
1321// Tell the embedding application that the title of the active page has changed
[email protected]3d9689372009-09-10 04:29:171322void RenderView::UpdateTitle(WebFrame* frame, const string16& title) {
initial.commit09911bf2008-07-26 23:55:291323 // Ignore all but top level navigations...
[email protected]3d9689372009-09-10 04:29:171324 if (!frame->parent()) {
[email protected]f0af6a72009-05-30 05:25:171325 Send(new ViewHostMsg_UpdateTitle(
[email protected]3d9689372009-09-10 04:29:171326 routing_id_,
1327 page_id_,
1328 UTF16ToWideHack(title.length() > chrome::kMaxTitleChars ?
1329 title.substr(0, chrome::kMaxTitleChars) : title)));
[email protected]f0af6a72009-05-30 05:25:171330 }
initial.commit09911bf2008-07-26 23:55:291331}
1332
1333void RenderView::UpdateEncoding(WebFrame* frame,
[email protected]41fc0322009-09-04 22:23:401334 const std::string& encoding_name) {
initial.commit09911bf2008-07-26 23:55:291335 // Only update main frame's encoding_name.
[email protected]26aa0482009-09-30 16:55:271336 if (webview()->mainFrame() == frame &&
initial.commit09911bf2008-07-26 23:55:291337 last_encoding_name_ != encoding_name) {
[email protected]e38f40152008-09-12 23:08:301338 // Save the encoding name for later comparing.
initial.commit09911bf2008-07-26 23:55:291339 last_encoding_name_ = encoding_name;
1340
[email protected]e38f40152008-09-12 23:08:301341 Send(new ViewHostMsg_UpdateEncoding(routing_id_, last_encoding_name_));
initial.commit09911bf2008-07-26 23:55:291342 }
1343}
1344
[email protected]f4d34b52008-11-24 23:05:011345// Sends the previous session history state to the browser so it will be saved
1346// before we navigate to a new page. This must be called *before* the page ID
1347// has been updated so we know what it was.
initial.commit09911bf2008-07-26 23:55:291348void RenderView::UpdateSessionHistory(WebFrame* frame) {
1349 // If we have a valid page ID at this point, then it corresponds to the page
1350 // we are navigating away from. Otherwise, this is the first navigation, so
1351 // there is no past session history to record.
1352 if (page_id_ == -1)
1353 return;
1354
[email protected]ca948a22009-06-25 19:36:171355 const WebHistoryItem& item =
[email protected]26aa0482009-09-30 16:55:271356 webview()->mainFrame()->previousHistoryItem();
[email protected]ca948a22009-06-25 19:36:171357 if (item.isNull())
initial.commit09911bf2008-07-26 23:55:291358 return;
[email protected]ca948a22009-06-25 19:36:171359
1360 Send(new ViewHostMsg_UpdateState(
1361 routing_id_, page_id_, webkit_glue::HistoryItemToString(item)));
initial.commit09911bf2008-07-26 23:55:291362}
1363
[email protected]3d9689372009-09-10 04:29:171364void RenderView::OpenURL(
1365 const GURL& url, const GURL& referrer, WebNavigationPolicy policy) {
1366 Send(new ViewHostMsg_OpenURL(
1367 routing_id_, url, referrer, NavigationPolicyToDisposition(policy)));
1368}
1369
[email protected]79dbc662009-09-04 05:42:511370// WebViewDelegate ------------------------------------------------------------
initial.commit09911bf2008-07-26 23:55:291371
initial.commit09911bf2008-07-26 23:55:291372void RenderView::LoadNavigationErrorPage(WebFrame* frame,
[email protected]726985e22009-06-18 21:09:281373 const WebURLRequest& failed_request,
1374 const WebURLError& error,
initial.commit09911bf2008-07-26 23:55:291375 const std::string& html,
1376 bool replace) {
[email protected]726985e22009-06-18 21:09:281377 GURL failed_url = error.unreachableURL;
initial.commit09911bf2008-07-26 23:55:291378
1379 std::string alt_html;
1380 if (html.empty()) {
1381 // Use a local error page.
1382 int resource_id;
1383 DictionaryValue error_strings;
[email protected]726985e22009-06-18 21:09:281384 if (error.reason == net::ERR_CACHE_MISS &&
1385 EqualsASCII(failed_request.httpMethod(), "POST")) {
initial.commit09911bf2008-07-26 23:55:291386 GetFormRepostErrorValues(failed_url, &error_strings);
1387 resource_id = IDR_ERROR_NO_DETAILS_HTML;
1388 } else {
1389 GetLocalizedErrorValues(error, &error_strings);
1390 resource_id = IDR_NET_ERROR_HTML;
1391 }
initial.commit09911bf2008-07-26 23:55:291392
1393 alt_html = GetAltHTMLForTemplate(error_strings, resource_id);
1394 } else {
1395 alt_html = html;
1396 }
1397
[email protected]dd7daa82009-08-10 05:46:451398 frame->loadHTMLString(alt_html,
[email protected]e6f546c32009-07-01 17:12:551399 GURL(kUnreachableWebDataURL),
1400 failed_url,
1401 replace);
initial.commit09911bf2008-07-26 23:55:291402}
1403
[email protected]7ccddb8c2009-08-04 17:36:551404void RenderView::BindDOMAutomationController(WebFrame* frame) {
initial.commit09911bf2008-07-26 23:55:291405 dom_automation_controller_.set_message_sender(this);
1406 dom_automation_controller_.set_routing_id(routing_id_);
[email protected]7ccddb8c2009-08-04 17:36:551407 dom_automation_controller_.BindToJavascript(frame,
initial.commit09911bf2008-07-26 23:55:291408 L"domAutomationController");
1409}
1410
initial.commit09911bf2008-07-26 23:55:291411bool RenderView::RunJavaScriptMessage(int type,
1412 const std::wstring& message,
1413 const std::wstring& default_value,
[email protected]a455d3812009-03-05 20:18:071414 const GURL& frame_url,
initial.commit09911bf2008-07-26 23:55:291415 std::wstring* result) {
1416 bool success = false;
1417 std::wstring result_temp;
1418 if (!result)
1419 result = &result_temp;
initial.commit09911bf2008-07-26 23:55:291420
[email protected]12636df2009-09-28 22:32:211421 SendAndRunNestedMessageLoop(new ViewHostMsg_RunJavaScriptMessage(
1422 routing_id_, message, default_value, frame_url, type, &success, result));
initial.commit09911bf2008-07-26 23:55:291423 return success;
1424}
1425
[email protected]c1f50aa2010-02-18 03:46:571426bool RenderView::SendAndRunNestedMessageLoop(IPC::SyncMessage* message) {
1427 // Before WebKit asks us to show an alert (etc.), it takes care of doing the
1428 // equivalent of WebView::willEnterModalLoop. In the case of showModalDialog
1429 // it is particularly important that we do not call willEnterModalLoop as
1430 // that would defer resource loads for the dialog itself.
1431 if (RenderThread::current()) // Will be NULL during unit tests.
1432 RenderThread::current()->DoNotNotifyWebKitOfModalLoop();
1433
1434 message->EnableMessagePumping(); // Runs a nested message loop.
1435 return Send(message);
1436}
1437
initial.commit09911bf2008-07-26 23:55:291438void RenderView::AddGURLSearchProvider(const GURL& osd_url, bool autodetected) {
1439 if (!osd_url.is_empty())
1440 Send(new ViewHostMsg_PageHasOSDD(routing_id_, page_id_, osd_url,
1441 autodetected));
1442}
1443
[email protected]95056b582010-02-18 01:29:241444void RenderView::OnAutoFillSuggestionsReturned(
1445 int query_id,
1446 const std::vector<string16>& names,
1447 const std::vector<string16>& labels,
1448 int default_suggestion_index) {
1449 if (webview() && query_id == autofill_query_id_) {
1450 webview()->applyAutoFillSuggestions(
1451 autofill_query_node_, names, labels, default_suggestion_index);
1452 }
1453 autofill_query_node_.reset();
1454}
1455
1456void RenderView::OnAutocompleteSuggestionsReturned(
[email protected]acca2a12009-10-16 03:53:391457 int query_id,
1458 const std::vector<string16>& suggestions,
[email protected]0ebf3872008-11-07 21:35:031459 int default_suggestion_index) {
[email protected]7e089f272009-11-03 17:07:181460 if (webview() && query_id == autofill_query_id_) {
[email protected]9e3444c2010-02-11 21:30:081461 webview()->applyAutocompleteSuggestions(
[email protected]acca2a12009-10-16 03:53:391462 autofill_query_node_, suggestions, default_suggestion_index);
1463 }
1464 autofill_query_node_.reset();
[email protected]0ebf3872008-11-07 21:35:031465}
1466
[email protected]45c6e532010-03-15 23:51:241467void RenderView::OnAutoFillFormDataFilled(int query_id,
1468 const webkit_glue::FormData& form) {
[email protected]c83641732010-02-20 01:04:481469 if (query_id != autofill_query_id_)
1470 return;
1471
1472 form_manager_.FillForm(form);
1473}
1474
[email protected]2c4410d2009-05-06 23:46:221475void RenderView::OnPopupNotificationVisibilityChanged(bool visible) {
[email protected]634a6f92008-12-01 21:39:311476 popup_notification_visible_ = visible;
1477}
1478
initial.commit09911bf2008-07-26 23:55:291479uint32 RenderView::GetCPBrowsingContext() {
1480 uint32 context = 0;
1481 Send(new ViewHostMsg_GetCPBrowsingContext(&context));
1482 return context;
1483}
1484
initial.commit09911bf2008-07-26 23:55:291485void RenderView::AddSearchProvider(const std::string& url) {
1486 AddGURLSearchProvider(GURL(url),
1487 false); // not autodetected
1488}
1489
[email protected]f103ab72009-09-02 17:10:591490void RenderView::OnMissingPluginStatus(
1491 WebPluginDelegateProxy* delegate,
1492 int status) {
[email protected]6c8afae52009-01-22 02:24:571493#if defined(OS_WIN)
[email protected]f103ab72009-09-02 17:10:591494 if (!first_default_plugin_) {
initial.commit09911bf2008-07-26 23:55:291495 // Show the InfoBar for the first available plugin.
1496 if (status == default_plugin::MISSING_PLUGIN_AVAILABLE) {
[email protected]f103ab72009-09-02 17:10:591497 first_default_plugin_ = delegate->AsWeakPtr();
initial.commit09911bf2008-07-26 23:55:291498 Send(new ViewHostMsg_MissingPluginStatus(routing_id_, status));
1499 }
1500 } else {
1501 // Closes the InfoBar if user clicks on the plugin (instead of the InfoBar)
1502 // to start the download/install.
1503 if (status == default_plugin::MISSING_PLUGIN_USER_STARTED_DOWNLOAD) {
1504 Send(new ViewHostMsg_MissingPluginStatus(routing_id_, status));
1505 }
1506 }
[email protected]6c8afae52009-01-22 02:24:571507#else
1508 // TODO(port): plugins current not supported
1509 NOTIMPLEMENTED();
1510#endif
initial.commit09911bf2008-07-26 23:55:291511}
1512
[email protected]48c9cf2d2009-09-16 16:47:521513// WebKit::WebViewClient ------------------------------------------------------
1514
1515WebView* RenderView::createView(WebFrame* creator) {
1516 // Check to make sure we aren't overloading on popups.
1517 if (shared_popup_counter_->data > kMaximumNumberOfUnacknowledgedPopups)
1518 return NULL;
1519
1520 // This window can't be closed from a window.close() call until we receive a
1521 // message from the Browser process explicitly allowing it.
1522 popup_notification_visible_ = true;
1523
1524 int32 routing_id = MSG_ROUTING_NONE;
1525 bool user_gesture = creator->isProcessingUserGesture();
[email protected]007a848b2009-10-26 15:55:461526 bool opener_suppressed = creator->willSuppressOpenerInNewFrame();
[email protected]4e6419c2010-01-15 04:50:341527 int64 cloned_session_storage_namespace_id;
[email protected]48c9cf2d2009-09-16 16:47:521528
[email protected]48c9cf2d2009-09-16 16:47:521529 render_thread_->Send(
[email protected]4e6419c2010-01-15 04:50:341530 new ViewHostMsg_CreateWindow(routing_id_, user_gesture,
1531 session_storage_namespace_id_,
1532 &routing_id,
1533 &cloned_session_storage_namespace_id));
[email protected]12636df2009-09-28 22:32:211534 if (routing_id == MSG_ROUTING_NONE)
[email protected]48c9cf2d2009-09-16 16:47:521535 return NULL;
[email protected]48c9cf2d2009-09-16 16:47:521536
[email protected]48c9cf2d2009-09-16 16:47:521537 RenderView* view = RenderView::Create(render_thread_,
[email protected]659f73fa2009-10-13 13:43:421538 0,
[email protected]12636df2009-09-28 22:32:211539 routing_id_,
[email protected]48c9cf2d2009-09-16 16:47:521540 renderer_preferences_,
1541 webkit_preferences_,
[email protected]12636df2009-09-28 22:32:211542 shared_popup_counter_,
[email protected]4e6419c2010-01-15 04:50:341543 routing_id,
1544 cloned_session_storage_namespace_id);
[email protected]48c9cf2d2009-09-16 16:47:521545 view->opened_by_user_gesture_ = user_gesture;
1546
[email protected]007a848b2009-10-26 15:55:461547 // Record whether the creator frame is trying to suppress the opener field.
1548 view->opener_suppressed_ = opener_suppressed;
1549
[email protected]48c9cf2d2009-09-16 16:47:521550 // Record the security origin of the creator.
[email protected]91733b62009-09-18 06:21:091551 GURL creator_url(creator->securityOrigin().toString().utf8());
[email protected]48c9cf2d2009-09-16 16:47:521552 if (!creator_url.is_valid() || !creator_url.IsStandard())
1553 creator_url = GURL();
1554 view->creator_url_ = creator_url;
1555
1556 // Copy over the alternate error page URL so we can have alt error pages in
1557 // the new render view (we don't need the browser to send the URL back down).
1558 view->alternate_error_page_url_ = alternate_error_page_url_;
1559
1560 return view->webview();
1561}
1562
1563WebWidget* RenderView::createPopupMenu(bool activatable) {
1564 RenderWidget* widget = RenderWidget::Create(routing_id_,
1565 render_thread_,
1566 activatable);
1567 return widget->webwidget();
1568}
1569
1570WebWidget* RenderView::createPopupMenu(const WebPopupMenuInfo& info) {
1571 RenderWidget* widget = RenderWidget::Create(routing_id_,
1572 render_thread_,
1573 true);
1574 widget->ConfigureAsExternalPopupMenu(info);
1575 return widget->webwidget();
1576}
1577
[email protected]bd92c3a2010-01-13 05:02:341578WebStorageNamespace* RenderView::createSessionStorageNamespace() {
1579 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kSingleProcess))
1580 return WebStorageNamespace::createSessionStorageNamespace();
[email protected]59afea12010-01-20 04:48:291581 CHECK(session_storage_namespace_id_ != kInvalidSessionStorageNamespaceId);
1582 return new RendererWebStorageNamespaceImpl(DOM_STORAGE_SESSION,
1583 session_storage_namespace_id_);
[email protected]bd92c3a2010-01-13 05:02:341584}
1585
[email protected]48c9cf2d2009-09-16 16:47:521586void RenderView::didAddMessageToConsole(
1587 const WebConsoleMessage& message, const WebString& source_name,
1588 unsigned source_line) {
1589 Send(new ViewHostMsg_AddMessageToConsole(routing_id_,
1590 UTF16ToWideHack(message.text),
1591 static_cast<int32>(source_line),
1592 UTF16ToWideHack(source_name)));
1593}
1594
1595void RenderView::printPage(WebFrame* frame) {
[email protected]71a14262009-09-22 20:02:581596 DCHECK(frame);
1597 Print(frame, true);
[email protected]48c9cf2d2009-09-16 16:47:521598}
1599
1600void RenderView::didStartLoading() {
1601 if (is_loading_) {
1602 DLOG(WARNING) << "didStartLoading called while loading";
1603 return;
1604 }
1605
1606 is_loading_ = true;
1607 // Clear the pointer so that we can assign it only when there is an unknown
1608 // plugin on a page.
1609 first_default_plugin_.reset();
1610
1611 Send(new ViewHostMsg_DidStartLoading(routing_id_));
1612}
1613
1614void RenderView::didStopLoading() {
1615 if (!is_loading_) {
1616 DLOG(WARNING) << "DidStopLoading called while not loading";
1617 return;
1618 }
1619
1620 is_loading_ = false;
1621
1622 // NOTE: For now we're doing the safest thing, and sending out notification
1623 // when done loading. This currently isn't an issue as the favicon is only
1624 // displayed when done loading. Ideally we would send notification when
1625 // finished parsing the head, but webkit doesn't support that yet.
1626 // The feed discovery code would also benefit from access to the head.
[email protected]26aa0482009-09-30 16:55:271627 GURL favicon_url(webview()->mainFrame()->favIconURL());
[email protected]48c9cf2d2009-09-16 16:47:521628 if (!favicon_url.is_empty())
1629 Send(new ViewHostMsg_UpdateFavIconURL(routing_id_, page_id_, favicon_url));
1630
[email protected]26aa0482009-09-30 16:55:271631 AddGURLSearchProvider(webview()->mainFrame()->openSearchDescriptionURL(),
[email protected]48c9cf2d2009-09-16 16:47:521632 true); // autodetected
1633
1634 Send(new ViewHostMsg_DidStopLoading(routing_id_));
1635
1636 MessageLoop::current()->PostDelayedTask(FROM_HERE,
1637 method_factory_.NewRunnableMethod(&RenderView::CapturePageInfo, page_id_,
1638 false),
1639 kDelayForCaptureMs);
[email protected]48c9cf2d2009-09-16 16:47:521640}
1641
[email protected]f55039a2010-02-17 14:12:061642bool RenderView::isSmartInsertDeleteEnabled() {
1643#if defined(OS_MACOSX)
1644 return true;
1645#else
1646 return false;
1647#endif
1648}
1649
[email protected]04fc9482009-09-18 22:13:031650bool RenderView::isSelectTrailingWhitespaceEnabled() {
1651#if defined(OS_WIN)
1652 return true;
1653#else
1654 return false;
1655#endif
1656}
1657
1658void RenderView::setInputMethodEnabled(bool enabled) {
1659 // Save the updated IME status and mark the input focus has been updated.
1660 // The IME status is to be sent to a browser process next time when
1661 // the input caret is rendered.
1662 if (!ime_control_busy_) {
1663 ime_control_updated_ = true;
1664 ime_control_new_state_ = enabled;
1665 }
1666}
1667
1668void RenderView::didChangeSelection(bool is_empty_selection) {
[email protected]6981f7f2010-03-09 00:53:031669#if defined(USE_X11)
[email protected]04fc9482009-09-18 22:13:031670 if (!handling_input_event_)
1671 return;
1672 // TODO(estade): investigate incremental updates to the selection so that we
1673 // don't send the entire selection over IPC every time.
1674 if (!is_empty_selection) {
1675 // Sometimes we get repeated didChangeSelection calls from webkit when
1676 // the selection hasn't actually changed. We don't want to report these
1677 // because it will cause us to continually claim the X clipboard.
1678 const std::string& this_selection =
[email protected]26aa0482009-09-30 16:55:271679 webview()->focusedFrame()->selectionAsText().utf8();
[email protected]04fc9482009-09-18 22:13:031680 if (this_selection == last_selection_)
1681 return;
1682
1683 Send(new ViewHostMsg_SelectionChanged(routing_id_,
1684 this_selection));
1685 last_selection_ = this_selection;
1686 } else {
1687 last_selection_.clear();
1688 }
1689#endif
1690}
1691
1692void RenderView::didExecuteCommand(const WebString& command_name) {
[email protected]afe3a1672009-11-17 19:04:121693 const std::string& name = UTF16ToUTF8(command_name);
1694 if (StartsWithASCII(name, "Move", true) ||
1695 StartsWithASCII(name, "Insert", true) ||
1696 StartsWithASCII(name, "Delete", true))
[email protected]04fc9482009-09-18 22:13:031697 return;
1698 UserMetricsRecordAction(name);
1699}
1700
[email protected]b2528b72009-09-24 06:57:101701bool RenderView::handleCurrentKeyboardEvent() {
1702 if (edit_commands_.empty())
1703 return false;
1704
[email protected]26aa0482009-09-30 16:55:271705 WebFrame* frame = webview()->focusedFrame();
[email protected]b2528b72009-09-24 06:57:101706 if (!frame)
1707 return false;
1708
1709 EditCommands::iterator it = edit_commands_.begin();
1710 EditCommands::iterator end = edit_commands_.end();
1711
[email protected]507b33ea2009-09-29 03:56:511712 bool did_execute_command = false;
[email protected]b2528b72009-09-24 06:57:101713 for (; it != end; ++it) {
[email protected]e6e15012009-09-30 14:59:331714 // In gtk and cocoa, it's possible to bind multiple edit commands to one
1715 // key (but it's the exception). Once one edit command is not executed, it
1716 // seems safest to not execute the rest.
[email protected]b2528b72009-09-24 06:57:101717 if (!frame->executeCommand(WebString::fromUTF8(it->name),
1718 WebString::fromUTF8(it->value)))
1719 break;
[email protected]507b33ea2009-09-29 03:56:511720 did_execute_command = true;
[email protected]b2528b72009-09-24 06:57:101721 }
1722
[email protected]507b33ea2009-09-29 03:56:511723 return did_execute_command;
[email protected]b2528b72009-09-24 06:57:101724}
1725
[email protected]2a3a7762009-10-19 19:17:321726void RenderView::spellCheck(const WebString& text,
1727 int& misspelled_offset,
1728 int& misspelled_length) {
[email protected]1dbafaf72009-09-23 19:43:561729 EnsureDocumentTag();
[email protected]85c55dc2009-11-06 03:05:461730
[email protected]85c55dc2009-11-06 03:05:461731 string16 word(text);
[email protected]cb6037d2009-11-16 22:55:171732 RenderThread* thread = RenderThread::current();
1733 // Will be NULL during unit tests.
1734 if (thread) {
[email protected]c27324b2009-11-19 22:44:291735 thread->spellchecker()->SpellCheckWord(
[email protected]cb6037d2009-11-16 22:55:171736 word.c_str(), word.size(), document_tag_,
1737 &misspelled_offset, &misspelled_length, NULL);
1738 }
[email protected]1dbafaf72009-09-23 19:43:561739}
1740
1741WebString RenderView::autoCorrectWord(const WebKit::WebString& word) {
[email protected]2a3a7762009-10-19 19:17:321742 string16 autocorrect_word;
[email protected]1dbafaf72009-09-23 19:43:561743 const CommandLine& command_line = *CommandLine::ForCurrentProcess();
[email protected]b86c8c12009-10-05 22:01:261744 if (command_line.HasSwitch(switches::kExperimentalSpellcheckerFeatures)) {
[email protected]1dbafaf72009-09-23 19:43:561745 EnsureDocumentTag();
[email protected]cb6037d2009-11-16 22:55:171746 RenderThread* thread = RenderThread::current();
1747 // Will be NULL during unit tests.
1748 if (thread) {
1749 autocorrect_word =
[email protected]c27324b2009-11-19 22:44:291750 thread->spellchecker()->GetAutoCorrectionWord(
[email protected]cb6037d2009-11-16 22:55:171751 word, document_tag_);
1752 }
[email protected]1dbafaf72009-09-23 19:43:561753 }
[email protected]2a3a7762009-10-19 19:17:321754 return autocorrect_word;
[email protected]1dbafaf72009-09-23 19:43:561755}
1756
[email protected]c49085c72009-10-02 16:28:561757void RenderView::showSpellingUI(bool show) {
1758 Send(new ViewHostMsg_ShowSpellingPanel(routing_id_, show));
1759}
1760
[email protected]8922e1f2009-10-03 05:01:261761bool RenderView::isShowingSpellingUI() {
1762 return spelling_panel_visible_;
1763}
1764
[email protected]1dbafaf72009-09-23 19:43:561765void RenderView::updateSpellingUIWithMisspelledWord(const WebString& word) {
[email protected]2a3a7762009-10-19 19:17:321766 Send(new ViewHostMsg_UpdateSpellingPanelWithMisspelledWord(routing_id_,
1767 word));
[email protected]1dbafaf72009-09-23 19:43:561768}
1769
[email protected]a1128322009-10-06 18:38:461770bool RenderView::runFileChooser(
[email protected]01178b52010-01-15 06:59:351771 const WebKit::WebFileChooserParams& params,
[email protected]a1128322009-10-06 18:38:461772 WebKit::WebFileChooserCompletion* chooser_completion) {
1773 if (file_chooser_completion_) {
1774 // TODO(brettw): bug 1235154: This should be a synchronous message to deal
1775 // with the fact that web pages can programatically trigger this. With the
1776 // asnychronous messages, we can get an additional call when one is pending,
1777 // which this test is for. For now, we just ignore the additional file
1778 // chooser request. WebKit doesn't do anything to expect the callback, so
1779 // we can just ignore calling it.
1780 return false;
1781 }
1782 file_chooser_completion_ = chooser_completion;
1783 Send(new ViewHostMsg_RunFileChooser(
[email protected]01178b52010-01-15 06:59:351784 routing_id_, params.multiSelect, params.title,
1785 webkit_glue::WebStringToFilePath(params.initialValue)));
[email protected]a1128322009-10-06 18:38:461786 return true;
1787}
1788
[email protected]48c9cf2d2009-09-16 16:47:521789void RenderView::runModalAlertDialog(
1790 WebFrame* frame, const WebString& message) {
1791 RunJavaScriptMessage(MessageBoxFlags::kIsJavascriptAlert,
1792 UTF16ToWideHack(message),
1793 std::wstring(),
1794 frame->url(),
1795 NULL);
1796}
1797
1798bool RenderView::runModalConfirmDialog(
1799 WebFrame* frame, const WebString& message) {
1800 return RunJavaScriptMessage(MessageBoxFlags::kIsJavascriptConfirm,
1801 UTF16ToWideHack(message),
1802 std::wstring(),
1803 frame->url(),
1804 NULL);
1805}
1806
1807bool RenderView::runModalPromptDialog(
1808 WebFrame* frame, const WebString& message, const WebString& default_value,
1809 WebString* actual_value) {
1810 std::wstring result;
1811 bool ok = RunJavaScriptMessage(MessageBoxFlags::kIsJavascriptPrompt,
1812 UTF16ToWideHack(message),
1813 UTF16ToWideHack(default_value),
1814 frame->url(),
1815 &result);
1816 if (ok)
1817 actual_value->assign(WideToUTF16Hack(result));
1818 return ok;
1819}
1820
1821bool RenderView::runModalBeforeUnloadDialog(
1822 WebFrame* frame, const WebString& message) {
1823 bool success = false;
1824 // This is an ignored return value, but is included so we can accept the same
1825 // response as RunJavaScriptMessage.
1826 std::wstring ignored_result;
[email protected]12636df2009-09-28 22:32:211827 SendAndRunNestedMessageLoop(new ViewHostMsg_RunBeforeUnloadConfirm(
[email protected]48c9cf2d2009-09-16 16:47:521828 routing_id_, frame->url(), UTF16ToWideHack(message), &success,
[email protected]12636df2009-09-28 22:32:211829 &ignored_result));
[email protected]48c9cf2d2009-09-16 16:47:521830 return success;
1831}
1832
[email protected]79e37442009-10-09 18:17:441833void RenderView::showContextMenu(
1834 WebFrame* frame, const WebContextMenuData& data) {
[email protected]c27324b2009-11-19 22:44:291835 ContextMenuParams params = ContextMenuParams(data);
1836 if (!params.misspelled_word.empty() && RenderThread::current()) {
1837 int misspelled_offset, misspelled_length;
[email protected]c76a36a2010-01-26 22:44:041838 bool spelled_right = RenderThread::current()->spellchecker()->
1839 SpellCheckWord(
1840 params.misspelled_word.c_str(), params.misspelled_word.size(),
1841 document_tag_,
1842 &misspelled_offset, &misspelled_length,
1843 &params.dictionary_suggestions);
1844 if (spelled_right)
[email protected]c27324b2009-11-19 22:44:291845 params.misspelled_word.clear();
1846 }
1847
1848 Send(new ViewHostMsg_ContextMenu(routing_id_, params));
[email protected]79e37442009-10-09 18:17:441849}
1850
[email protected]48c9cf2d2009-09-16 16:47:521851void RenderView::setStatusText(const WebString& text) {
1852}
1853
[email protected]163f8242009-10-30 20:19:551854void RenderView::UpdateTargetURL(const GURL& url, const GURL& fallback_url) {
1855 GURL latest_url = url.spec().empty() ? fallback_url : url;
[email protected]48c9cf2d2009-09-16 16:47:521856 if (latest_url == target_url_)
1857 return;
[email protected]163f8242009-10-30 20:19:551858
[email protected]48c9cf2d2009-09-16 16:47:521859 // Tell the browser to display a destination link.
1860 if (target_url_status_ == TARGET_INFLIGHT ||
1861 target_url_status_ == TARGET_PENDING) {
1862 // If we have a request in-flight, save the URL to be sent when we
1863 // receive an ACK to the in-flight request. We can happily overwrite
1864 // any existing pending sends.
1865 pending_target_url_ = latest_url;
1866 target_url_status_ = TARGET_PENDING;
1867 } else {
1868 Send(new ViewHostMsg_UpdateTargetURL(routing_id_, page_id_, latest_url));
1869 target_url_ = latest_url;
1870 target_url_status_ = TARGET_INFLIGHT;
1871 }
1872}
1873
[email protected]882daa92009-11-05 16:31:311874void RenderView::StartNavStateSyncTimerIfNecessary() {
1875 int delay;
1876 if (send_content_state_immediately_)
1877 delay = 0;
1878 else if (is_hidden())
1879 delay = kDelaySecondsForContentStateSyncHidden;
1880 else
1881 delay = kDelaySecondsForContentStateSync;
1882
1883 if (nav_state_sync_timer_.IsRunning()) {
1884 // The timer is already running. If the delay of the timer maches the amount
1885 // we want to delay by, then return. Otherwise stop the timer so that it
1886 // gets started with the right delay.
1887 if (nav_state_sync_timer_.GetCurrentDelay().InSeconds() == delay)
1888 return;
1889 nav_state_sync_timer_.Stop();
1890 }
1891
1892 nav_state_sync_timer_.Start(
1893 TimeDelta::FromSeconds(delay), this, &RenderView::SyncNavigationState);
1894}
1895
[email protected]163f8242009-10-30 20:19:551896void RenderView::setMouseOverURL(const WebURL& url) {
1897 mouse_over_url_ = GURL(url);
1898 UpdateTargetURL(mouse_over_url_, focus_url_);
1899}
1900
1901void RenderView::setKeyboardFocusURL(const WebURL& url) {
1902 focus_url_ = GURL(url);
1903 UpdateTargetURL(focus_url_, mouse_over_url_);
1904}
1905
[email protected]48c9cf2d2009-09-16 16:47:521906void RenderView::setToolTipText(const WebString& text, WebTextDirection hint) {
1907 Send(new ViewHostMsg_SetTooltipText(routing_id_, UTF16ToWideHack(text),
1908 hint));
1909}
1910
[email protected]49fd9da2010-03-17 21:00:471911void RenderView::startDragging(const WebPoint& from, const WebDragData& data,
1912 WebDragOperationsMask allowed_ops) {
[email protected]c27ae592010-03-18 15:24:411913 startDragging(data, allowed_ops, WebImage(), WebPoint());
1914}
1915
1916void RenderView::startDragging(const WebDragData& data,
1917 WebDragOperationsMask mask,
1918 const WebImage& image,
1919 const WebPoint& imageOffset) {
1920#if WEBKIT_USING_SKIA
1921 SkBitmap bitmap(image.getSkBitmap());
1922#elif WEBKIT_USING_CG
1923 // Needs implementing: http://crbug.com/11457
1924 SkBitmap bitmap;
1925#endif
1926
[email protected]48c9cf2d2009-09-16 16:47:521927 Send(new ViewHostMsg_StartDragging(routing_id_,
1928 WebDropData(data),
[email protected]c27ae592010-03-18 15:24:411929 mask,
1930 bitmap,
1931 imageOffset));
[email protected]48c9cf2d2009-09-16 16:47:521932}
1933
[email protected]28b92df2009-09-25 17:35:451934bool RenderView::acceptsLoadDrops() {
1935 return renderer_preferences_.can_accept_load_drops;
1936}
1937
[email protected]48c9cf2d2009-09-16 16:47:521938void RenderView::focusNext() {
1939 Send(new ViewHostMsg_TakeFocus(routing_id_, false));
1940}
1941
1942void RenderView::focusPrevious() {
1943 Send(new ViewHostMsg_TakeFocus(routing_id_, true));
1944}
1945
1946void RenderView::navigateBackForwardSoon(int offset) {
1947 history_back_list_count_ += offset;
1948 history_forward_list_count_ -= offset;
1949
1950 Send(new ViewHostMsg_GoToEntryAtOffset(routing_id_, offset));
1951}
1952
1953int RenderView::historyBackListCount() {
1954 return history_back_list_count_;
1955}
1956
1957int RenderView::historyForwardListCount() {
1958 return history_forward_list_count_;
1959}
1960
1961void RenderView::didAddHistoryItem() {
1962 // We don't want to update the history length for the start page
1963 // navigation.
[email protected]26aa0482009-09-30 16:55:271964 WebFrame* main_frame = webview()->mainFrame();
[email protected]48c9cf2d2009-09-16 16:47:521965 DCHECK(main_frame != NULL);
1966
1967 WebDataSource* ds = main_frame->dataSource();
1968 DCHECK(ds != NULL);
1969
1970 NavigationState* navigation_state = NavigationState::FromDataSource(ds);
1971 DCHECK(navigation_state);
1972 if (navigation_state->transition_type() == PageTransition::START_PAGE)
1973 return;
1974
1975 history_back_list_count_++;
1976 history_forward_list_count_ = 0;
1977}
1978
[email protected]8922e1f2009-10-03 05:01:261979void RenderView::didUpdateInspectorSettings() {
1980 Send(new ViewHostMsg_UpdateInspectorSettings(
1981 routing_id_, webview()->inspectorSettings().utf8()));
1982}
1983
[email protected]acca2a12009-10-16 03:53:391984void RenderView::queryAutofillSuggestions(const WebNode& node,
1985 const WebString& name,
1986 const WebString& value) {
1987 static int query_counter = 0;
1988 autofill_query_id_ = query_counter++;
1989 autofill_query_node_ = node;
[email protected]95056b582010-02-18 01:29:241990 const WebKit::WebInputElement input_element =
1991 node.toConstElement<WebInputElement>();
[email protected]acca2a12009-10-16 03:53:391992 Send(new ViewHostMsg_QueryFormFieldAutofill(
[email protected]95056b582010-02-18 01:29:241993 routing_id_, autofill_query_id_, FormField(input_element)));
[email protected]acca2a12009-10-16 03:53:391994}
1995
1996void RenderView::removeAutofillSuggestions(const WebString& name,
1997 const WebString& value) {
1998 Send(new ViewHostMsg_RemoveAutofillEntry(routing_id_, name, value));
1999}
2000
[email protected]c83641732010-02-20 01:04:482001void RenderView::didAcceptAutoFillSuggestion(
2002 const WebKit::WebNode& node,
2003 const WebKit::WebString& name,
2004 const WebKit::WebString& label) {
2005 static int query_counter = 0;
2006 autofill_query_id_ = query_counter++;
2007
[email protected]45c6e532010-03-15 23:51:242008 webkit_glue::FormData form;
[email protected]c83641732010-02-20 01:04:482009 const WebInputElement element = node.toConstElement<WebInputElement>();
2010 if (!form_manager_.FindForm(element, &form))
2011 return;
2012
2013 Send(new ViewHostMsg_FillAutoFillFormData(
2014 routing_id_, autofill_query_id_, form, name, label));
2015}
2016
[email protected]79dbc662009-09-04 05:42:512017// WebKit::WebWidgetClient ----------------------------------------------------
2018
initial.commit09911bf2008-07-26 23:55:292019// We are supposed to get a single call to Show for a newly created RenderView
2020// that was created via RenderView::CreateWebView. So, we wait until this
2021// point to dispatch the ShowView message.
2022//
2023// This method provides us with the information about how to display the newly
2024// created RenderView (i.e., as a constrained popup or as a new tab).
2025//
[email protected]4873c7d2009-07-16 06:36:282026void RenderView::show(WebNavigationPolicy policy) {
initial.commit09911bf2008-07-26 23:55:292027 DCHECK(!did_show_) << "received extraneous Show call";
2028 DCHECK(opener_id_ != MSG_ROUTING_NONE);
2029
2030 if (did_show_)
2031 return;
2032 did_show_ = true;
2033
[email protected]28295ec2009-10-16 05:34:332034 // Force new windows to a popup if they were not opened with a user gesture.
2035 if (!opened_by_user_gesture_) {
2036 // We exempt background tabs for compat with older versions of Chrome.
2037 // TODO(darin): This seems bogus. These should have a user gesture, so
2038 // we probably don't need this check.
2039 if (policy != WebKit::WebNavigationPolicyNewBackgroundTab)
2040 policy = WebKit::WebNavigationPolicyNewPopup;
2041 }
2042
initial.commit09911bf2008-07-26 23:55:292043 // NOTE: initial_pos_ may still have its default values at this point, but
2044 // that's okay. It'll be ignored if disposition is not NEW_POPUP, or the
2045 // browser process will impose a default position otherwise.
[email protected]4873c7d2009-07-16 06:36:282046 Send(new ViewHostMsg_ShowView(opener_id_, routing_id_,
2047 NavigationPolicyToDisposition(policy), initial_pos_,
[email protected]7e7414ae2010-01-26 20:19:292048 opened_by_user_gesture_));
[email protected]2533ce12009-05-09 00:02:242049 SetPendingWindowRect(initial_pos_);
initial.commit09911bf2008-07-26 23:55:292050}
2051
[email protected]4873c7d2009-07-16 06:36:282052void RenderView::closeWidgetSoon() {
[email protected]2c4410d2009-05-06 23:46:222053 if (!popup_notification_visible_)
[email protected]4873c7d2009-07-16 06:36:282054 RenderWidget::closeWidgetSoon();
[email protected]634a6f92008-12-01 21:39:312055}
2056
[email protected]4873c7d2009-07-16 06:36:282057void RenderView::runModal() {
initial.commit09911bf2008-07-26 23:55:292058 DCHECK(did_show_) << "should already have shown the view";
2059
[email protected]c1f50aa2010-02-18 03:46:572060 // We must keep WebKit's shared timer running in this case in order to allow
2061 // showModalDialog to function properly.
2062 //
2063 // TODO(darin): WebKit should really be smarter about suppressing events and
2064 // timers so that we do not need to manage the shared timer in such a heavy
2065 // handed manner.
2066 //
2067 if (RenderThread::current()) // Will be NULL during unit tests.
2068 RenderThread::current()->DoNotSuspendWebKitSharedTimer();
2069
[email protected]12636df2009-09-28 22:32:212070 SendAndRunNestedMessageLoop(new ViewHostMsg_RunModal(routing_id_));
initial.commit09911bf2008-07-26 23:55:292071}
2072
[email protected]3d9689372009-09-10 04:29:172073// WebKit::WebFrameClient -----------------------------------------------------
2074
2075WebPlugin* RenderView::createPlugin(
2076 WebFrame* frame, const WebPluginParams& params) {
2077 return new webkit_glue::WebPluginImpl(frame, params, AsWeakPtr());
2078}
2079
2080WebWorker* RenderView::createWorker(WebFrame* frame, WebWorkerClient* client) {
2081 return new WebWorkerProxy(client, RenderThread::current(), routing_id_);
2082}
2083
[email protected]9c00f002009-11-05 22:37:422084WebSharedWorker* RenderView::createSharedWorker(
2085 WebFrame* frame, const WebURL& url, const WebString& name,
[email protected]30447b62009-11-13 01:13:372086 unsigned long long document_id) {
[email protected]9c00f002009-11-05 22:37:422087
[email protected]30447b62009-11-13 01:13:372088 int route_id = MSG_ROUTING_NONE;
[email protected]6de0bcf2010-02-17 22:00:512089 bool exists = false;
[email protected]30447b62009-11-13 01:13:372090 bool url_mismatch = false;
[email protected]6de0bcf2010-02-17 22:00:512091 ViewHostMsg_CreateWorker_Params params;
2092 params.url = url;
2093 params.is_shared = true;
2094 params.name = name;
2095 params.document_id = document_id;
2096 params.render_view_route_id = routing_id_;
2097 params.route_id = MSG_ROUTING_NONE;
[email protected]30447b62009-11-13 01:13:372098 Send(new ViewHostMsg_LookupSharedWorker(
[email protected]6de0bcf2010-02-17 22:00:512099 params, &exists, &route_id, &url_mismatch));
[email protected]30447b62009-11-13 01:13:372100 if (url_mismatch) {
2101 return NULL;
2102 } else {
2103 return new WebSharedWorkerProxy(RenderThread::current(),
[email protected]0791d3a2010-01-28 01:28:492104 document_id,
[email protected]6de0bcf2010-02-17 22:00:512105 exists,
[email protected]30447b62009-11-13 01:13:372106 route_id,
2107 routing_id_);
2108 }
[email protected]9c00f002009-11-05 22:37:422109}
2110
[email protected]3d9689372009-09-10 04:29:172111WebMediaPlayer* RenderView::createMediaPlayer(
2112 WebFrame* frame, WebMediaPlayerClient* client) {
2113 scoped_refptr<media::FilterFactoryCollection> factory =
2114 new media::FilterFactoryCollection();
2115 // Add in any custom filter factories first.
2116 const CommandLine* cmd_line = CommandLine::ForCurrentProcess();
2117 if (!cmd_line->HasSwitch(switches::kDisableAudio)) {
2118 // Add the chrome specific audio renderer.
2119 factory->AddFactory(
2120 AudioRendererImpl::CreateFactory(audio_message_filter()));
2121 }
2122
[email protected]80f584d92010-01-21 03:59:042123 WebApplicationCacheHostImpl* appcache_host =
2124 WebApplicationCacheHostImpl::FromFrame(frame);
2125
[email protected]3d9689372009-09-10 04:29:172126 // TODO(hclam): obtain the following parameters from |client|.
2127 webkit_glue::MediaResourceLoaderBridgeFactory* bridge_factory =
2128 new webkit_glue::MediaResourceLoaderBridgeFactory(
[email protected]810a52ef2010-01-08 01:22:152129 GURL(), // referrer
2130 "null", // frame origin
2131 "null", // main_frame_origin
[email protected]3d9689372009-09-10 04:29:172132 base::GetCurrentProcId(),
[email protected]80f584d92010-01-21 03:59:042133 appcache_host ? appcache_host->host_id() : appcache::kNoHostId,
[email protected]3d9689372009-09-10 04:29:172134 routing_id());
2135
[email protected]0436b9a2009-10-23 00:23:052136 // A simple data source that keeps all data in memory.
2137 media::FilterFactory* simple_data_source_factory =
2138 webkit_glue::SimpleDataSource::CreateFactory(MessageLoop::current(),
2139 bridge_factory);
2140 // A sophisticated data source that does memory caching.
2141 media::FilterFactory* buffered_data_source_factory =
2142 webkit_glue::BufferedDataSource::CreateFactory(MessageLoop::current(),
2143 bridge_factory);
2144 if (cmd_line->HasSwitch(switches::kSimpleDataSource)) {
2145 factory->AddFactory(simple_data_source_factory);
2146 factory->AddFactory(buffered_data_source_factory);
[email protected]3d9689372009-09-10 04:29:172147 } else {
[email protected]0436b9a2009-10-23 00:23:052148 factory->AddFactory(buffered_data_source_factory);
2149 factory->AddFactory(simple_data_source_factory);
[email protected]3d9689372009-09-10 04:29:172150 }
[email protected]8400e032010-02-26 18:50:112151
2152 webkit_glue::WebVideoRendererFactoryFactory* factory_factory = NULL;
2153 if (cmd_line->HasSwitch(switches::kEnableVideoLayering)) {
2154 factory_factory = new IPCVideoRenderer::FactoryFactory(routing_id_);
2155 } else {
2156 factory_factory = new webkit_glue::VideoRendererImpl::FactoryFactory();
2157 }
2158
2159 return new webkit_glue::WebMediaPlayerImpl(client, factory, factory_factory);
[email protected]3d9689372009-09-10 04:29:172160}
2161
[email protected]b921cfd22010-02-25 16:57:512162WebCookieJar* RenderView::cookieJar() {
2163 return &cookie_jar_;
2164}
2165
[email protected]3d9689372009-09-10 04:29:172166void RenderView::willClose(WebFrame* frame) {
2167 if (!frame->parent()) {
2168 const GURL& url = frame->url();
2169 if (url.SchemeIs("http") || url.SchemeIs("https"))
2170 DumpLoadHistograms();
2171 }
[email protected]fa7b6b542009-11-03 05:02:302172
2173 WebDataSource* ds = frame->dataSource();
2174 NavigationState* navigation_state = NavigationState::FromDataSource(ds);
2175 navigation_state->user_script_idle_scheduler()->Cancel();
[email protected]3d9689372009-09-10 04:29:172176}
2177
[email protected]684e4a42010-01-30 06:44:112178bool RenderView::allowPlugins(WebFrame* frame, bool enabled_per_settings) {
[email protected]8934a3b2010-02-25 00:34:002179 if (!enabled_per_settings)
2180 return false;
[email protected]c21f1d52010-03-04 03:19:432181 return AllowContentType(CONTENT_SETTINGS_TYPE_PLUGINS);
[email protected]684e4a42010-01-30 06:44:112182}
2183
2184bool RenderView::allowImages(WebFrame* frame, bool enabled_per_settings) {
[email protected]8934a3b2010-02-25 00:34:002185 if (!enabled_per_settings)
2186 return false;
2187 if (!AllowContentType(CONTENT_SETTINGS_TYPE_IMAGES)) {
2188 DidBlockContentType(CONTENT_SETTINGS_TYPE_IMAGES);
2189 return false;
2190 }
2191 return true;
[email protected]684e4a42010-01-30 06:44:112192}
2193
[email protected]3d9689372009-09-10 04:29:172194void RenderView::loadURLExternally(
2195 WebFrame* frame, const WebURLRequest& request,
2196 WebNavigationPolicy policy) {
[email protected]efce17b2009-09-11 18:04:592197 GURL referrer(request.httpHeaderField(WebString::fromUTF8("Referer")));
2198 if (policy == WebKit::WebNavigationPolicyDownload) {
2199 Send(new ViewHostMsg_DownloadUrl(routing_id_, request.url(), referrer));
2200 } else {
2201 OpenURL(request.url(), referrer, policy);
2202 }
[email protected]3d9689372009-09-10 04:29:172203}
2204
2205WebNavigationPolicy RenderView::decidePolicyForNavigation(
2206 WebFrame* frame, const WebURLRequest& request, WebNavigationType type,
[email protected]65b95cd2009-10-09 05:10:222207 const WebNode&, WebNavigationPolicy default_policy, bool is_redirect) {
[email protected]3d9689372009-09-10 04:29:172208 // Webkit is asking whether to navigate to a new URL.
2209 // This is fine normally, except if we're showing UI from one security
2210 // context and they're trying to navigate to a different context.
2211 const GURL& url = request.url();
2212
2213 // If the browser is interested, then give it a chance to look at top level
2214 // navigations
2215 if (renderer_preferences_.browser_handles_top_level_requests &&
2216 // Only send once.
2217 last_top_level_navigation_page_id_ != page_id_ &&
2218 // Not interested in reloads.
2219 type != WebKit::WebNavigationTypeReload &&
2220 type != WebKit::WebNavigationTypeFormSubmitted &&
2221 // Must be a top level frame.
2222 frame->parent() == NULL) {
2223 // Skip if navigation is on the same page (using '#').
2224 GURL frame_origin = GURL(frame->url()).GetOrigin();
2225 if (url.GetOrigin() != frame_origin || url.ref().empty()) {
2226 last_top_level_navigation_page_id_ = page_id_;
[email protected]b36a9f92009-10-19 17:34:572227 GURL referrer(request.httpHeaderField(WebString::fromUTF8("Referer")));
2228 OpenURL(url, referrer, default_policy);
[email protected]3d9689372009-09-10 04:29:172229 return WebKit::WebNavigationPolicyIgnore; // Suppress the load here.
2230 }
2231 }
2232
2233 // A content initiated navigation may have originated from a link-click,
2234 // script, drag-n-drop operation, etc.
2235 bool is_content_initiated =
2236 NavigationState::FromDataSource(frame->provisionalDataSource())->
2237 is_content_initiated();
2238
2239 // We only care about navigations that are within the current tab (as opposed
2240 // to, for example, opening a new window).
2241 // But we sometimes navigate to about:blank to clear a tab, and we want to
2242 // still allow that.
2243 if (default_policy == WebKit::WebNavigationPolicyCurrentTab &&
2244 is_content_initiated && frame->parent() == NULL &&
2245 !url.SchemeIs(chrome::kAboutScheme)) {
2246 // When we received such unsolicited navigations, we sometimes want to
2247 // punt them up to the browser to handle.
2248 if (BindingsPolicy::is_dom_ui_enabled(enabled_bindings_) ||
2249 BindingsPolicy::is_extension_enabled(enabled_bindings_) ||
2250 frame->isViewSourceModeEnabled() ||
2251 url.SchemeIs(chrome::kViewSourceScheme) ||
2252 url.SchemeIs(chrome::kPrintScheme)) {
2253 OpenURL(url, GURL(), default_policy);
2254 return WebKit::WebNavigationPolicyIgnore; // Suppress the load here.
2255 }
2256 }
2257
2258 // Detect when a page is "forking" a new tab that can be safely rendered in
2259 // its own process. This is done by sites like Gmail that try to open links
2260 // in new windows without script connections back to the original page. We
2261 // treat such cases as browser navigations (in which we will create a new
2262 // renderer for a cross-site navigation), rather than WebKit navigations.
2263 //
2264 // We use the following heuristic to decide whether to fork a new page in its
2265 // own process:
2266 // The parent page must open a new tab to about:blank, set the new tab's
2267 // window.opener to null, and then redirect the tab to a cross-site URL using
2268 // JavaScript.
[email protected]007a848b2009-10-26 15:55:462269 //
2270 // TODO(creis): Deprecate this logic once we can rely on rel=noreferrer
2271 // (see below).
[email protected]3d9689372009-09-10 04:29:172272 bool is_fork =
2273 // Must start from a tab showing about:blank, which is later redirected.
[email protected]e0d481582009-09-15 21:06:252274 GURL(frame->url()) == GURL(chrome::kAboutBlankURL) &&
[email protected]3d9689372009-09-10 04:29:172275 // Must be the first real navigation of the tab.
[email protected]48c9cf2d2009-09-16 16:47:522276 historyBackListCount() < 1 &&
2277 historyForwardListCount() < 1 &&
[email protected]3d9689372009-09-10 04:29:172278 // The parent page must have set the child's window.opener to null before
2279 // redirecting to the desired URL.
2280 frame->opener() == NULL &&
2281 // Must be a top-level frame.
2282 frame->parent() == NULL &&
2283 // Must not have issued the request from this page.
2284 is_content_initiated &&
2285 // Must be targeted at the current tab.
2286 default_policy == WebKit::WebNavigationPolicyCurrentTab &&
2287 // Must be a JavaScript navigation, which appears as "other".
2288 type == WebKit::WebNavigationTypeOther;
[email protected]007a848b2009-10-26 15:55:462289
2290 // Recognize if this navigation is from a link with rel=noreferrer and
2291 // target=_blank attributes, in which case the opener will be suppressed. If
2292 // so, it is safe to load cross-site pages in a separate process, so we
2293 // should let the browser handle it.
2294 bool is_noreferrer_and_blank_target =
2295 // Frame should be top level and not yet navigated.
2296 frame->parent() == NULL &&
2297 frame->url().isEmpty() &&
2298 historyBackListCount() < 1 &&
2299 historyForwardListCount() < 1 &&
2300 // Links with rel=noreferrer will have no Referer field, and their
2301 // resulting frame will have its window.opener suppressed.
2302 // TODO(creis): should add a request.httpReferrer() method to help avoid
2303 // typos on the unusual spelling of Referer.
2304 request.httpHeaderField(WebString::fromUTF8("Referer")).isNull() &&
2305 opener_suppressed_ &&
2306 frame->opener() == NULL &&
2307 // Links with target=_blank will have no name.
2308 frame->name().isNull() &&
2309 // Another frame (with a non-empty creator) should have initiated the
2310 // request, targeted at this frame.
2311 !creator_url_.is_empty() &&
2312 is_content_initiated &&
2313 default_policy == WebKit::WebNavigationPolicyCurrentTab &&
2314 type == WebKit::WebNavigationTypeOther;
2315
2316 if (is_fork || is_noreferrer_and_blank_target) {
[email protected]3d9689372009-09-10 04:29:172317 // Open the URL via the browser, not via WebKit.
2318 OpenURL(url, GURL(), default_policy);
2319 return WebKit::WebNavigationPolicyIgnore;
2320 }
2321
2322 return default_policy;
2323}
2324
[email protected]6069da8c2009-10-20 20:33:492325bool RenderView::canHandleRequest(
2326 WebFrame* frame, const WebURLRequest& request) {
2327 // We allow WebKit to think that everything can be handled even though
2328 // browser-side we limit what we load.
[email protected]7b7a7dc2009-10-19 02:23:342329 return true;
2330}
2331
[email protected]6069da8c2009-10-20 20:33:492332WebURLError RenderView::cannotHandleRequestError(
2333 WebFrame* frame, const WebURLRequest& request) {
2334 NOTREACHED(); // Since we said we can handle all requests.
2335 return WebURLError();
2336}
2337
2338WebURLError RenderView::cancelledError(
2339 WebFrame* frame, const WebURLRequest& request) {
2340 WebURLError error;
2341 error.domain = WebString::fromUTF8(net::kErrorDomain);
2342 error.reason = net::ERR_ABORTED;
2343 error.unreachableURL = request.url();
2344 return error;
[email protected]7b7a7dc2009-10-19 02:23:342345}
2346
2347void RenderView::unableToImplementPolicyWithError(
[email protected]6069da8c2009-10-20 20:33:492348 WebFrame*, const WebURLError&) {
2349 NOTREACHED(); // Since we said we can handle all requests.
[email protected]7b7a7dc2009-10-19 02:23:342350}
2351
[email protected]979c28b2009-11-07 01:30:482352void RenderView::willSubmitForm(WebFrame* frame, const WebFormElement& form) {
[email protected]3d9689372009-09-10 04:29:172353 NavigationState* navigation_state =
2354 NavigationState::FromDataSource(frame->provisionalDataSource());
2355
2356 if (navigation_state->transition_type() == PageTransition::LINK)
2357 navigation_state->set_transition_type(PageTransition::FORM_SUBMIT);
2358
2359 // Save these to be processed when the ensuing navigation is committed.
[email protected]ce0e250d2009-10-23 21:00:352360 WebSearchableFormData web_searchable_form_data(form);
2361 navigation_state->set_searchable_form_url(web_searchable_form_data.url());
2362 navigation_state->set_searchable_form_encoding(
[email protected]b7910b3a2010-01-13 18:33:212363 web_searchable_form_data.encoding().utf8());
[email protected]3d9689372009-09-10 04:29:172364 navigation_state->set_password_form_data(
2365 PasswordFormDomManager::CreatePasswordForm(form));
2366
[email protected]979c28b2009-11-07 01:30:482367 if (form.autoComplete()) {
[email protected]c54d269e2009-10-21 18:07:382368 scoped_ptr<FormFieldValues> form_values(FormFieldValues::Create(form));
2369 if (form_values.get())
[email protected]51bd36612009-10-20 22:49:472370 Send(new ViewHostMsg_FormFieldValuesSubmitted(routing_id_,
[email protected]c54d269e2009-10-21 18:07:382371 *form_values));
[email protected]3d9689372009-09-10 04:29:172372 }
2373}
2374
2375void RenderView::willPerformClientRedirect(
2376 WebFrame* frame, const WebURL& from, const WebURL& to, double interval,
2377 double fire_time) {
2378 // Ignore
2379}
2380
2381void RenderView::didCancelClientRedirect(WebFrame* frame) {
2382 // Ignore
2383}
2384
2385void RenderView::didCompleteClientRedirect(
2386 WebFrame* frame, const WebURL& from) {
2387 if (!frame->parent())
2388 completed_client_redirect_src_ = from;
2389}
2390
2391void RenderView::didCreateDataSource(WebFrame* frame, WebDataSource* ds) {
2392 // The rest of RenderView assumes that a WebDataSource will always have a
2393 // non-null NavigationState.
[email protected]a7ccc4d2010-01-27 08:14:482394 bool content_initiated = !pending_navigation_state_.get();
2395 NavigationState* state = content_initiated ?
2396 NavigationState::CreateContentInitiated() :
2397 pending_navigation_state_.release();
[email protected]4c1b6f0b2010-02-07 16:38:182398 if (content_initiated) {
2399 switch (ds->request().cachePolicy()) {
2400 case WebURLRequest::UseProtocolCachePolicy: // normal load.
2401 state->set_load_type(NavigationState::LINK_LOAD_NORMAL);
2402 break;
2403 case WebURLRequest::ReloadIgnoringCacheData: // reload.
2404 state->set_load_type(NavigationState::LINK_LOAD_RELOAD);
2405 break;
2406 case WebURLRequest::ReturnCacheDataElseLoad: // allow stale data.
2407 state->set_load_type(NavigationState::LINK_LOAD_CACHE_STALE_OK);
2408 break;
2409 case WebURLRequest::ReturnCacheDataDontLoad: // Don't re-post.
2410 state->set_load_type(NavigationState::LINK_LOAD_CACHE_ONLY);
2411 break;
2412 }
2413 }
[email protected]fa7b6b542009-11-03 05:02:302414
2415 state->set_user_script_idle_scheduler(
2416 new UserScriptIdleScheduler(this, frame));
2417 ds->setExtraData(state);
[email protected]3d9689372009-09-10 04:29:172418}
2419
2420void RenderView::didStartProvisionalLoad(WebFrame* frame) {
2421 WebDataSource* ds = frame->provisionalDataSource();
2422 NavigationState* navigation_state = NavigationState::FromDataSource(ds);
2423
2424 navigation_state->set_start_load_time(Time::Now());
2425
2426 // Update the request time if WebKit has better knowledge of it.
2427 if (navigation_state->request_time().is_null()) {
2428 double event_time = ds->triggeringEventTime();
2429 if (event_time != 0.0)
2430 navigation_state->set_request_time(Time::FromDoubleT(event_time));
2431 }
2432
2433 bool is_top_most = !frame->parent();
2434 if (is_top_most) {
2435 navigation_gesture_ = frame->isProcessingUserGesture() ?
2436 NavigationGestureUnknown : NavigationGestureAuto;
2437
2438 // Make sure redirect tracking state is clear for the new load.
2439 completed_client_redirect_src_ = GURL();
2440 } else if (frame->parent()->isLoading()) {
2441 // Take note of AUTO_SUBFRAME loads here, so that we can know how to
[email protected]4fb66842009-12-04 21:41:002442 // load an error page. See didFailProvisionalLoad.
[email protected]3d9689372009-09-10 04:29:172443 navigation_state->set_transition_type(PageTransition::AUTO_SUBFRAME);
2444 }
2445
2446 Send(new ViewHostMsg_DidStartProvisionalLoadForFrame(
2447 routing_id_, is_top_most, ds->request().url()));
2448}
2449
2450void RenderView::didReceiveServerRedirectForProvisionalLoad(WebFrame* frame) {
2451 if (frame->parent())
2452 return;
2453 // Received a redirect on the main frame.
2454 WebDataSource* data_source = frame->provisionalDataSource();
2455 if (!data_source) {
2456 // Should only be invoked when we have a data source.
2457 NOTREACHED();
2458 return;
2459 }
2460 std::vector<GURL> redirects;
2461 GetRedirectChain(data_source, &redirects);
2462 if (redirects.size() >= 2) {
[email protected]40bd6582009-12-04 23:49:512463 Send(new ViewHostMsg_DidRedirectProvisionalLoad(routing_id_, page_id_,
2464 redirects[redirects.size() - 2], redirects.back()));
[email protected]3d9689372009-09-10 04:29:172465 }
2466}
2467
[email protected]40bd6582009-12-04 23:49:512468void RenderView::didFailProvisionalLoad(WebFrame* frame,
2469 const WebURLError& error) {
[email protected]3d9689372009-09-10 04:29:172470 // Notify the browser that we failed a provisional load with an error.
2471 //
2472 // Note: It is important this notification occur before DidStopLoading so the
2473 // SSL manager can react to the provisional load failure before being
2474 // notified the load stopped.
2475 //
2476 WebDataSource* ds = frame->provisionalDataSource();
2477 DCHECK(ds);
2478
2479 const WebURLRequest& failed_request = ds->request();
2480
2481 bool show_repost_interstitial =
2482 (error.reason == net::ERR_CACHE_MISS &&
2483 EqualsASCII(failed_request.httpMethod(), "POST"));
2484 Send(new ViewHostMsg_DidFailProvisionalLoadWithError(
2485 routing_id_, !frame->parent(), error.reason, error.unreachableURL,
2486 show_repost_interstitial));
2487
2488 // Don't display an error page if this is simply a cancelled load. Aside
2489 // from being dumb, WebCore doesn't expect it and it will cause a crash.
2490 if (error.reason == net::ERR_ABORTED)
2491 return;
2492
2493 // Make sure we never show errors in view source mode.
2494 frame->enableViewSourceMode(false);
2495
2496 NavigationState* navigation_state = NavigationState::FromDataSource(ds);
2497
2498 // If this is a failed back/forward/reload navigation, then we need to do a
2499 // 'replace' load. This is necessary to avoid messing up session history.
2500 // Otherwise, we do a normal load, which simulates a 'go' navigation as far
2501 // as session history is concerned.
2502 //
2503 // AUTO_SUBFRAME loads should always be treated as loads that do not advance
2504 // the page id.
2505 //
2506 bool replace =
2507 navigation_state->pending_page_id() != -1 ||
2508 navigation_state->transition_type() == PageTransition::AUTO_SUBFRAME;
2509
2510 // If we failed on a browser initiated request, then make sure that our error
2511 // page load is regarded as the same browser initiated request.
2512 if (!navigation_state->is_content_initiated()) {
2513 pending_navigation_state_.reset(NavigationState::CreateBrowserInitiated(
2514 navigation_state->pending_page_id(),
2515 navigation_state->transition_type(),
2516 navigation_state->request_time()));
2517 }
2518
2519 // Provide the user with a more helpful error page?
2520 if (MaybeLoadAlternateErrorPage(frame, error, replace))
2521 return;
2522
2523 // Fallback to a local error page.
2524 LoadNavigationErrorPage(frame, failed_request, error, std::string(),
2525 replace);
2526}
2527
2528void RenderView::didReceiveDocumentData(
2529 WebFrame* frame, const char* data, size_t data_len,
2530 bool& prevent_default) {
2531 NavigationState* navigation_state =
2532 NavigationState::FromDataSource(frame->dataSource());
2533 if (!navigation_state->postpone_loading_data())
2534 return;
2535
2536 // We're going to call commitDocumentData ourselves...
2537 prevent_default = true;
2538
2539 // Continue buffering the response data for the original 404 page. If it
2540 // grows too large, then we'll just let it through.
2541 navigation_state->append_postponed_data(data, data_len);
2542 if (navigation_state->postponed_data().size() >= 512) {
2543 navigation_state->set_postpone_loading_data(false);
2544 frame->commitDocumentData(navigation_state->postponed_data().data(),
2545 navigation_state->postponed_data().size());
2546 navigation_state->clear_postponed_data();
2547 }
2548}
2549
[email protected]40bd6582009-12-04 23:49:512550void RenderView::didCommitProvisionalLoad(WebFrame* frame,
2551 bool is_new_navigation) {
[email protected]3d9689372009-09-10 04:29:172552 NavigationState* navigation_state =
2553 NavigationState::FromDataSource(frame->dataSource());
2554
[email protected]9e84a872010-02-09 18:23:422555 if (!frame->parent()) { // Main frame case.
2556 // Let the page translator know that the page has changed so it can clear
2557 // its states.
2558 page_translator_->MainFrameNavigated();
2559 }
2560
[email protected]3d9689372009-09-10 04:29:172561 navigation_state->set_commit_load_time(Time::Now());
2562 if (is_new_navigation) {
2563 // When we perform a new navigation, we need to update the previous session
2564 // history entry with state for the page we are leaving.
2565 UpdateSessionHistory(frame);
2566
2567 // We bump our Page ID to correspond with the new session history entry.
2568 page_id_ = next_page_id_++;
2569
2570 MessageLoop::current()->PostDelayedTask(FROM_HERE,
2571 method_factory_.NewRunnableMethod(&RenderView::CapturePageInfo,
2572 page_id_, true),
2573 kDelayForForcedCaptureMs);
2574 } else {
2575 // Inspect the navigation_state on this frame to see if the navigation
2576 // corresponds to a session history navigation... Note: |frame| may or
2577 // may not be the toplevel frame, but for the case of capturing session
2578 // history, the first committed frame suffices. We keep track of whether
2579 // we've seen this commit before so that only capture session history once
2580 // per navigation.
2581 //
2582 // Note that we need to check if the page ID changed. In the case of a
2583 // reload, the page ID doesn't change, and UpdateSessionHistory gets the
2584 // previous URL and the current page ID, which would be wrong.
2585 if (navigation_state->pending_page_id() != -1 &&
2586 navigation_state->pending_page_id() != page_id_ &&
2587 !navigation_state->request_committed()) {
2588 // This is a successful session history navigation!
2589 UpdateSessionHistory(frame);
2590 page_id_ = navigation_state->pending_page_id();
2591 }
2592 }
2593
2594 // Remember that we've already processed this request, so we don't update
2595 // the session history again. We do this regardless of whether this is
2596 // a session history navigation, because if we attempted a session history
2597 // navigation without valid HistoryItem state, WebCore will think it is a
2598 // new navigation.
2599 navigation_state->set_request_committed(true);
2600
2601 UpdateURL(frame);
2602
2603 // If this committed load was initiated by a client redirect, we're
2604 // at the last stop now, so clear it.
2605 completed_client_redirect_src_ = GURL();
2606
2607 // Check whether we have new encoding name.
[email protected]26aa0482009-09-30 16:55:272608 UpdateEncoding(frame, frame->view()->pageEncoding().utf8());
[email protected]3d9689372009-09-10 04:29:172609}
2610
2611void RenderView::didClearWindowObject(WebFrame* frame) {
2612 if (BindingsPolicy::is_dom_automation_enabled(enabled_bindings_))
2613 BindDOMAutomationController(frame);
2614 if (BindingsPolicy::is_dom_ui_enabled(enabled_bindings_)) {
2615 dom_ui_bindings_.set_message_sender(this);
2616 dom_ui_bindings_.set_routing_id(routing_id_);
2617 dom_ui_bindings_.BindToJavascript(frame, L"chrome");
2618 }
2619 if (BindingsPolicy::is_external_host_enabled(enabled_bindings_)) {
2620 external_host_bindings_.set_message_sender(this);
2621 external_host_bindings_.set_routing_id(routing_id_);
2622 external_host_bindings_.BindToJavascript(frame, L"externalHost");
2623 }
2624}
2625
2626void RenderView::didCreateDocumentElement(WebFrame* frame) {
2627 if (RenderThread::current()) { // Will be NULL during unit tests.
2628 RenderThread::current()->user_script_slave()->InjectScripts(
2629 frame, UserScript::DOCUMENT_START);
2630 }
[email protected]078b34612009-09-19 19:31:512631 if (view_type_ == ViewType::EXTENSION_TOOLSTRIP ||
2632 view_type_ == ViewType::EXTENSION_MOLE) {
2633 InjectToolstripCSS();
2634 ExtensionProcessBindings::SetViewType(webview(), view_type_);
2635 }
[email protected]3d9689372009-09-10 04:29:172636
2637 // Notify the browser about non-blank documents loading in the top frame.
2638 GURL url = frame->url();
[email protected]e0d481582009-09-15 21:06:252639 if (url.is_valid() && url.spec() != chrome::kAboutBlankURL) {
[email protected]26aa0482009-09-30 16:55:272640 if (frame == webview()->mainFrame())
[email protected]3d9689372009-09-10 04:29:172641 Send(new ViewHostMsg_DocumentAvailableInMainFrame(routing_id_));
2642 }
2643}
2644
2645void RenderView::didReceiveTitle(WebFrame* frame, const WebString& title) {
2646 UpdateTitle(frame, title);
2647
2648 // Also check whether we have new encoding name.
[email protected]26aa0482009-09-30 16:55:272649 UpdateEncoding(frame, frame->view()->pageEncoding().utf8());
[email protected]3d9689372009-09-10 04:29:172650}
2651
2652void RenderView::didFinishDocumentLoad(WebFrame* frame) {
2653 WebDataSource* ds = frame->dataSource();
2654 NavigationState* navigation_state = NavigationState::FromDataSource(ds);
2655 DCHECK(navigation_state);
2656 navigation_state->set_finish_document_load_time(Time::Now());
2657
2658 Send(new ViewHostMsg_DocumentLoadedInFrame(routing_id_));
2659
[email protected]e9e07992010-02-17 21:04:362660 // The document has now been fully loaded. Scan for forms to be sent up to
2661 // the browser.
2662 // TODO(jhawkins): Make these use the FormManager.
[email protected]c83641732010-02-20 01:04:482663 form_manager_.ExtractForms(frame);
[email protected]e9e07992010-02-17 21:04:362664 SendForms(frame);
[email protected]3d9689372009-09-10 04:29:172665 SendPasswordForms(frame);
2666
2667 // Check whether we have new encoding name.
[email protected]26aa0482009-09-30 16:55:272668 UpdateEncoding(frame, frame->view()->pageEncoding().utf8());
[email protected]3d9689372009-09-10 04:29:172669
2670 if (RenderThread::current()) { // Will be NULL during unit tests.
2671 RenderThread::current()->user_script_slave()->InjectScripts(
2672 frame, UserScript::DOCUMENT_END);
2673 }
[email protected]fa7b6b542009-11-03 05:02:302674
2675 navigation_state->user_script_idle_scheduler()->DidFinishDocumentLoad();
[email protected]9e84a872010-02-09 18:23:422676
2677 if (page_translator_->IsPageTranslated())
2678 page_translator_->TranslateFrame(frame);
[email protected]fa7b6b542009-11-03 05:02:302679}
2680
2681void RenderView::OnUserScriptIdleTriggered(WebFrame* frame) {
2682 if (RenderThread::current()) { // Will be NULL during unit tests.
2683 RenderThread::current()->user_script_slave()->InjectScripts(
2684 frame, UserScript::DOCUMENT_IDLE);
2685 }
2686
2687 WebFrame* main_frame = webview()->mainFrame();
2688 if (frame == main_frame) {
2689 while (!pending_code_execution_queue_.empty()) {
[email protected]61f5a7b2009-12-22 22:21:202690 linked_ptr<ViewMsg_ExecuteCode_Params>& params =
[email protected]fa7b6b542009-11-03 05:02:302691 pending_code_execution_queue_.front();
[email protected]61f5a7b2009-12-22 22:21:202692 ExecuteCodeImpl(main_frame, *params);
[email protected]fa7b6b542009-11-03 05:02:302693 pending_code_execution_queue_.pop();
2694 }
2695 }
[email protected]3d9689372009-09-10 04:29:172696}
2697
2698void RenderView::didHandleOnloadEvents(WebFrame* frame) {
2699 // Ignore
2700}
2701
2702void RenderView::didFailLoad(WebFrame* frame, const WebURLError& error) {
2703 // Ignore
2704}
2705
2706void RenderView::didFinishLoad(WebFrame* frame) {
2707 WebDataSource* ds = frame->dataSource();
2708 NavigationState* navigation_state = NavigationState::FromDataSource(ds);
2709 DCHECK(navigation_state);
2710 navigation_state->set_finish_load_time(Time::Now());
[email protected]fa7b6b542009-11-03 05:02:302711 navigation_state->user_script_idle_scheduler()->DidFinishLoad();
[email protected]3d9689372009-09-10 04:29:172712}
2713
[email protected]ccbe04e2010-03-17 17:58:432714void RenderView::didNavigateWithinPage(
[email protected]3d9689372009-09-10 04:29:172715 WebFrame* frame, bool is_new_navigation) {
[email protected]f6c2459d2010-02-24 22:34:062716
2717 // Determine if the UserScriptIdleScheduler already ran scripts on this page,
2718 // since a new one gets created by didCreateDataSource.
2719 NavigationState* state =
2720 NavigationState::FromDataSource(frame->dataSource());
2721 bool idle_scheduler_ran = state->user_script_idle_scheduler()->has_run();
2722
[email protected]3d9689372009-09-10 04:29:172723 // If this was a reference fragment navigation that we initiated, then we
2724 // could end up having a non-null pending navigation state. We just need to
2725 // update the ExtraData on the datasource so that others who read the
2726 // ExtraData will get the new NavigationState. Similarly, if we did not
2727 // initiate this navigation, then we need to take care to reset any pre-
2728 // existing navigation state to a content-initiated navigation state.
2729 // DidCreateDataSource conveniently takes care of this for us.
2730 didCreateDataSource(frame, frame->dataSource());
2731
[email protected]f6c2459d2010-02-24 22:34:062732 if (idle_scheduler_ran) {
2733 // Update the new UserScriptIdleScheduler so we don't re-run scripts.
2734 NavigationState* new_state =
2735 NavigationState::FromDataSource(frame->dataSource());
2736 new_state->user_script_idle_scheduler()->set_has_run(true);
2737 }
2738
[email protected]3d9689372009-09-10 04:29:172739 didCommitProvisionalLoad(frame, is_new_navigation);
2740
[email protected]26aa0482009-09-30 16:55:272741 UpdateTitle(frame, frame->view()->mainFrame()->dataSource()->pageTitle());
[email protected]3d9689372009-09-10 04:29:172742}
2743
[email protected]476b6f82009-09-10 21:00:592744void RenderView::didUpdateCurrentHistoryItem(WebFrame* frame) {
[email protected]882daa92009-11-05 16:31:312745 StartNavStateSyncTimerIfNecessary();
[email protected]476b6f82009-09-10 21:00:592746}
2747
[email protected]3d9689372009-09-10 04:29:172748void RenderView::assignIdentifierToRequest(
2749 WebFrame* frame, unsigned identifier, const WebURLRequest& request) {
2750 // Ignore
2751}
2752
2753void RenderView::willSendRequest(
2754 WebFrame* frame, unsigned identifier, WebURLRequest& request,
2755 const WebURLResponse& redirect_response) {
[email protected]5e369672009-11-03 23:48:302756 WebFrame* top_frame = frame->top();
2757 if (!top_frame)
2758 top_frame = frame;
2759 WebDataSource* data_source = top_frame->provisionalDataSource();
2760 if (!data_source)
2761 data_source = top_frame->dataSource();
2762 if (data_source) {
2763 NavigationState* state = NavigationState::FromDataSource(data_source);
2764 if (state && state->is_cache_policy_override_set())
2765 request.setCachePolicy(state->cache_policy_override());
2766 }
[email protected]3d9689372009-09-10 04:29:172767 request.setRequestorID(routing_id_);
[email protected]c5bbc2452010-03-08 08:33:502768 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kNoReferrers))
[email protected]7deade42010-03-05 09:33:132769 request.clearHTTPHeaderField("Referer");
[email protected]3d9689372009-09-10 04:29:172770}
2771
2772void RenderView::didReceiveResponse(
2773 WebFrame* frame, unsigned identifier, const WebURLResponse& response) {
[email protected]3d9689372009-09-10 04:29:172774 // Only do this for responses that correspond to a provisional data source
2775 // of the top-most frame. If we have a provisional data source, then we
2776 // can't have any sub-resources yet, so we know that this response must
2777 // correspond to a frame load.
2778 if (!frame->provisionalDataSource() || frame->parent())
2779 return;
2780
2781 // If we are in view source mode, then just let the user see the source of
2782 // the server's 404 error page.
2783 if (frame->isViewSourceModeEnabled())
2784 return;
2785
[email protected]f48013be2010-01-14 22:07:452786 // Record that this was a page loaded over SPDY.
2787 if (response.wasFetchedViaSPDY()) {
2788 NavigationState* navigation_state =
2789 NavigationState::FromDataSource(frame->provisionalDataSource());
2790 navigation_state->set_was_fetched_via_spdy(true);
2791 }
2792
2793 // Consider loading an alternate error page for 404 responses.
2794 if (response.httpStatusCode() != 404)
2795 return;
2796
[email protected]3d9689372009-09-10 04:29:172797 // Can we even load an alternate error page for this URL?
2798 if (!GetAlternateErrorPageURL(response.url(), HTTP_404).is_valid())
2799 return;
2800
2801 NavigationState* navigation_state =
2802 NavigationState::FromDataSource(frame->provisionalDataSource());
2803 navigation_state->set_postpone_loading_data(true);
2804 navigation_state->clear_postponed_data();
2805}
2806
2807void RenderView::didFinishResourceLoad(
2808 WebFrame* frame, unsigned identifier) {
2809 NavigationState* navigation_state =
2810 NavigationState::FromDataSource(frame->dataSource());
2811 if (!navigation_state->postpone_loading_data())
2812 return;
2813
2814 // The server returned a 404 and the content was < 512 bytes (which we
2815 // suppressed). Go ahead and fetch the alternate page content.
2816
2817 const GURL& frame_url = frame->url();
2818
2819 const GURL& error_page_url = GetAlternateErrorPageURL(frame_url, HTTP_404);
2820 DCHECK(error_page_url.is_valid());
2821
2822 WebURLError original_error;
2823 original_error.unreachableURL = frame_url;
2824
2825 navigation_state->set_alt_error_page_fetcher(
2826 new AltErrorPageResourceFetcher(
2827 error_page_url, frame, original_error,
2828 NewCallback(this, &RenderView::AltErrorPageFinished)));
2829}
2830
2831void RenderView::didFailResourceLoad(
2832 WebFrame* frame, unsigned identifier, const WebURLError& error) {
2833 // Ignore
2834}
2835
2836void RenderView::didLoadResourceFromMemoryCache(
2837 WebFrame* frame, const WebURLRequest& request,
2838 const WebURLResponse& response) {
2839 // Let the browser know we loaded a resource from the memory cache. This
2840 // message is needed to display the correct SSL indicators.
2841 Send(new ViewHostMsg_DidLoadResourceFromMemoryCache(
2842 routing_id_,
2843 request.url(),
[email protected]91733b62009-09-18 06:21:092844 frame->securityOrigin().toString().utf8(),
2845 frame->top()->securityOrigin().toString().utf8(),
[email protected]3d9689372009-09-10 04:29:172846 response.securityInfo()));
2847}
2848
[email protected]6069da8c2009-10-20 20:33:492849void RenderView::didDisplayInsecureContent(WebFrame* frame) {
[email protected]e3d60e5d2009-09-25 21:08:292850 Send(new ViewHostMsg_DidDisplayInsecureContent(routing_id_));
2851}
2852
2853void RenderView::didRunInsecureContent(
2854 WebFrame* frame, const WebSecurityOrigin& origin) {
2855 Send(new ViewHostMsg_DidRunInsecureContent(
2856 routing_id_,
2857 origin.toString().utf8()));
2858}
2859
[email protected]7ea093ba2009-11-03 05:54:592860bool RenderView::allowScript(WebFrame* frame, bool enabled_per_settings) {
[email protected]8934a3b2010-02-25 00:34:002861 if (enabled_per_settings)
2862 return AllowContentType(CONTENT_SETTINGS_TYPE_JAVASCRIPT);
[email protected]7ea093ba2009-11-03 05:54:592863
2864 WebSecurityOrigin origin = frame->securityOrigin();
2865 if (origin.isEmpty())
2866 return false; // Uninitialized document?
2867
2868 if (EqualsASCII(origin.protocol(), chrome::kChromeUIScheme))
2869 return true; // Browser UI elements should still work.
2870
2871 // If the scheme is ftp: or file:, an empty file name indicates a directory
2872 // listing, which requires JavaScript to function properly.
2873 GURL frame_url = frame->url();
2874 const char* kDirProtocols[] = { "ftp", "file" };
2875 for (size_t i = 0; i < arraysize(kDirProtocols); ++i) {
2876 if (EqualsASCII(origin.protocol(), kDirProtocols[i])) {
2877 return frame_url.SchemeIs(kDirProtocols[i]) &&
2878 frame_url.ExtractFileName().empty();
2879 }
2880 }
2881
2882 return false; // Other protocols fall through here.
2883}
2884
[email protected]8934a3b2010-02-25 00:34:002885void RenderView::didNotAllowScript(WebKit::WebFrame* frame) {
2886 DidBlockContentType(CONTENT_SETTINGS_TYPE_JAVASCRIPT);
2887}
2888
[email protected]c21f1d52010-03-04 03:19:432889void RenderView::didNotAllowPlugins(WebKit::WebFrame* frame) {
2890 DidBlockContentType(CONTENT_SETTINGS_TYPE_PLUGINS);
2891}
2892
[email protected]3d9689372009-09-10 04:29:172893void RenderView::didExhaustMemoryAvailableForScript(WebFrame* frame) {
2894 Send(new ViewHostMsg_JSOutOfMemory(routing_id_));
2895}
2896
[email protected]0c882b282009-10-07 17:01:282897void RenderView::didCreateScriptContext(WebFrame* frame) {
2898 EventBindings::HandleContextCreated(frame, false);
2899}
2900
2901void RenderView::didDestroyScriptContext(WebFrame* frame) {
2902 EventBindings::HandleContextDestroyed(frame);
2903}
2904
2905void RenderView::didCreateIsolatedScriptContext(WebFrame* frame) {
2906 EventBindings::HandleContextCreated(frame, true);
2907}
2908
[email protected]ab9eabac2010-03-16 16:54:102909void RenderView::didMakeCrossFrameAccess(WebFrame* frame,
2910 bool cross_origin,
2911 const WebString& property,
2912 unsigned long long event_id) {
2913 // TODO(johnnyg): track the individual properties and repeat event_ids.
2914 if (cross_origin)
2915 cross_origin_access_count_++;
2916 else
2917 same_origin_access_count_++;
2918}
2919
[email protected]3d9689372009-09-10 04:29:172920void RenderView::didChangeContentsSize(WebFrame* frame, const WebSize& size) {
[email protected]d8a179c2010-01-31 00:58:142921 CheckPreferredSize();
2922}
2923
2924void RenderView::CheckPreferredSize() {
[email protected]3d9689372009-09-10 04:29:172925 // We don't always want to send the change messages over IPC, only if we've
[email protected]ab32b16c2009-10-16 14:57:252926 // be put in that mode by getting a |ViewMsg_EnablePreferredSizeChangedMode|
[email protected]3d9689372009-09-10 04:29:172927 // message.
[email protected]ab32b16c2009-10-16 14:57:252928 if (send_preferred_size_changes_) {
[email protected]3d9689372009-09-10 04:29:172929 // WebCore likes to tell us things have changed even when they haven't, so
[email protected]ab32b16c2009-10-16 14:57:252930 // cache the width and height and only send the IPC message when we're sure
2931 // they're different.
[email protected]26aa0482009-09-30 16:55:272932 int width = webview()->mainFrame()->contentsPreferredWidth();
[email protected]440a52a2009-11-18 07:23:392933 int height = webview()->mainFrame()->documentElementScrollHeight();
[email protected]c27324b2009-11-19 22:44:292934
[email protected]ab32b16c2009-10-16 14:57:252935 if (width != preferred_size_.width() ||
[email protected]440a52a2009-11-18 07:23:392936 height != preferred_size_.height()) {
[email protected]ab32b16c2009-10-16 14:57:252937 preferred_size_.set_width(width);
[email protected]440a52a2009-11-18 07:23:392938 preferred_size_.set_height(height);
[email protected]ab32b16c2009-10-16 14:57:252939
[email protected]ab32b16c2009-10-16 14:57:252940 Send(new ViewHostMsg_DidContentsPreferredSizeChange(routing_id_,
2941 preferred_size_));
[email protected]3d9689372009-09-10 04:29:172942 }
2943 }
2944}
2945
[email protected]143dcd592009-11-06 21:33:492946void RenderView::didChangeScrollOffset(WebFrame* frame) {
2947 StartNavStateSyncTimerIfNecessary();
2948}
2949
[email protected]8922e1f2009-10-03 05:01:262950void RenderView::reportFindInPageMatchCount(int request_id, int count,
2951 bool final_update) {
2952 // If we have a message that has been queued up, then we should just replace
2953 // it. The ACK from the browser will make sure it gets sent when the browser
2954 // wants it.
2955 if (queued_find_reply_message_.get()) {
2956 IPC::Message* msg = new ViewHostMsg_Find_Reply(
2957 routing_id_,
2958 request_id,
2959 count,
2960 gfx::Rect(),
2961 -1, // Don't update active match ordinal.
2962 final_update);
2963 queued_find_reply_message_.reset(msg);
2964 } else {
2965 // Send the search result over to the browser process.
2966 Send(new ViewHostMsg_Find_Reply(
2967 routing_id_,
2968 request_id,
2969 count,
2970 gfx::Rect(),
2971 -1, // // Don't update active match ordinal.
2972 final_update));
2973 }
2974}
2975
2976void RenderView::reportFindInPageSelection(int request_id,
2977 int active_match_ordinal,
2978 const WebRect& selection_rect) {
2979 // Send the search result over to the browser process.
2980 Send(new ViewHostMsg_Find_Reply(routing_id_,
2981 request_id,
2982 -1,
2983 selection_rect,
2984 active_match_ordinal,
2985 false));
2986}
2987
[email protected]79dbc662009-09-04 05:42:512988// webkit_glue::WebPluginPageDelegate -----------------------------------------
2989
[email protected]f103ab72009-09-02 17:10:592990webkit_glue::WebPluginDelegate* RenderView::CreatePluginDelegate(
2991 const GURL& url,
2992 const std::string& mime_type,
[email protected]f103ab72009-09-02 17:10:592993 std::string* actual_mime_type) {
2994 if (!PluginChannelHost::IsListening())
2995 return NULL;
2996
2997 GURL policy_url;
[email protected]26aa0482009-09-30 16:55:272998 WebFrame* main_frame = webview()->mainFrame();
[email protected]f103ab72009-09-02 17:10:592999 if (main_frame)
3000 policy_url = main_frame->url();
3001
3002 FilePath path;
[email protected]610c0892009-09-08 19:46:183003 render_thread_->Send(new ViewHostMsg_GetPluginPath(
3004 url, policy_url, mime_type, &path, actual_mime_type));
[email protected]f103ab72009-09-02 17:10:593005 if (path.value().empty())
3006 return NULL;
3007
3008 const std::string* mime_type_to_use;
3009 if (!actual_mime_type->empty())
3010 mime_type_to_use = actual_mime_type;
3011 else
3012 mime_type_to_use = &mime_type;
3013
[email protected]d2139662009-12-10 03:21:143014 bool use_pepper_host = false;
[email protected]00c39612010-03-06 02:53:283015 bool in_process_plugin = RenderProcess::current()->UseInProcessPlugins();
[email protected]d2139662009-12-10 03:21:143016 // Check for trusted Pepper plugins.
[email protected]26e8d5e2009-10-13 02:47:163017 const char kPepperPrefix[] = "pepper-";
3018 if (StartsWithASCII(*mime_type_to_use, kPepperPrefix, true)) {
[email protected]d2139662009-12-10 03:21:143019 if (CommandLine::ForCurrentProcess()->
3020 HasSwitch(switches::kInternalPepper)) {
3021 in_process_plugin = true;
3022 use_pepper_host = true;
3023 } else {
3024 // In process Pepper plugins must be explicitly enabled.
3025 return NULL;
3026 }
[email protected]26e8d5e2009-10-13 02:47:163027 }
[email protected]d2139662009-12-10 03:21:143028 // Check for Native Client modules.
[email protected]d032f492009-09-29 00:33:463029 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kInternalNaCl)) {
3030 if (mime_type == "application/x-nacl-srpc") {
3031 in_process_plugin = true;
[email protected]d2139662009-12-10 03:21:143032 use_pepper_host = true;
[email protected]d032f492009-09-29 00:33:463033 }
3034 }
3035 if (in_process_plugin) {
[email protected]d2139662009-12-10 03:21:143036 if (use_pepper_host) {
[email protected]00c39612010-03-06 02:53:283037 WebPluginDelegatePepper* pepper_plugin =
3038 WebPluginDelegatePepper::Create(path, *mime_type_to_use,
3039 AsWeakPtr());
3040 current_pepper_plugins_.insert(pepper_plugin);
3041 return pepper_plugin;
[email protected]d2139662009-12-10 03:21:143042 } else {
[email protected]6876dff2010-01-15 19:38:093043#if defined(OS_WIN) // In-proc plugins aren't supported on Linux or Mac.
[email protected]d2139662009-12-10 03:21:143044 return WebPluginDelegateImpl::Create(
3045 path, *mime_type_to_use, gfx::NativeViewFromId(host_window_));
[email protected]6876dff2010-01-15 19:38:093046#else
[email protected]596b2c42010-01-14 20:40:433047 NOTIMPLEMENTED();
3048 return NULL;
[email protected]7b6616f2010-01-14 18:07:553049#endif
[email protected]6876dff2010-01-15 19:38:093050 }
[email protected]f103ab72009-09-02 17:10:593051 }
3052
[email protected]610c0892009-09-08 19:46:183053 return new WebPluginDelegateProxy(*mime_type_to_use, AsWeakPtr());
[email protected]f103ab72009-09-02 17:10:593054}
3055
3056void RenderView::CreatedPluginWindow(gfx::PluginWindowHandle window) {
[email protected]6981f7f2010-03-09 00:53:033057#if defined(USE_X11)
[email protected]f103ab72009-09-02 17:10:593058 RenderThread::current()->Send(new ViewHostMsg_CreatePluginContainer(
3059 routing_id(), window));
3060#endif
3061}
3062
3063void RenderView::WillDestroyPluginWindow(gfx::PluginWindowHandle window) {
[email protected]6981f7f2010-03-09 00:53:033064#if defined(USE_X11)
[email protected]f103ab72009-09-02 17:10:593065 RenderThread::current()->Send(new ViewHostMsg_DestroyPluginContainer(
3066 routing_id(), window));
3067#endif
3068 CleanupWindowInPluginMoves(window);
3069}
3070
3071void RenderView::DidMovePlugin(const webkit_glue::WebPluginGeometry& move) {
3072 SchedulePluginMove(move);
3073}
3074
3075void RenderView::DidStartLoadingForPlugin() {
3076 // TODO(darin): Make is_loading_ be a counter!
[email protected]48c9cf2d2009-09-16 16:47:523077 didStartLoading();
[email protected]f103ab72009-09-02 17:10:593078}
3079
3080void RenderView::DidStopLoadingForPlugin() {
3081 // TODO(darin): Make is_loading_ be a counter!
[email protected]48c9cf2d2009-09-16 16:47:523082 didStopLoading();
[email protected]f103ab72009-09-02 17:10:593083}
3084
3085void RenderView::ShowModalHTMLDialogForPlugin(
3086 const GURL& url,
3087 const gfx::Size& size,
3088 const std::string& json_arguments,
3089 std::string* json_retval) {
[email protected]12636df2009-09-28 22:32:213090 SendAndRunNestedMessageLoop(new ViewHostMsg_ShowModalHTMLDialog(
[email protected]f103ab72009-09-02 17:10:593091 routing_id_, url, size.width(), size.height(), json_arguments,
[email protected]12636df2009-09-28 22:32:213092 json_retval));
[email protected]f103ab72009-09-02 17:10:593093}
3094
[email protected]b921cfd22010-02-25 16:57:513095WebCookieJar* RenderView::GetCookieJar() {
3096 return &cookie_jar_;
3097}
3098
3099void RenderView::PageTranslated(int page_id,
3100 const std::string& original_lang,
3101 const std::string& target_lang) {
3102 Send(new ViewHostMsg_PageTranslated(routing_id_, page_id_,
3103 original_lang, target_lang));
3104}
3105
initial.commit09911bf2008-07-26 23:55:293106void RenderView::SyncNavigationState() {
3107 if (!webview())
3108 return;
3109
[email protected]26aa0482009-09-30 16:55:273110 const WebHistoryItem& item = webview()->mainFrame()->currentHistoryItem();
[email protected]ca948a22009-06-25 19:36:173111 if (item.isNull())
initial.commit09911bf2008-07-26 23:55:293112 return;
[email protected]ca948a22009-06-25 19:36:173113
3114 Send(new ViewHostMsg_UpdateState(
3115 routing_id_, page_id_, webkit_glue::HistoryItemToString(item)));
initial.commit09911bf2008-07-26 23:55:293116}
3117
[email protected]b0950a72009-09-29 23:16:173118bool RenderView::DownloadImage(int id, const GURL& image_url, int image_size) {
3119 // Make sure webview was not shut down.
3120 if (!webview())
3121 return false;
3122 // Create an image resource fetcher and assign it with a call back object.
3123 image_fetchers_.insert(new ImageResourceFetcher(
[email protected]26aa0482009-09-30 16:55:273124 image_url, webview()->mainFrame(), id, image_size,
[email protected]b0950a72009-09-29 23:16:173125 NewCallback(this, &RenderView::DidDownloadImage)));
3126 return true;
3127}
3128
3129void RenderView::DidDownloadImage(ImageResourceFetcher* fetcher,
initial.commit09911bf2008-07-26 23:55:293130 const SkBitmap& image) {
[email protected]b0950a72009-09-29 23:16:173131 // Notify requester of image download status.
[email protected]51bd36612009-10-20 22:49:473132 Send(new ViewHostMsg_DidDownloadFavIcon(routing_id_,
3133 fetcher->id(),
3134 fetcher->image_url(),
3135 image.isNull(),
3136 image));
[email protected]b0950a72009-09-29 23:16:173137 // Dispose of the image fetcher.
3138 DCHECK(image_fetchers_.find(fetcher) != image_fetchers_.end());
3139 image_fetchers_.erase(fetcher);
3140 // We're in the callback from the ImageResourceFetcher, best to delay
3141 // deletion.
3142 MessageLoop::current()->DeleteSoon(FROM_HERE, fetcher);
initial.commit09911bf2008-07-26 23:55:293143}
3144
[email protected]bf5c2ff392009-07-08 16:24:333145void RenderView::OnDownloadFavIcon(int id,
3146 const GURL& image_url,
3147 int image_size) {
[email protected]f11ca0732009-04-11 00:09:343148 bool data_image_failed = false;
3149 if (image_url.SchemeIs("data")) {
3150 SkBitmap data_image = ImageFromDataUrl(image_url);
3151 data_image_failed = data_image.empty();
3152 if (!data_image_failed) {
[email protected]bf5c2ff392009-07-08 16:24:333153 Send(new ViewHostMsg_DidDownloadFavIcon(routing_id_, id, image_url, false,
3154 data_image));
[email protected]f11ca0732009-04-11 00:09:343155 }
3156 }
3157
[email protected]bf5c2ff392009-07-08 16:24:333158 if (data_image_failed ||
[email protected]b0950a72009-09-29 23:16:173159 !DownloadImage(id, image_url, image_size)) {
[email protected]bf5c2ff392009-07-08 16:24:333160 Send(new ViewHostMsg_DidDownloadFavIcon(routing_id_, id, image_url, true,
3161 SkBitmap()));
3162 }
initial.commit09911bf2008-07-26 23:55:293163}
3164
[email protected]f11ca0732009-04-11 00:09:343165SkBitmap RenderView::ImageFromDataUrl(const GURL& url) const {
3166 std::string mime_type, char_set, data;
3167 if (net::DataURL::Parse(url, &mime_type, &char_set, &data) && !data.empty()) {
3168 // Decode the favicon using WebKit's image decoder.
3169 webkit_glue::ImageDecoder decoder(gfx::Size(kFavIconSize, kFavIconSize));
3170 const unsigned char* src_data =
3171 reinterpret_cast<const unsigned char*>(&data[0]);
3172
3173 return decoder.Decode(src_data, data.size());
3174 }
3175 return SkBitmap();
3176}
3177
initial.commit09911bf2008-07-26 23:55:293178void RenderView::OnGetApplicationInfo(int page_id) {
3179 webkit_glue::WebApplicationInfo app_info;
3180 if (page_id == page_id_)
3181 webkit_glue::GetApplicationInfo(webview(), &app_info);
3182
3183 // Prune out any data URLs in the set of icons. The browser process expects
3184 // any icon with a data URL to have originated from a favicon. We don't want
3185 // to decode arbitrary data URLs in the browser process. See
3186 // http://b/issue?id=1162972
3187 for (size_t i = 0; i < app_info.icons.size(); ++i) {
[email protected]6de74452009-02-25 18:04:593188 if (app_info.icons[i].url.SchemeIs(chrome::kDataScheme)) {
initial.commit09911bf2008-07-26 23:55:293189 app_info.icons.erase(app_info.icons.begin() + i);
3190 --i;
3191 }
3192 }
3193
3194 Send(new ViewHostMsg_DidGetApplicationInfo(routing_id_, page_id, app_info));
3195}
3196
[email protected]7ccddb8c2009-08-04 17:36:553197GURL RenderView::GetAlternateErrorPageURL(const GURL& failed_url,
initial.commit09911bf2008-07-26 23:55:293198 ErrorPageType error_type) {
[email protected]7ccddb8c2009-08-04 17:36:553199 if (failed_url.SchemeIsSecure()) {
initial.commit09911bf2008-07-26 23:55:293200 // If the URL that failed was secure, then the embedding web page was not
3201 // expecting a network attacker to be able to manipulate its contents. As
3202 // we fetch alternate error pages over HTTP, we would be allowing a network
3203 // attacker to manipulate the contents of the response if we tried to use
3204 // the link doctor here.
[email protected]810a52ef2010-01-08 01:22:153205 return GURL();
initial.commit09911bf2008-07-26 23:55:293206 }
3207
3208 // Grab the base URL from the browser process.
3209 if (!alternate_error_page_url_.is_valid())
[email protected]810a52ef2010-01-08 01:22:153210 return GURL();
initial.commit09911bf2008-07-26 23:55:293211
3212 // Strip query params from the failed URL.
3213 GURL::Replacements remove_params;
3214 remove_params.ClearUsername();
3215 remove_params.ClearPassword();
3216 remove_params.ClearQuery();
3217 remove_params.ClearRef();
[email protected]7ccddb8c2009-08-04 17:36:553218 const GURL url_to_send = failed_url.ReplaceComponents(remove_params);
[email protected]6fd28f642010-03-15 17:15:503219 std::string spec_to_send = url_to_send.spec();
3220 // Notify link doctor of the url truncation by sending of "?" at the end.
3221 if (failed_url.has_query())
3222 spec_to_send.append("?");
initial.commit09911bf2008-07-26 23:55:293223
3224 // Construct the query params to send to link doctor.
3225 std::string params(alternate_error_page_url_.query());
3226 params.append("&url=");
[email protected]6fd28f642010-03-15 17:15:503227 params.append(EscapeQueryParamValue(spec_to_send, true));
initial.commit09911bf2008-07-26 23:55:293228 params.append("&sourceid=chrome");
3229 params.append("&error=");
3230 switch (error_type) {
3231 case DNS_ERROR:
3232 params.append("dnserror");
3233 break;
3234
3235 case HTTP_404:
3236 params.append("http404");
3237 break;
3238
[email protected]5df266ac2008-10-15 19:50:133239 case CONNECTION_ERROR:
[email protected]e1f934b2009-01-26 20:41:333240 params.append("connectionfailure");
[email protected]5df266ac2008-10-15 19:50:133241 break;
3242
initial.commit09911bf2008-07-26 23:55:293243 default:
3244 NOTREACHED() << "unknown ErrorPageType";
3245 }
3246
3247 // OK, build the final url to return.
3248 GURL::Replacements link_doctor_params;
3249 link_doctor_params.SetQueryStr(params);
3250 GURL url = alternate_error_page_url_.ReplaceComponents(link_doctor_params);
3251 return url;
3252}
3253
[email protected]6069da8c2009-10-20 20:33:493254void RenderView::OnFind(int request_id, const string16& search_text,
3255 const WebFindOptions& options) {
[email protected]26aa0482009-09-30 16:55:273256 WebFrame* main_frame = webview()->mainFrame();
[email protected]b4bb2502009-10-01 22:35:273257 WebFrame* frame_after_main = main_frame->traverseNext(true);
[email protected]26aa0482009-09-30 16:55:273258 WebFrame* focused_frame = webview()->focusedFrame();
initial.commit09911bf2008-07-26 23:55:293259 WebFrame* search_frame = focused_frame; // start searching focused frame.
3260
3261 bool multi_frame = (frame_after_main != main_frame);
3262
3263 // If we have multiple frames, we don't want to wrap the search within the
3264 // frame, so we check here if we only have main_frame in the chain.
3265 bool wrap_within_frame = !multi_frame;
3266
[email protected]b3f2b912009-04-09 16:18:523267 WebRect selection_rect;
initial.commit09911bf2008-07-26 23:55:293268 bool result = false;
3269
[email protected]7830da3e2009-11-06 16:27:263270 // If something is selected when we start searching it means we cannot just
3271 // increment the current match ordinal; we need to re-generate it.
3272 WebRange current_selection = focused_frame->selectionRange();
3273
initial.commit09911bf2008-07-26 23:55:293274 do {
[email protected]dd7daa82009-08-10 05:46:453275 result = search_frame->find(
[email protected]7ea066a2009-04-06 20:21:593276 request_id, search_text, options, wrap_within_frame, &selection_rect);
initial.commit09911bf2008-07-26 23:55:293277
3278 if (!result) {
3279 // don't leave text selected as you move to the next frame.
[email protected]a100d76bb2009-08-14 17:50:223280 search_frame->executeCommand(WebString::fromUTF8("Unselect"));
initial.commit09911bf2008-07-26 23:55:293281
3282 // Find the next frame, but skip the invisible ones.
3283 do {
3284 // What is the next frame to search? (we might be going backwards). Note
3285 // that we specify wrap=true so that search_frame never becomes NULL.
[email protected]7ea066a2009-04-06 20:21:593286 search_frame = options.forward ?
[email protected]b4bb2502009-10-01 22:35:273287 search_frame->traverseNext(true) :
3288 search_frame->traversePrevious(true);
[email protected]dd7daa82009-08-10 05:46:453289 } while (!search_frame->hasVisibleContent() &&
3290 search_frame != focused_frame);
initial.commit09911bf2008-07-26 23:55:293291
[email protected]884db412008-11-24 23:46:503292 // Make sure selection doesn't affect the search operation in new frame.
[email protected]a100d76bb2009-08-14 17:50:223293 search_frame->executeCommand(WebString::fromUTF8("Unselect"));
initial.commit09911bf2008-07-26 23:55:293294
3295 // If we have multiple frames and we have wrapped back around to the
3296 // focused frame, we need to search it once more allowing wrap within
3297 // the frame, otherwise it will report 'no match' if the focused frame has
3298 // reported matches, but no frames after the focused_frame contain a
3299 // match for the search word(s).
3300 if (multi_frame && search_frame == focused_frame) {
[email protected]dd7daa82009-08-10 05:46:453301 result = search_frame->find(
[email protected]7ea066a2009-04-06 20:21:593302 request_id, search_text, options, true, // Force wrapping.
3303 &selection_rect);
initial.commit09911bf2008-07-26 23:55:293304 }
3305 }
3306
[email protected]26aa0482009-09-30 16:55:273307 webview()->setFocusedFrame(search_frame);
initial.commit09911bf2008-07-26 23:55:293308 } while (!result && search_frame != focused_frame);
3309
[email protected]7830da3e2009-11-06 16:27:263310 if (options.findNext && current_selection.isNull()) {
[email protected]4f3dc372009-02-24 00:10:293311 // Force the main_frame to report the actual count.
[email protected]dd7daa82009-08-10 05:46:453312 main_frame->increaseMatchCount(0, request_id);
[email protected]4f3dc372009-02-24 00:10:293313 } else {
3314 // If nothing is found, set result to "0 of 0", otherwise, set it to
3315 // "-1 of 1" to indicate that we found at least one item, but we don't know
3316 // yet what is active.
3317 int ordinal = result ? -1 : 0; // -1 here means, we might know more later.
3318 int match_count = result ? 1 : 0; // 1 here means possibly more coming.
initial.commit09911bf2008-07-26 23:55:293319
[email protected]4f3dc372009-02-24 00:10:293320 // If we find no matches then this will be our last status update.
3321 // Otherwise the scoping effort will send more results.
3322 bool final_status_update = !result;
initial.commit09911bf2008-07-26 23:55:293323
[email protected]4f3dc372009-02-24 00:10:293324 // Send the search result over to the browser process.
[email protected]4f999132009-03-31 18:08:403325 Send(new ViewHostMsg_Find_Reply(routing_id_,
[email protected]7ea066a2009-04-06 20:21:593326 request_id,
[email protected]4f3dc372009-02-24 00:10:293327 match_count,
3328 selection_rect,
3329 ordinal,
3330 final_status_update));
initial.commit09911bf2008-07-26 23:55:293331
initial.commit09911bf2008-07-26 23:55:293332 // Scoping effort begins, starting with the mainframe.
3333 search_frame = main_frame;
3334
[email protected]dd7daa82009-08-10 05:46:453335 main_frame->resetMatchCount();
initial.commit09911bf2008-07-26 23:55:293336
3337 do {
3338 // Cancel all old scoping requests before starting a new one.
[email protected]dd7daa82009-08-10 05:46:453339 search_frame->cancelPendingScopingEffort();
initial.commit09911bf2008-07-26 23:55:293340
3341 // We don't start another scoping effort unless at least one match has
3342 // been found.
3343 if (result) {
3344 // Start new scoping request. If the scoping function determines that it
3345 // needs to scope, it will defer until later.
[email protected]dd7daa82009-08-10 05:46:453346 search_frame->scopeStringMatches(request_id,
[email protected]7ea066a2009-04-06 20:21:593347 search_text,
3348 options,
initial.commit09911bf2008-07-26 23:55:293349 true); // reset the tickmarks
3350 }
3351
3352 // Iterate to the next frame. The frame will not necessarily scope, for
3353 // example if it is not visible.
[email protected]b4bb2502009-10-01 22:35:273354 search_frame = search_frame->traverseNext(true);
initial.commit09911bf2008-07-26 23:55:293355 } while (search_frame != main_frame);
3356 }
3357}
3358
[email protected]8c4cdd42010-01-12 21:31:133359// static
3360std::string RenderView::DetermineTextLanguage(const std::wstring& text) {
[email protected]70082aab2010-02-24 01:44:403361 // Text with less than 100 bytes will probably not provide good results.
3362 // Report it as unknown language.
3363 if (text.length() < 100)
3364 return kUnknownLanguageCode;
3365
[email protected]8c4cdd42010-01-12 21:31:133366 std::string language = kUnknownLanguageCode;
[email protected]8c4cdd42010-01-12 21:31:133367 int num_languages = 0;
3368 bool is_reliable = false;
[email protected]8dc5a2052010-01-19 21:32:423369 string16 input = WideToUTF16(text);
[email protected]8c4cdd42010-01-12 21:31:133370 Language cld_language =
[email protected]8dc5a2052010-01-19 21:32:423371 DetectLanguageOfUnicodeText(NULL, input.c_str(), true, &is_reliable,
[email protected]8c4cdd42010-01-12 21:31:133372 &num_languages, NULL);
[email protected]70082aab2010-02-24 01:44:403373 if (is_reliable && cld_language != NUM_LANGUAGES &&
3374 cld_language != UNKNOWN_LANGUAGE && cld_language != TG_UNKNOWN_LANGUAGE) {
[email protected]a7ccc4d2010-01-27 08:14:483375 // We should not use LanguageCode_ISO_639_1 because it does not cover all
3376 // the languages CLD can detect. As a result, it'll return the invalid
[email protected]8d022a92010-02-04 02:49:263377 // language code for tradtional Chinese among others.
3378 // |LanguageCodeWithDialect| will go through ISO 639-1, ISO-639-2 and
3379 // 'other' tables to do the 'right' thing. In addition, it'll return zh-CN
3380 // for Simplified Chinese.
3381 language = LanguageCodeWithDialects(cld_language);
[email protected]8c4cdd42010-01-12 21:31:133382 }
[email protected]8c4cdd42010-01-12 21:31:133383 return language;
[email protected]7893a982010-01-07 23:25:523384}
3385
[email protected]8934a3b2010-02-25 00:34:003386bool RenderView::AllowContentType(ContentSettingsType settings_type) {
[email protected]0de80162010-02-03 04:52:353387 // CONTENT_SETTING_ASK is only valid for cookies.
[email protected]8934a3b2010-02-25 00:34:003388 return current_content_settings_.settings[settings_type] !=
3389 CONTENT_SETTING_BLOCK;
3390}
3391
3392void RenderView::DidBlockContentType(ContentSettingsType settings_type) {
3393 if (!content_blocked_[settings_type]) {
3394 content_blocked_[settings_type] = true;
3395 Send(new ViewHostMsg_ContentBlocked(routing_id_, settings_type));
[email protected]0de80162010-02-03 04:52:353396 }
[email protected]0de80162010-02-03 04:52:353397}
3398
[email protected]71b0d5d2010-02-15 05:43:073399void RenderView::ClearBlockedContentSettings() {
3400 for (size_t i = 0; i < arraysize(content_blocked_); ++i)
3401 content_blocked_[i] = false;
3402}
3403
initial.commit09911bf2008-07-26 23:55:293404void RenderView::DnsPrefetch(const std::vector<std::string>& host_names) {
3405 Send(new ViewHostMsg_DnsPrefetch(host_names));
3406}
3407
[email protected]40bd6582009-12-04 23:49:513408void RenderView::OnZoom(PageZoom::Function function) {
3409 if (!webview()) // Not sure if this can happen, but no harm in being safe.
3410 return;
3411
3412 int zoom_level = webview()->zoomLevel();
3413 int new_zoom_level = webview()->setZoomLevel(false,
3414 (function == PageZoom::RESET) ? 0 : (zoom_level + function));
3415
3416 // Tell the browser which host got zoomed so it can update the saved values.
3417 // Pages like the safe browsing interstitial can have empty hosts; don't
3418 // record those.
3419 std::string host(GURL(webview()->mainFrame()->url()).host());
3420 if (!host.empty())
3421 Send(new ViewHostMsg_DidZoomHost(host, new_zoom_level));
3422}
3423
[email protected]f85f0702010-01-30 09:31:013424void RenderView::OnSetContentSettingsForLoadingHost(
3425 std::string host,
3426 const ContentSettings& content_settings) {
3427 host_content_settings_[host] = content_settings;
3428}
3429
[email protected]40bd6582009-12-04 23:49:513430void RenderView::OnSetZoomLevelForLoadingHost(std::string host,
3431 int zoom_level) {
3432 host_zoom_levels_[host] = zoom_level;
initial.commit09911bf2008-07-26 23:55:293433}
3434
[email protected]41fc0322009-09-04 22:23:403435void RenderView::OnSetPageEncoding(const std::string& encoding_name) {
[email protected]26aa0482009-09-30 16:55:273436 webview()->setPageEncoding(WebString::fromUTF8(encoding_name));
initial.commit09911bf2008-07-26 23:55:293437}
3438
[email protected]a697f4c2009-09-14 22:30:183439void RenderView::OnResetPageEncodingToDefault() {
[email protected]26aa0482009-09-30 16:55:273440 WebString no_encoding;
3441 webview()->setPageEncoding(no_encoding);
[email protected]a697f4c2009-09-14 22:30:183442}
3443
[email protected]20ad2692009-11-20 18:27:203444bool RenderView::GetAllChildFrames(
3445 WebFrame* parent_frame,
3446 std::vector<WebFrame*>* frames_vector) const {
3447 if (!parent_frame)
3448 return false;
3449 for (WebFrame* child_frame = parent_frame->firstChild(); child_frame;
3450 child_frame = child_frame->nextSibling()) {
3451 frames_vector->push_back(child_frame);
3452 GetAllChildFrames(child_frame, frames_vector);
3453 }
3454 return true;
3455}
3456
[email protected]dd7daa82009-08-10 05:46:453457WebFrame* RenderView::GetChildFrame(const std::wstring& xpath) const {
3458 if (xpath.empty())
[email protected]26aa0482009-09-30 16:55:273459 return webview()->mainFrame();
[email protected]dd7daa82009-08-10 05:46:453460
3461 // xpath string can represent a frame deep down the tree (across multiple
3462 // frame DOMs).
3463 // Example, /html/body/table/tbody/tr/td/iframe\n/frameset/frame[0]
3464 // should break into 2 xpaths
3465 // /html/body/table/tbody/tr/td/iframe & /frameset/frame[0]
3466
[email protected]26aa0482009-09-30 16:55:273467 WebFrame* frame = webview()->mainFrame();
[email protected]dd7daa82009-08-10 05:46:453468
3469 std::wstring xpath_remaining = xpath;
3470 while (!xpath_remaining.empty()) {
3471 std::wstring::size_type delim_pos = xpath_remaining.find_first_of(L'\n');
3472 std::wstring xpath_child;
3473 if (delim_pos != std::wstring::npos) {
3474 xpath_child = xpath_remaining.substr(0, delim_pos);
3475 xpath_remaining.erase(0, delim_pos + 1);
3476 } else {
3477 xpath_remaining.swap(xpath_child);
3478 }
3479 frame = frame->findChildByExpression(WideToUTF16Hack(xpath_child));
initial.commit09911bf2008-07-26 23:55:293480 }
3481
[email protected]dd7daa82009-08-10 05:46:453482 return frame;
initial.commit09911bf2008-07-26 23:55:293483}
3484
[email protected]f29acf52008-11-03 20:08:333485void RenderView::EvaluateScript(const std::wstring& frame_xpath,
3486 const std::wstring& script) {
initial.commit09911bf2008-07-26 23:55:293487 WebFrame* web_frame = GetChildFrame(frame_xpath);
3488 if (!web_frame)
3489 return;
3490
[email protected]dd7daa82009-08-10 05:46:453491 web_frame->executeScript(WebScriptSource(WideToUTF16Hack(script)));
initial.commit09911bf2008-07-26 23:55:293492}
3493
[email protected]1810e132009-03-24 23:35:483494void RenderView::InsertCSS(const std::wstring& frame_xpath,
[email protected]ffaef0c2009-09-15 17:08:083495 const std::string& css,
3496 const std::string& id) {
[email protected]1810e132009-03-24 23:35:483497 WebFrame* web_frame = GetChildFrame(frame_xpath);
3498 if (!web_frame)
3499 return;
3500
[email protected]ffaef0c2009-09-15 17:08:083501 web_frame->insertStyleText(WebString::fromUTF8(css), WebString::fromUTF8(id));
[email protected]1810e132009-03-24 23:35:483502}
3503
[email protected]00c39612010-03-06 02:53:283504void RenderView::OnPepperPluginDestroy(
3505 WebPluginDelegatePepper* pepper_plugin) {
3506 std::set<WebPluginDelegatePepper*>::iterator found_pepper =
3507 current_pepper_plugins_.find(pepper_plugin);
3508 if (found_pepper == current_pepper_plugins_.end()) {
3509 NOTREACHED();
3510 return;
3511 }
3512 current_pepper_plugins_.erase(found_pepper);
3513}
3514
initial.commit09911bf2008-07-26 23:55:293515void RenderView::OnScriptEvalRequest(const std::wstring& frame_xpath,
3516 const std::wstring& jscript) {
[email protected]f29acf52008-11-03 20:08:333517 EvaluateScript(frame_xpath, jscript);
initial.commit09911bf2008-07-26 23:55:293518}
3519
[email protected]1810e132009-03-24 23:35:483520void RenderView::OnCSSInsertRequest(const std::wstring& frame_xpath,
[email protected]ffaef0c2009-09-15 17:08:083521 const std::string& css,
3522 const std::string& id) {
3523 InsertCSS(frame_xpath, css, id);
[email protected]ae461542009-06-19 19:03:413524
3525 // Notify RenderViewHost that css has been inserted into the frame.
3526 Send(new ViewHostMsg_OnCSSInserted(routing_id_));
[email protected]1810e132009-03-24 23:35:483527}
3528
[email protected]7ea066a2009-04-06 20:21:593529void RenderView::OnAddMessageToConsole(
3530 const string16& frame_xpath,
3531 const string16& message,
3532 const WebConsoleMessage::Level& level) {
3533 WebFrame* web_frame = GetChildFrame(UTF16ToWideHack(frame_xpath));
[email protected]0dea3ea2009-03-31 23:30:593534 if (web_frame)
[email protected]dd7daa82009-08-10 05:46:453535 web_frame->addMessageToConsole(WebConsoleMessage(level, message));
initial.commit09911bf2008-07-26 23:55:293536}
3537
[email protected]81e63782009-02-27 19:35:093538void RenderView::OnAllowBindings(int enabled_bindings_flags) {
3539 enabled_bindings_ |= enabled_bindings_flags;
initial.commit09911bf2008-07-26 23:55:293540}
3541
3542void RenderView::OnSetDOMUIProperty(const std::string& name,
3543 const std::string& value) {
[email protected]81e63782009-02-27 19:35:093544 DCHECK(BindingsPolicy::is_dom_ui_enabled(enabled_bindings_));
initial.commit09911bf2008-07-26 23:55:293545 dom_ui_bindings_.SetProperty(name, value);
3546}
3547
3548void RenderView::OnReservePageIDRange(int size_of_range) {
3549 next_page_id_ += size_of_range + 1;
3550}
3551
[email protected]e80c73b2009-04-07 23:24:583552void RenderView::OnDragSourceEndedOrMoved(const gfx::Point& client_point,
3553 const gfx::Point& screen_point,
[email protected]1d9f4132009-09-08 17:29:253554 bool ended,
3555 WebDragOperation op) {
[email protected]5f9ae6c2009-07-08 02:38:033556 if (ended) {
[email protected]26aa0482009-09-30 16:55:273557 webview()->dragSourceEndedAt(client_point, screen_point, op);
[email protected]5f9ae6c2009-07-08 02:38:033558 }
initial.commit09911bf2008-07-26 23:55:293559}
3560
3561void RenderView::OnDragSourceSystemDragEnded() {
[email protected]26aa0482009-09-30 16:55:273562 webview()->dragSourceSystemDragEnded();
initial.commit09911bf2008-07-26 23:55:293563}
3564
initial.commit09911bf2008-07-26 23:55:293565void RenderView::OnFillPasswordForm(
[email protected]daa8c58e2009-06-15 17:21:103566 const webkit_glue::PasswordFormDomManager::FillData& form_data) {
initial.commit09911bf2008-07-26 23:55:293567 webkit_glue::FillPasswordForm(this->webview(), form_data);
3568}
3569
3570void RenderView::OnDragTargetDragEnter(const WebDropData& drop_data,
[email protected]e80c73b2009-04-07 23:24:583571 const gfx::Point& client_point,
[email protected]1d9f4132009-09-08 17:29:253572 const gfx::Point& screen_point,
3573 WebDragOperationsMask ops) {
[email protected]26aa0482009-09-30 16:55:273574 WebDragOperation operation = webview()->dragTargetDragEnter(
[email protected]e80c73b2009-04-07 23:24:583575 drop_data.ToDragData(),
3576 drop_data.identity,
3577 client_point,
[email protected]1d9f4132009-09-08 17:29:253578 screen_point,
3579 ops);
initial.commit09911bf2008-07-26 23:55:293580
[email protected]1d9f4132009-09-08 17:29:253581 Send(new ViewHostMsg_UpdateDragCursor(routing_id_, operation));
initial.commit09911bf2008-07-26 23:55:293582}
3583
[email protected]e80c73b2009-04-07 23:24:583584void RenderView::OnDragTargetDragOver(const gfx::Point& client_point,
[email protected]1d9f4132009-09-08 17:29:253585 const gfx::Point& screen_point,
3586 WebDragOperationsMask ops) {
[email protected]26aa0482009-09-30 16:55:273587 WebDragOperation operation = webview()->dragTargetDragOver(
[email protected]1d9f4132009-09-08 17:29:253588 client_point,
3589 screen_point,
3590 ops);
initial.commit09911bf2008-07-26 23:55:293591
[email protected]1d9f4132009-09-08 17:29:253592 Send(new ViewHostMsg_UpdateDragCursor(routing_id_, operation));
initial.commit09911bf2008-07-26 23:55:293593}
3594
3595void RenderView::OnDragTargetDragLeave() {
[email protected]26aa0482009-09-30 16:55:273596 webview()->dragTargetDragLeave();
initial.commit09911bf2008-07-26 23:55:293597}
3598
[email protected]e80c73b2009-04-07 23:24:583599void RenderView::OnDragTargetDrop(const gfx::Point& client_point,
3600 const gfx::Point& screen_point) {
[email protected]26aa0482009-09-30 16:55:273601 webview()->dragTargetDrop(client_point, screen_point);
initial.commit09911bf2008-07-26 23:55:293602}
3603
3604void RenderView::OnUpdateWebPreferences(const WebPreferences& prefs) {
[email protected]2fab253a2009-08-17 23:00:593605 webkit_preferences_ = prefs;
3606 webkit_preferences_.Apply(webview());
initial.commit09911bf2008-07-26 23:55:293607}
3608
3609void RenderView::OnSetAltErrorPageURL(const GURL& url) {
3610 alternate_error_page_url_ = url;
3611}
3612
[email protected]a0c7153e2009-12-09 14:36:333613void RenderView::OnCustomContextMenuAction(unsigned action) {
3614 webview()->performCustomContextMenuAction(action);
3615}
3616
[email protected]d4a00a72010-01-29 01:44:423617void RenderView::OnTranslatePage(int page_id,
3618 const std::string& source_lang,
3619 const std::string& target_lang) {
3620 if (page_id != page_id_)
3621 return; // Not the page we expected, nothing to do.
3622
3623 WebFrame* main_frame = webview()->mainFrame();
3624 if (!main_frame)
3625 return;
[email protected]9e84a872010-02-09 18:23:423626
3627 page_translator_->TranslatePage(page_id, main_frame,
3628 source_lang, target_lang);
[email protected]d4a00a72010-01-29 01:44:423629}
3630
[email protected]0bedb8a2010-01-14 19:36:323631void RenderView::OnTranslateTextResponse(
3632 int work_id, int error_id, const std::vector<string16>& text_chunks) {
[email protected]d4a00a72010-01-29 01:44:423633 text_translator_.OnTranslationResponse(work_id, error_id, text_chunks);
[email protected]0bedb8a2010-01-14 19:36:323634}
3635
initial.commit09911bf2008-07-26 23:55:293636void RenderView::OnInstallMissingPlugin() {
3637 // This could happen when the first default plugin is deleted.
[email protected]f103ab72009-09-02 17:10:593638 if (first_default_plugin_)
3639 first_default_plugin_->InstallMissingPlugin();
initial.commit09911bf2008-07-26 23:55:293640}
3641
[email protected]b62d1a8c2009-01-13 23:54:573642void RenderView::OnFileChooserResponse(
[email protected]561abe62009-04-06 18:08:343643 const std::vector<FilePath>& file_names) {
[email protected]8029f5672009-03-20 22:33:363644 // This could happen if we navigated to a different page before the user
3645 // closed the chooser.
[email protected]a1128322009-10-06 18:38:463646 if (!file_chooser_completion_)
[email protected]8029f5672009-03-20 22:33:363647 return;
3648
[email protected]6069da8c2009-10-20 20:33:493649 WebVector<WebString> ws_file_names(file_names.size());
[email protected]a1128322009-10-06 18:38:463650 for (size_t i = 0; i < file_names.size(); ++i) {
3651 ws_file_names[i] = webkit_glue::FilePathToWebString(file_names[i]);
3652 }
3653
3654 file_chooser_completion_->didChooseFile(ws_file_names);
3655 // Reset the chooser pointer
3656 file_chooser_completion_ = NULL;
initial.commit09911bf2008-07-26 23:55:293657}
3658
3659void RenderView::OnEnableViewSourceMode() {
3660 if (!webview())
3661 return;
[email protected]26aa0482009-09-30 16:55:273662 WebFrame* main_frame = webview()->mainFrame();
initial.commit09911bf2008-07-26 23:55:293663 if (!main_frame)
3664 return;
3665
[email protected]dd7daa82009-08-10 05:46:453666 main_frame->enableViewSourceMode(true);
initial.commit09911bf2008-07-26 23:55:293667}
3668
[email protected]ab32b16c2009-10-16 14:57:253669void RenderView::OnEnablePreferredSizeChangedMode() {
3670 send_preferred_size_changes_ = true;
[email protected]e8014aa52010-03-03 14:30:063671
3672 if (ViewType::ShouldAutoResize(view_type_))
[email protected]d8a179c2010-01-31 00:58:143673 preferred_size_change_timer_.Start(TimeDelta::FromMilliseconds(10), this,
3674 &RenderView::CheckPreferredSize);
[email protected]0666aef2009-05-13 19:48:083675}
3676
[email protected]cda45c02010-02-25 19:28:103677void RenderView::OnDisableScrollbarsForSmallWindows(
3678 const gfx::Size& disable_scrollbar_size_limit) {
3679 disable_scrollbars_size_limit_ = disable_scrollbar_size_limit;
3680}
3681
[email protected]80d96fa2009-06-10 22:34:513682void RenderView::OnSetRendererPrefs(const RendererPreferences& renderer_prefs) {
3683 renderer_preferences_ = renderer_prefs;
[email protected]6e282c92009-07-24 01:19:373684 UpdateFontRenderingFromRendererPrefs();
[email protected]6981f7f2010-03-09 00:53:033685#if defined(TOOLKIT_GTK)
[email protected]1c83eb42009-09-11 21:08:413686 WebColorName name = WebKit::WebColorWebkitFocusRingColor;
3687 WebKit::setNamedColors(&name, &renderer_prefs.focus_ring_color, 1);
[email protected]39cd64ed2010-02-05 02:18:463688 WebKit::setCaretBlinkInterval(renderer_prefs.caret_blink_interval);
[email protected]93623c5d2009-12-10 21:40:323689
[email protected]644d77e2010-01-27 01:03:103690 if (webview()) {
[email protected]93623c5d2009-12-10 21:40:323691 webview()->setScrollbarColors(
3692 renderer_prefs.thumb_inactive_color,
3693 renderer_prefs.thumb_active_color,
3694 renderer_prefs.track_color);
[email protected]644d77e2010-01-27 01:03:103695 webview()->setSelectionColors(
3696 renderer_prefs.active_selection_bg_color,
3697 renderer_prefs.active_selection_fg_color,
3698 renderer_prefs.inactive_selection_bg_color,
3699 renderer_prefs.inactive_selection_fg_color);
3700 }
[email protected]7a74e102009-09-03 00:16:563701#endif
[email protected]80d96fa2009-06-10 22:34:513702}
3703
[email protected]952cb702009-10-07 05:50:283704void RenderView::OnMediaPlayerActionAt(const gfx::Point& location,
3705 const WebMediaPlayerAction& action) {
3706 if (webview())
3707 webview()->performMediaPlayerAction(action, location);
[email protected]581b87eb2009-07-23 23:06:563708}
3709
[email protected]7b291f92009-08-14 05:43:533710void RenderView::OnNotifyRendererViewType(ViewType::Type type) {
[email protected]078b34612009-09-19 19:31:513711 // When this is first set, the bindings aren't fully loaded. We only need
3712 // to call through this API after the page has already been loaded. It's
3713 // also called in didCreateDocumentElement to bootstrap.
3714 if (view_type_ != ViewType::INVALID) {
3715 if (type == ViewType::EXTENSION_MOLE ||
3716 type == ViewType::EXTENSION_TOOLSTRIP) {
3717 ExtensionProcessBindings::SetViewType(webview(), type);
3718 }
3719 }
[email protected]7b291f92009-08-14 05:43:533720 view_type_ = type;
3721}
3722
3723void RenderView::OnUpdateBrowserWindowId(int window_id) {
3724 browser_window_id_ = window_id;
3725}
3726
initial.commit09911bf2008-07-26 23:55:293727void RenderView::OnUpdateBackForwardListCount(int back_list_count,
3728 int forward_list_count) {
3729 history_back_list_count_ = back_list_count;
3730 history_forward_list_count_ = forward_list_count;
3731}
3732
[email protected]266eb6f2008-09-30 23:56:503733void RenderView::OnGetAccessibilityInfo(
[email protected]6a983b42009-03-20 20:12:253734 const webkit_glue::WebAccessibility::InParams& in_params,
3735 webkit_glue::WebAccessibility::OutParams* out_params) {
[email protected]6c8afae52009-01-22 02:24:573736#if defined(OS_WIN)
[email protected]c7287a92009-11-04 20:06:153737 if (!accessibility_.get()) {
3738 // TODO(dglazkov): Once implemented for all ports, remove lazy
3739 // instantiation of accessibility_.
3740 accessibility_.reset(WebAccessibilityCache::create());
3741 accessibility_->initialize(webview());
[email protected]6a983b42009-03-20 20:12:253742 }
[email protected]266eb6f2008-09-30 23:56:503743
[email protected]17455962010-02-24 01:39:353744 out_params->return_code =
3745 webkit_glue::WebAccessibility::GetAccObjInfo(accessibility_.get(),
3746 in_params,
3747 out_params);
[email protected]c7287a92009-11-04 20:06:153748
[email protected]6c8afae52009-01-22 02:24:573749#else // defined(OS_WIN)
3750 // TODO(port): accessibility not yet implemented
3751 NOTIMPLEMENTED();
3752#endif
[email protected]266eb6f2008-09-30 23:56:503753}
3754
[email protected]6a983b42009-03-20 20:12:253755void RenderView::OnClearAccessibilityInfo(int acc_obj_id, bool clear_all) {
[email protected]6c8afae52009-01-22 02:24:573756#if defined(OS_WIN)
[email protected]c7287a92009-11-04 20:06:153757 if (!accessibility_.get()) {
[email protected]266eb6f2008-09-30 23:56:503758 // If accessibility is not activated, ignore clearing message.
3759 return;
3760 }
[email protected]e846d0d2009-05-20 00:53:063761
[email protected]c7287a92009-11-04 20:06:153762 if (clear_all) {
3763 accessibility_->clear();
[email protected]266eb6f2008-09-30 23:56:503764 return;
[email protected]c7287a92009-11-04 20:06:153765 }
3766
3767 accessibility_->remove(acc_obj_id);
[email protected]e846d0d2009-05-20 00:53:063768
[email protected]6c8afae52009-01-22 02:24:573769#else // defined(OS_WIN)
3770 // TODO(port): accessibility not yet implemented
3771 NOTIMPLEMENTED();
3772#endif
[email protected]266eb6f2008-09-30 23:56:503773}
3774
initial.commit09911bf2008-07-26 23:55:293775void RenderView::OnGetAllSavableResourceLinksForCurrentPage(
3776 const GURL& page_url) {
3777 // Prepare list to storage all savable resource links.
3778 std::vector<GURL> resources_list;
3779 std::vector<GURL> referrers_list;
3780 std::vector<GURL> frames_list;
3781 webkit_glue::SavableResourcesResult result(&resources_list,
3782 &referrers_list,
3783 &frames_list);
3784
[email protected]dbeb3952009-10-13 18:01:183785 if (!webkit_glue::GetAllSavableResourceLinksForCurrentPage(
3786 webview(),
3787 page_url,
3788 &result,
3789 chrome::kSavableSchemes)) {
initial.commit09911bf2008-07-26 23:55:293790 // If something is wrong when collecting all savable resource links,
3791 // send empty list to embedder(browser) to tell it failed.
3792 referrers_list.clear();
3793 resources_list.clear();
3794 frames_list.clear();
3795 }
3796
3797 // Send result of all savable resource links to embedder.
3798 Send(new ViewHostMsg_SendCurrentPageAllSavableResourceLinks(routing_id_,
3799 resources_list,
3800 referrers_list,
3801 frames_list));
3802}
3803
3804void RenderView::OnGetSerializedHtmlDataForCurrentPageWithLocalLinks(
[email protected]f6b48532009-02-12 01:56:323805 const std::vector<GURL>& links,
[email protected]fde6714d12009-02-18 22:39:313806 const std::vector<FilePath>& local_paths,
3807 const FilePath& local_directory_name) {
[email protected]d9ec5c0f2009-12-23 11:55:073808
3809 // Convert std::vector of GURLs to WebVector<WebURL>
3810 WebVector<WebURL> weburl_links(links);
3811
3812 // Convert std::vector of std::strings to WebVector<WebString>
3813 WebVector<WebString> webstring_paths(local_paths.size());
3814 for (size_t i = 0; i < local_paths.size(); i++)
3815 webstring_paths[i] = webkit_glue::FilePathToWebString(local_paths[i]);
3816
3817 WebPageSerializer::serialize(webview()->mainFrame(),
3818 true, this, weburl_links, webstring_paths,
3819 webkit_glue::FilePathToWebString(
3820 local_directory_name));
initial.commit09911bf2008-07-26 23:55:293821}
3822
[email protected]d9ec5c0f2009-12-23 11:55:073823void RenderView::didSerializeDataForFrame(const WebURL& frame_url,
3824 const WebCString& data,
3825 WebPageSerializerClient::PageSerializationStatus status) {
3826 Send(new ViewHostMsg_SendSerializedHtmlData(
3827 routing_id_,
3828 frame_url,
3829 data.data(),
3830 static_cast<int32>(status)));
initial.commit09911bf2008-07-26 23:55:293831}
3832
[email protected]04b4a6c2008-08-02 00:44:473833void RenderView::OnMsgShouldClose() {
[email protected]26aa0482009-09-30 16:55:273834 bool should_close = webview()->dispatchBeforeUnloadEvent();
[email protected]04b4a6c2008-08-02 00:44:473835 Send(new ViewHostMsg_ShouldClose_ACK(routing_id_, should_close));
initial.commit09911bf2008-07-26 23:55:293836}
3837
[email protected]eb6b87a2009-07-24 15:57:393838void RenderView::OnClosePage(const ViewMsg_ClosePage_Params& params) {
initial.commit09911bf2008-07-26 23:55:293839 // TODO(creis): We'd rather use webview()->Close() here, but that currently
3840 // sets the WebView's delegate_ to NULL, preventing any JavaScript dialogs
3841 // in the onunload handler from appearing. For now, we're bypassing that and
3842 // calling the FrameLoader's CloseURL method directly. This should be
3843 // revisited to avoid having two ways to close a page. Having a single way
3844 // to close that can run onunload is also useful for fixing
3845 // http://b/issue?id=753080.
[email protected]26aa0482009-09-30 16:55:273846 WebFrame* main_frame = webview()->mainFrame();
[email protected]7a9b51f2009-06-29 21:28:293847 if (main_frame) {
[email protected]dd7daa82009-08-10 05:46:453848 const GURL& url = main_frame->url();
[email protected]3d9689372009-09-10 04:29:173849 // TODO(davemoore) this code should be removed once willClose() gets
[email protected]7a9b51f2009-06-29 21:28:293850 // called when a page is destroyed. DumpLoadHistograms() is safe to call
3851 // multiple times for the same frame, but it will simplify things.
[email protected]dd7daa82009-08-10 05:46:453852 if (url.SchemeIs(chrome::kHttpScheme) ||
3853 url.SchemeIs(chrome::kHttpsScheme))
[email protected]7a9b51f2009-06-29 21:28:293854 DumpLoadHistograms();
[email protected]7a9b51f2009-06-29 21:28:293855 }
[email protected]26aa0482009-09-30 16:55:273856 webview()->dispatchUnloadEvent();
initial.commit09911bf2008-07-26 23:55:293857
[email protected]ab9eabac2010-03-16 16:54:103858 // Reset stats
3859 cross_origin_access_count_ = 0;
3860 same_origin_access_count_ = 0;
3861
[email protected]eb6b87a2009-07-24 15:57:393862 // Just echo back the params in the ACK.
3863 Send(new ViewHostMsg_ClosePage_ACK(routing_id_, params));
initial.commit09911bf2008-07-26 23:55:293864}
3865
3866void RenderView::OnThemeChanged() {
[email protected]6c8afae52009-01-22 02:24:573867#if defined(OS_WIN)
initial.commit09911bf2008-07-26 23:55:293868 gfx::NativeTheme::instance()->CloseHandles();
3869 gfx::Rect view_rect(0, 0, size_.width(), size_.height());
[email protected]4873c7d2009-07-16 06:36:283870 didInvalidateRect(view_rect);
[email protected]6c8afae52009-01-22 02:24:573871#else // defined(OS_WIN)
3872 // TODO(port): we don't support theming on non-Windows platforms yet
3873 NOTIMPLEMENTED();
3874#endif
initial.commit09911bf2008-07-26 23:55:293875}
3876
[email protected]28790922009-03-09 19:48:373877void RenderView::OnMessageFromExternalHost(const std::string& message,
3878 const std::string& origin,
3879 const std::string& target) {
[email protected]3ac14a052008-08-15 21:22:153880 if (message.empty())
3881 return;
3882
[email protected]28790922009-03-09 19:48:373883 external_host_bindings_.ForwardMessageFromExternalHost(message, origin,
3884 target);
[email protected]3ac14a052008-08-15 21:22:153885}
3886
[email protected]0aa55312008-10-17 21:53:083887void RenderView::OnDisassociateFromPopupCount() {
3888 if (decrement_shared_popup_at_destruction_)
3889 shared_popup_counter_->data--;
3890 shared_popup_counter_ = new SharedRenderViewCounter(0);
3891 decrement_shared_popup_at_destruction_ = false;
3892}
3893
[email protected]15d79e12009-08-02 19:23:453894bool RenderView::MaybeLoadAlternateErrorPage(WebFrame* frame,
3895 const WebURLError& error,
3896 bool replace) {
3897 // We only show alternate error pages in the main frame. They are
3898 // intended to assist the user when navigating, so there is not much
3899 // value in showing them for failed subframes. Ideally, we would be
3900 // able to use the TYPED transition type for this, but that flag is
3901 // not preserved across page reloads.
[email protected]dd7daa82009-08-10 05:46:453902 if (frame->parent())
[email protected]15d79e12009-08-02 19:23:453903 return false;
3904
3905 // Use the alternate error page service if this is a DNS failure or
[email protected]c53976d52009-08-07 18:58:373906 // connection failure.
[email protected]15d79e12009-08-02 19:23:453907 int ec = error.reason;
3908 if (ec != net::ERR_NAME_NOT_RESOLVED &&
3909 ec != net::ERR_CONNECTION_FAILED &&
3910 ec != net::ERR_CONNECTION_REFUSED &&
3911 ec != net::ERR_ADDRESS_UNREACHABLE &&
[email protected]c53976d52009-08-07 18:58:373912 ec != net::ERR_CONNECTION_TIMED_OUT)
[email protected]15d79e12009-08-02 19:23:453913 return false;
3914
3915 const GURL& error_page_url = GetAlternateErrorPageURL(error.unreachableURL,
[email protected]7ccddb8c2009-08-04 17:36:553916 ec == net::ERR_NAME_NOT_RESOLVED ? DNS_ERROR : CONNECTION_ERROR);
[email protected]15d79e12009-08-02 19:23:453917 if (!error_page_url.is_valid())
3918 return false;
3919
3920 // Load an empty page first so there is an immediate response to the error,
3921 // and then kick off a request for the alternate error page.
[email protected]dd7daa82009-08-10 05:46:453922 frame->loadHTMLString(std::string(),
[email protected]15d79e12009-08-02 19:23:453923 GURL(kUnreachableWebDataURL),
3924 error.unreachableURL,
3925 replace);
3926
3927 // Now, create a fetcher for the error page and associate it with the data
3928 // source we just created via the LoadHTMLString call. That way if another
3929 // navigation occurs, the fetcher will get destroyed.
3930 NavigationState* navigation_state =
[email protected]dd7daa82009-08-10 05:46:453931 NavigationState::FromDataSource(frame->provisionalDataSource());
[email protected]15d79e12009-08-02 19:23:453932 navigation_state->set_alt_error_page_fetcher(
3933 new AltErrorPageResourceFetcher(
3934 error_page_url, frame, error,
3935 NewCallback(this, &RenderView::AltErrorPageFinished)));
3936 return true;
3937}
3938
initial.commit09911bf2008-07-26 23:55:293939std::string RenderView::GetAltHTMLForTemplate(
3940 const DictionaryValue& error_strings, int template_resource_id) const {
[email protected]8a16266e2009-09-10 21:08:393941 const base::StringPiece template_html(
initial.commit09911bf2008-07-26 23:55:293942 ResourceBundle::GetSharedInstance().GetRawDataResource(
3943 template_resource_id));
3944
3945 if (template_html.empty()) {
3946 NOTREACHED() << "unable to load template. ID: " << template_resource_id;
3947 return "";
3948 }
[email protected]7cd22a52009-07-14 00:40:253949
initial.commit09911bf2008-07-26 23:55:293950 // "t" is the id of the templates root node.
[email protected]7cd22a52009-07-14 00:40:253951 return jstemplate_builder::GetTemplatesHtml(
initial.commit09911bf2008-07-26 23:55:293952 template_html, &error_strings, "t");
3953}
[email protected]0e79b9e2009-02-13 04:20:483954
[email protected]15d79e12009-08-02 19:23:453955void RenderView::AltErrorPageFinished(WebFrame* frame,
3956 const WebURLError& original_error,
3957 const std::string& html) {
3958 // Here, we replace the blank page we loaded previously.
[email protected]7ccddb8c2009-08-04 17:36:553959
3960 // If we failed to download the alternate error page, fall back to the
3961 // original error page if present. Otherwise, LoadNavigationErrorPage
3962 // will simply display a default error page.
3963 const std::string* html_to_load = &html;
3964 if (html.empty()) {
3965 NavigationState* navigation_state =
[email protected]dd7daa82009-08-10 05:46:453966 NavigationState::FromDataSource(frame->dataSource());
[email protected]7ccddb8c2009-08-04 17:36:553967 html_to_load = &navigation_state->postponed_data();
3968 }
3969 LoadNavigationErrorPage(
3970 frame, WebURLRequest(), original_error, *html_to_load, true);
[email protected]15d79e12009-08-02 19:23:453971}
3972
[email protected]30f75e62009-02-25 22:01:003973void RenderView::OnMoveOrResizeStarted() {
3974 if (webview())
[email protected]4605325d2010-02-08 23:46:043975 webview()->hideSuggestionsPopup();
[email protected]30f75e62009-02-25 22:01:003976}
3977
[email protected]30f75e62009-02-25 22:01:003978void RenderView::OnResize(const gfx::Size& new_size,
3979 const gfx::Rect& resizer_rect) {
[email protected]cda45c02010-02-25 19:28:103980 if (webview()) {
[email protected]4605325d2010-02-08 23:46:043981 webview()->hideSuggestionsPopup();
[email protected]cda45c02010-02-25 19:28:103982
3983 if (send_preferred_size_changes_) {
3984 // If resizing to a size larger than |disable_scrollbars_size_limit_| in
3985 // either width or height, allow scroll bars.
3986 bool allow_scrollbars = (
3987 disable_scrollbars_size_limit_.width() <= new_size.width() ||
[email protected]45c6e532010-03-15 23:51:243988 disable_scrollbars_size_limit_.height() <= new_size.height());
[email protected]cda45c02010-02-25 19:28:103989 webview()->mainFrame()->setCanHaveScrollbars(allow_scrollbars);
3990 }
3991 }
3992
[email protected]30f75e62009-02-25 22:01:003993 RenderWidget::OnResize(new_size, resizer_rect);
3994}
[email protected]0aa477bd2009-03-23 22:21:433995
[email protected]00c39612010-03-06 02:53:283996void RenderView::DidInitiatePaint() {
3997 // Notify any pepper plugins that we started painting. The plugin "should"
3998 // never notified that we started painting, this is used for internal
3999 // bookkeeping only, so we know that the set can not change under us.
4000 for (std::set<WebPluginDelegatePepper*>::iterator i =
4001 current_pepper_plugins_.begin();
4002 i != current_pepper_plugins_.end(); ++i)
4003 (*i)->RenderViewInitiatedPaint();
4004}
4005
4006void RenderView::DidFlushPaint() {
4007 // Notify any pepper plugins that we painted. This will call into the plugin,
4008 // and we it may ask to close itself as a result. This will, in turn, modify
4009 // our set, possibly invalidating the iterator. So we iterate on a copy that
4010 // won't change out from under us.
4011 std::set<WebPluginDelegatePepper*> plugins = current_pepper_plugins_;
4012 for (std::set<WebPluginDelegatePepper*>::iterator i = plugins.begin();
4013 i != plugins.end(); ++i) {
4014 // The copy above makes sure our iterator is never invalid if some plugins
4015 // are destroyed. But some plugin may decide to close all of its views in
4016 // response to a paint in one of them, so we need to make sure each one is
4017 // still "current" before using it.
4018 if (current_pepper_plugins_.find(*i) != current_pepper_plugins_.end())
4019 (*i)->RenderViewFlushedPaint();
4020 }
4021
4022 WebFrame* main_frame = webview()->mainFrame();
4023
4024 // If we have a provisional frame we are between the start and commit stages
4025 // of loading and we don't want to save stats.
4026 if (!main_frame->provisionalDataSource()) {
4027 WebDataSource* ds = main_frame->dataSource();
4028 NavigationState* navigation_state = NavigationState::FromDataSource(ds);
4029 DCHECK(navigation_state);
4030
4031 Time now = Time::Now();
4032 if (navigation_state->first_paint_time().is_null()) {
4033 navigation_state->set_first_paint_time(now);
4034 }
4035 if (navigation_state->first_paint_after_load_time().is_null() &&
4036 !navigation_state->finish_load_time().is_null()) {
4037 navigation_state->set_first_paint_after_load_time(now);
4038 }
4039 }
4040}
4041
4042
[email protected]05d478752009-04-08 23:38:164043void RenderView::OnClearFocusedNode() {
4044 if (webview())
[email protected]26aa0482009-09-30 16:55:274045 webview()->clearFocusedNode();
[email protected]05d478752009-04-08 23:38:164046}
4047
[email protected]699ab0d2009-04-23 23:19:144048void RenderView::OnSetBackground(const SkBitmap& background) {
4049 if (webview())
[email protected]b4bb2502009-10-01 22:35:274050 webview()->setIsTransparent(!background.empty());
[email protected]699ab0d2009-04-23 23:19:144051
4052 SetBackground(background);
4053}
4054
[email protected]8c66c5a2009-07-22 17:26:344055void RenderView::OnSetActive(bool active) {
4056 if (webview())
[email protected]b4bb2502009-10-01 22:35:274057 webview()->setIsActive(active);
[email protected]d8fd6fa2010-02-01 15:54:264058
4059#if defined(OS_MACOSX)
4060 std::set<WebPluginDelegateProxy*>::iterator plugin_it;
4061 for (plugin_it = plugin_delegates_.begin();
4062 plugin_it != plugin_delegates_.end(); ++plugin_it) {
4063 (*plugin_it)->SetWindowFocus(active);
4064 }
4065#endif
[email protected]8c66c5a2009-07-22 17:26:344066}
4067
[email protected]6ce7abc52010-02-02 18:40:144068#if defined(OS_MACOSX)
4069void RenderView::OnSetWindowVisibility(bool visible) {
4070 // Inform plugins that their container has changed visibility.
4071 std::set<WebPluginDelegateProxy*>::iterator plugin_it;
4072 for (plugin_it = plugin_delegates_.begin();
4073 plugin_it != plugin_delegates_.end(); ++plugin_it) {
4074 (*plugin_it)->SetContainerVisibility(visible);
4075 }
4076}
[email protected]1e6e3c992010-02-08 15:52:134077
4078void RenderView::OnWindowFrameChanged(gfx::Rect window_frame,
4079 gfx::Rect view_frame) {
4080 // Inform plugins that their window's frame has changed.
4081 std::set<WebPluginDelegateProxy*>::iterator plugin_it;
4082 for (plugin_it = plugin_delegates_.begin();
4083 plugin_it != plugin_delegates_.end(); ++plugin_it) {
4084 (*plugin_it)->WindowFrameChanged(window_frame, view_frame);
4085 }
4086}
[email protected]6ce7abc52010-02-02 18:40:144087#endif // OS_MACOSX
4088
[email protected]309d7a282009-03-24 09:18:274089void RenderView::SendExtensionRequest(const std::string& name,
[email protected]e4dad9fb2009-10-06 18:15:584090 const ListValue& args,
[email protected]c6619182009-05-12 14:59:324091 int request_id,
[email protected]2f25d7b92009-06-10 00:06:474092 bool has_callback) {
[email protected]c6619182009-05-12 14:59:324093 Send(new ViewHostMsg_ExtensionRequest(routing_id_, name, args, request_id,
[email protected]2f25d7b92009-06-10 00:06:474094 has_callback));
[email protected]309d7a282009-03-24 09:18:274095}
4096
[email protected]c6619182009-05-12 14:59:324097void RenderView::OnExtensionResponse(int request_id,
4098 bool success,
4099 const std::string& response,
4100 const std::string& error) {
[email protected]0f6053962009-07-09 19:26:354101 ExtensionProcessBindings::HandleResponse(
4102 request_id, success, response, error);
[email protected]309d7a282009-03-24 09:18:274103}
[email protected]c20210e62009-04-03 21:39:264104
[email protected]078b34612009-09-19 19:31:514105void RenderView::InjectToolstripCSS() {
4106 if (view_type_ != ViewType::EXTENSION_TOOLSTRIP)
4107 return;
4108
4109 static const base::StringPiece toolstrip_css(
4110 ResourceBundle::GetSharedInstance().GetRawDataResource(
4111 IDR_EXTENSION_TOOLSTRIP_CSS));
4112 std::string css = toolstrip_css.as_string();
4113 InsertCSS(L"", css, "ToolstripDefaultCSS");
4114}
4115
[email protected]7120f132009-07-20 21:05:374116void RenderView::OnExtensionMessageInvoke(const std::string& function_name,
4117 const ListValue& args) {
4118 RendererExtensionBindings::Invoke(function_name, args, this);
4119}
4120
[email protected]e7e4f3c2009-04-21 15:24:084121// Dump all load time histograms.
[email protected]c20210e62009-04-03 21:39:264122//
[email protected]7a9b51f2009-06-29 21:28:294123// There are 13 histograms measuring various times.
[email protected]c20210e62009-04-03 21:39:264124// The time points we keep are
4125// request: time document was requested by user
4126// start: time load of document started
[email protected]a2f6bc112009-06-27 16:27:254127// commit: time load of document started
[email protected]7a9b51f2009-06-29 21:28:294128// finish_document: main document loaded, before onload()
[email protected]c20210e62009-04-03 21:39:264129// finish: after onload() and all resources are loaded
[email protected]7a9b51f2009-06-29 21:28:294130// first_paint: first paint performed
4131// first_paint_after_load: first paint performed after load is finished
4132// begin: request if it was user requested, start otherwise
4133//
[email protected]c20210e62009-04-03 21:39:264134// The times that we histogram are
[email protected]a2f6bc112009-06-27 16:27:254135// request->start,
[email protected]7a9b51f2009-06-29 21:28:294136// start->commit,
4137// commit->finish_document,
4138// finish_document->finish,
4139// begin->commit,
4140// begin->finishDoc,
4141// begin->finish,
4142// begin->first_paint,
4143// begin->first_paint_after_load
4144// commit->finishDoc,
4145// commit->first_paint,
4146// commit->first_paint_after_load,
4147// finish->first_paint_after_load,
[email protected]c20210e62009-04-03 21:39:264148//
[email protected]e7e4f3c2009-04-21 15:24:084149// It's possible for the request time not to be set, if a client
4150// redirect had been done (the user never requested the page)
4151// Also, it's possible to load a page without ever laying it out
[email protected]7a9b51f2009-06-29 21:28:294152// so first_paint and first_paint_after_load can be 0.
[email protected]c20210e62009-04-03 21:39:264153void RenderView::DumpLoadHistograms() const {
[email protected]26aa0482009-09-30 16:55:274154 WebFrame* main_frame = webview()->mainFrame();
[email protected]ed3fb032009-06-16 19:50:564155 NavigationState* navigation_state =
[email protected]dd7daa82009-08-10 05:46:454156 NavigationState::FromDataSource(main_frame->dataSource());
[email protected]7a9b51f2009-06-29 21:28:294157 Time finish = navigation_state->finish_load_time();
[email protected]ed3fb032009-06-16 19:50:564158
[email protected]7a9b51f2009-06-29 21:28:294159 // If we've already dumped or we haven't finished loading, do nothing.
4160 if (navigation_state->load_histograms_recorded() || finish.is_null())
4161 return;
[email protected]ed3fb032009-06-16 19:50:564162
[email protected]f8999642009-10-27 21:39:424163 LogNavigationState(navigation_state, main_frame->dataSource());
4164
[email protected]a7ccc4d2010-01-27 08:14:484165 NavigationState::LoadType load_type = navigation_state->load_type();
4166 UMA_HISTOGRAM_ENUMERATION("Renderer4.LoadType", load_type,
[email protected]4c1b6f0b2010-02-07 16:38:184167 NavigationState::kLoadTypeMax);
[email protected]a7ccc4d2010-01-27 08:14:484168
[email protected]ab9eabac2010-03-16 16:54:104169 // Site isolation metrics.
4170 UMA_HISTOGRAM_COUNTS("SiteIsolation.PageLoadsWithCrossSiteFrameAccess",
4171 cross_origin_access_count_);
4172 UMA_HISTOGRAM_COUNTS("SiteIsolation.PageLoadsWithSameSiteFrameAccess",
4173 same_origin_access_count_);
4174
[email protected]7a9b51f2009-06-29 21:28:294175 Time request = navigation_state->request_time();
4176 Time start = navigation_state->start_load_time();
4177 Time commit = navigation_state->commit_load_time();
4178 Time finish_doc = navigation_state->finish_document_load_time();
4179 Time first_paint = navigation_state->first_paint_time();
4180 Time first_paint_after_load =
4181 navigation_state->first_paint_after_load_time();
[email protected]c20210e62009-04-03 21:39:264182
[email protected]7a9b51f2009-06-29 21:28:294183 Time begin;
4184 // Client side redirects will have no request time.
4185 if (request.is_null()) {
4186 begin = start;
4187 } else {
4188 begin = request;
4189 UMA_HISTOGRAM_MEDIUM_TIMES("Renderer4.RequestToStart", start - request);
[email protected]e7e4f3c2009-04-21 15:24:084190 }
[email protected]7a9b51f2009-06-29 21:28:294191 UMA_HISTOGRAM_MEDIUM_TIMES("Renderer4.StartToCommit", commit - start);
4192 UMA_HISTOGRAM_MEDIUM_TIMES(
4193 "Renderer4.CommitToFinishDoc", finish_doc - commit);
4194 UMA_HISTOGRAM_MEDIUM_TIMES(
4195 "Renderer4.FinishDocToFinish", finish - finish_doc);
4196
4197 UMA_HISTOGRAM_MEDIUM_TIMES("Renderer4.BeginToCommit", commit - begin);
[email protected]a7ccc4d2010-01-27 08:14:484198
4199 static const TimeDelta kBeginToFinishDocMin(TimeDelta::FromMilliseconds(10));
4200 static const TimeDelta kBeginToFinishDocMax(TimeDelta::FromMinutes(10));
4201 static const size_t kBeginToFinishDocBucketCount(100);
[email protected]a7ccc4d2010-01-27 08:14:484202 TimeDelta begin_to_finish_doc = finish_doc - begin;
4203 UMA_HISTOGRAM_MEDIUM_TIMES("Renderer4.BeginToFinishDoc", begin_to_finish_doc);
[email protected]4c1b6f0b2010-02-07 16:38:184204
4205 static const TimeDelta kBeginToFinishMin(TimeDelta::FromMilliseconds(10));
4206 static const TimeDelta kBeginToFinishMax(TimeDelta::FromMinutes(10));
4207 static const size_t kBeginToFinishBucketCount(100);
4208 TimeDelta begin_to_finish = finish_doc - begin;
4209 UMA_HISTOGRAM_CUSTOM_TIMES("Renderer4.BeginToFinish", begin_to_finish,
4210 kBeginToFinishMin, kBeginToFinishMax, kBeginToFinishBucketCount);
4211
[email protected]a7ccc4d2010-01-27 08:14:484212 switch (load_type) {
4213 case NavigationState::UNDEFINED_LOAD:
4214 UMA_HISTOGRAM_CUSTOM_TIMES("Renderer4.BeginToFinishDoc_UndefLoad",
4215 begin_to_finish_doc, kBeginToFinishDocMin, kBeginToFinishDocMax,
4216 kBeginToFinishDocBucketCount);
[email protected]4c1b6f0b2010-02-07 16:38:184217 UMA_HISTOGRAM_CUSTOM_TIMES("Renderer4.BeginToFinish_UndefLoad",
4218 begin_to_finish, kBeginToFinishMin, kBeginToFinishMax,
4219 kBeginToFinishBucketCount);
[email protected]a7ccc4d2010-01-27 08:14:484220 break;
4221 case NavigationState::RELOAD:
4222 UMA_HISTOGRAM_CUSTOM_TIMES("Renderer4.BeginToFinishDoc_Reload",
4223 begin_to_finish_doc, kBeginToFinishDocMin, kBeginToFinishDocMax,
4224 kBeginToFinishDocBucketCount);
[email protected]4c1b6f0b2010-02-07 16:38:184225 UMA_HISTOGRAM_CUSTOM_TIMES("Renderer4.BeginToFinish_Reload",
4226 begin_to_finish, kBeginToFinishMin, kBeginToFinishMax,
4227 kBeginToFinishBucketCount);
[email protected]a7ccc4d2010-01-27 08:14:484228 break;
4229 case NavigationState::HISTORY_LOAD:
4230 UMA_HISTOGRAM_CUSTOM_TIMES("Renderer4.BeginToFinishDoc_HistoryLoad",
4231 begin_to_finish_doc, kBeginToFinishDocMin, kBeginToFinishDocMax,
4232 kBeginToFinishDocBucketCount);
[email protected]4c1b6f0b2010-02-07 16:38:184233 UMA_HISTOGRAM_CUSTOM_TIMES("Renderer4.BeginToFinish_HistoryLoad",
4234 begin_to_finish, kBeginToFinishMin, kBeginToFinishMax,
4235 kBeginToFinishBucketCount);
[email protected]a7ccc4d2010-01-27 08:14:484236 break;
4237 case NavigationState::NORMAL_LOAD:
4238 UMA_HISTOGRAM_CUSTOM_TIMES("Renderer4.BeginToFinishDoc_NormalLoad",
4239 begin_to_finish_doc, kBeginToFinishDocMin, kBeginToFinishDocMax,
4240 kBeginToFinishDocBucketCount);
[email protected]4c1b6f0b2010-02-07 16:38:184241 UMA_HISTOGRAM_CUSTOM_TIMES("Renderer4.BeginToFinish_NormalLoad",
4242 begin_to_finish, kBeginToFinishMin, kBeginToFinishMax,
4243 kBeginToFinishBucketCount);
[email protected]a7ccc4d2010-01-27 08:14:484244 break;
[email protected]4c1b6f0b2010-02-07 16:38:184245 case NavigationState::LINK_LOAD_NORMAL:
4246 UMA_HISTOGRAM_CUSTOM_TIMES("Renderer4.BeginToFinishDoc_LinkLoadNormal",
[email protected]a7ccc4d2010-01-27 08:14:484247 begin_to_finish_doc, kBeginToFinishDocMin, kBeginToFinishDocMax,
4248 kBeginToFinishDocBucketCount);
[email protected]4c1b6f0b2010-02-07 16:38:184249 UMA_HISTOGRAM_CUSTOM_TIMES("Renderer4.BeginToFinish_LinkLoadNormal",
4250 begin_to_finish, kBeginToFinishMin, kBeginToFinishMax,
4251 kBeginToFinishBucketCount);
4252 break;
4253 case NavigationState::LINK_LOAD_RELOAD:
4254 UMA_HISTOGRAM_CUSTOM_TIMES("Renderer4.BeginToFinishDoc_LinkLoadReload",
4255 begin_to_finish_doc, kBeginToFinishDocMin, kBeginToFinishDocMax,
4256 kBeginToFinishDocBucketCount);
4257 UMA_HISTOGRAM_CUSTOM_TIMES("Renderer4.BeginToFinish_LinkLoadReload",
4258 begin_to_finish, kBeginToFinishMin, kBeginToFinishMax,
4259 kBeginToFinishBucketCount);
4260 break;
4261 case NavigationState::LINK_LOAD_CACHE_STALE_OK:
4262 UMA_HISTOGRAM_CUSTOM_TIMES("Renderer4.BeginToFinishDoc_LinkLoadStaleOk",
4263 begin_to_finish_doc, kBeginToFinishDocMin, kBeginToFinishDocMax,
4264 kBeginToFinishDocBucketCount);
4265 UMA_HISTOGRAM_CUSTOM_TIMES("Renderer4.BeginToFinish_LinkLoadStaleOk",
4266 begin_to_finish, kBeginToFinishMin, kBeginToFinishMax,
4267 kBeginToFinishBucketCount);
4268 break;
4269 case NavigationState::LINK_LOAD_CACHE_ONLY:
4270 UMA_HISTOGRAM_CUSTOM_TIMES("Renderer4.BeginToFinishDoc_LinkLoadCacheOnly",
4271 begin_to_finish_doc, kBeginToFinishDocMin, kBeginToFinishDocMax,
4272 kBeginToFinishDocBucketCount);
4273 UMA_HISTOGRAM_CUSTOM_TIMES("Renderer4.BeginToFinish_LinkLoadCacheOnly",
4274 begin_to_finish, kBeginToFinishMin, kBeginToFinishMax,
4275 kBeginToFinishBucketCount);
[email protected]a7ccc4d2010-01-27 08:14:484276 break;
4277 default:
4278 break;
4279 }
4280
4281 static bool use_dns_histogram(FieldTrialList::Find("DnsImpact") &&
4282 !FieldTrialList::Find("DnsImpact")->group_name().empty());
4283 if (use_dns_histogram) {
[email protected]fd11f1752010-02-23 22:35:484284 UMA_HISTOGRAM_ENUMERATION(FieldTrial::MakeName(
4285 "Renderer4.LoadType", "DnsImpact"),
4286 load_type, NavigationState::kLoadTypeMax);
[email protected]a7ccc4d2010-01-27 08:14:484287 switch (load_type) {
4288 case NavigationState::NORMAL_LOAD:
4289 UMA_HISTOGRAM_CUSTOM_TIMES(FieldTrial::MakeName(
[email protected]4c1b6f0b2010-02-07 16:38:184290 "Renderer4.BeginToFinish_NormalLoad", "DnsImpact"),
4291 begin_to_finish, kBeginToFinishMin, kBeginToFinishMax,
4292 kBeginToFinishBucketCount);
4293 break;
4294 case NavigationState::LINK_LOAD_NORMAL:
4295 UMA_HISTOGRAM_CUSTOM_TIMES(FieldTrial::MakeName(
[email protected]4c1b6f0b2010-02-07 16:38:184296 "Renderer4.BeginToFinish_LinkLoadNormal", "DnsImpact"),
4297 begin_to_finish, kBeginToFinishMin, kBeginToFinishMax,
4298 kBeginToFinishBucketCount);
4299 break;
4300 case NavigationState::LINK_LOAD_RELOAD:
4301 UMA_HISTOGRAM_CUSTOM_TIMES(FieldTrial::MakeName(
[email protected]4c1b6f0b2010-02-07 16:38:184302 "Renderer4.BeginToFinish_LinkLoadReload", "DnsImpact"),
4303 begin_to_finish, kBeginToFinishMin, kBeginToFinishMax,
4304 kBeginToFinishBucketCount);
4305 break;
4306 case NavigationState::LINK_LOAD_CACHE_STALE_OK:
4307 UMA_HISTOGRAM_CUSTOM_TIMES(FieldTrial::MakeName(
[email protected]4c1b6f0b2010-02-07 16:38:184308 "Renderer4.BeginToFinish_LinkLoadStaleOk", "DnsImpact"),
4309 begin_to_finish, kBeginToFinishMin, kBeginToFinishMax,
4310 kBeginToFinishBucketCount);
[email protected]a7ccc4d2010-01-27 08:14:484311 break;
4312 default:
4313 break;
4314 }
4315 }
4316
4317 static bool use_sdch_histogram(FieldTrialList::Find("GlobalSdch") &&
4318 !FieldTrialList::Find("GlobalSdch")->group_name().empty());
4319 if (use_sdch_histogram) {
[email protected]fd11f1752010-02-23 22:35:484320 UMA_HISTOGRAM_ENUMERATION(
4321 FieldTrial::MakeName("Renderer4.LoadType", "GlobalSdch"),
4322 load_type, NavigationState::kLoadTypeMax);
[email protected]a7ccc4d2010-01-27 08:14:484323 switch (load_type) {
4324 case NavigationState::NORMAL_LOAD:
4325 UMA_HISTOGRAM_CUSTOM_TIMES(FieldTrial::MakeName(
[email protected]fd11f1752010-02-23 22:35:484326 "Renderer4.BeginToFinish_NormalLoad", "GlobalSdch"),
4327 begin_to_finish, kBeginToFinishMin, kBeginToFinishMax,
4328 kBeginToFinishBucketCount);
[email protected]a7ccc4d2010-01-27 08:14:484329 break;
[email protected]4c1b6f0b2010-02-07 16:38:184330 case NavigationState::LINK_LOAD_NORMAL:
[email protected]a7ccc4d2010-01-27 08:14:484331 UMA_HISTOGRAM_CUSTOM_TIMES(FieldTrial::MakeName(
[email protected]fd11f1752010-02-23 22:35:484332 "Renderer4.BeginToFinish_LinkLoadNormal", "GlobalSdch"),
4333 begin_to_finish, kBeginToFinishMin, kBeginToFinishMax,
4334 kBeginToFinishBucketCount);
[email protected]4c1b6f0b2010-02-07 16:38:184335 break;
4336 case NavigationState::LINK_LOAD_RELOAD:
4337 UMA_HISTOGRAM_CUSTOM_TIMES(FieldTrial::MakeName(
[email protected]fd11f1752010-02-23 22:35:484338 "Renderer4.BeginToFinish_LinkLoadReload", "GlobalSdch"),
4339 begin_to_finish, kBeginToFinishMin, kBeginToFinishMax,
4340 kBeginToFinishBucketCount);
[email protected]4c1b6f0b2010-02-07 16:38:184341 break;
4342 case NavigationState::LINK_LOAD_CACHE_STALE_OK:
4343 UMA_HISTOGRAM_CUSTOM_TIMES(FieldTrial::MakeName(
[email protected]fd11f1752010-02-23 22:35:484344 "Renderer4.BeginToFinish_LinkLoadStaleOk", "GlobalSdch"),
4345 begin_to_finish, kBeginToFinishMin, kBeginToFinishMax,
4346 kBeginToFinishBucketCount);
[email protected]4c1b6f0b2010-02-07 16:38:184347 break;
4348 case NavigationState::LINK_LOAD_CACHE_ONLY:
4349 UMA_HISTOGRAM_CUSTOM_TIMES(FieldTrial::MakeName(
[email protected]fd11f1752010-02-23 22:35:484350 "Renderer4.BeginToFinish_LinkLoadCacheOnly", "GlobalSdch"),
4351 begin_to_finish, kBeginToFinishMin, kBeginToFinishMax,
4352 kBeginToFinishBucketCount);
[email protected]a7ccc4d2010-01-27 08:14:484353 break;
4354 default:
4355 break;
4356 }
4357 }
4358
4359 static bool use_cache_histogram1(FieldTrialList::Find("CacheSize") &&
4360 !FieldTrialList::Find("CacheSize")->group_name().empty());
[email protected]4c1b6f0b2010-02-07 16:38:184361 if (use_cache_histogram1 && NavigationState::LINK_LOAD_NORMAL <= load_type &&
4362 NavigationState::LINK_LOAD_CACHE_ONLY >= load_type)
[email protected]a7ccc4d2010-01-27 08:14:484363 UMA_HISTOGRAM_CUSTOM_TIMES(FieldTrial::MakeName(
4364 "Renderer4.BeginToFinishDoc_LinkLoad", "CacheSize"),
4365 begin_to_finish_doc, kBeginToFinishDocMin, kBeginToFinishDocMax,
4366 kBeginToFinishDocBucketCount);
[email protected]e695fbd62009-06-30 16:31:544367
[email protected]0a32257a2009-07-09 18:10:414368 UMA_HISTOGRAM_CUSTOM_TIMES("Renderer4.StartToFinish",
4369 finish - start, kBeginToFinishMin,
4370 kBeginToFinishMax, kBeginToFinishBucketCount);
4371 if (!request.is_null())
4372 UMA_HISTOGRAM_CUSTOM_TIMES("Renderer4.RequestToFinish",
4373 finish - request, kBeginToFinishMin,
4374 kBeginToFinishMax, kBeginToFinishBucketCount);
[email protected]e695fbd62009-06-30 16:31:544375
[email protected]7a9b51f2009-06-29 21:28:294376 UMA_HISTOGRAM_MEDIUM_TIMES("Renderer4.CommitToFinish", finish - commit);
4377
4378 if (!first_paint.is_null()) {
4379 UMA_HISTOGRAM_MEDIUM_TIMES(
4380 "Renderer4.BeginToFirstPaint", first_paint - begin);
4381 UMA_HISTOGRAM_MEDIUM_TIMES(
4382 "Renderer4.CommitToFirstPaint", first_paint - commit);
[email protected]c20210e62009-04-03 21:39:264383 }
[email protected]7a9b51f2009-06-29 21:28:294384
4385 if (!first_paint_after_load.is_null()) {
4386 UMA_HISTOGRAM_MEDIUM_TIMES(
4387 "Renderer4.BeginToFirstPaintAfterLoad", first_paint_after_load - begin);
4388 UMA_HISTOGRAM_MEDIUM_TIMES(
4389 "Renderer4.CommitToFirstPaintAfterLoad",
4390 first_paint_after_load - commit);
4391 UMA_HISTOGRAM_MEDIUM_TIMES(
4392 "Renderer4.FinishToFirstPaintAfterLoad",
4393 first_paint_after_load - finish);
4394 }
4395
4396 navigation_state->set_load_histograms_recorded(true);
[email protected]1f4fc8e8c2010-01-02 00:46:414397
4398 // Since there are currently no guarantees that renderer histograms will be
4399 // sent to the browser, we initiate a PostTask here to be sure that we send
4400 // the histograms we generated. Without this call, pages that don't have an
4401 // on-close-handler might generate data that is lost when the renderer is
4402 // shutdown abruptly (perchance because the user closed the tab).
[email protected]a7ccc4d2010-01-27 08:14:484403 // TODO(jar) BUG=33233: This needs to be moved to a PostDelayedTask, and it
4404 // should post when the onload is complete, so that it doesn't interfere with
4405 // the next load.
[email protected]1f4fc8e8c2010-01-02 00:46:414406 if (RenderThread::current()) {
4407 RenderThread::current()->SendHistograms(
[email protected]7c927b62010-02-24 09:54:134408 chrome::kHistogramSynchronizerReservedSequenceNumber);
[email protected]1f4fc8e8c2010-01-02 00:46:414409 }
[email protected]c20210e62009-04-03 21:39:264410}
[email protected]e846d0d2009-05-20 00:53:064411
[email protected]f8999642009-10-27 21:39:424412void RenderView::LogNavigationState(const NavigationState* state,
4413 const WebDataSource* ds) const {
4414 // Because this function gets called on every page load,
4415 // take extra care to optimize it away if logging is turned off.
4416 if (logging::LOG_INFO < logging::GetMinLogLevel())
4417 return;
4418
4419 DCHECK(state);
4420 DCHECK(ds);
4421 GURL url(ds->request().url());
4422 Time start = state->start_load_time();
4423 Time finish = state->finish_load_time();
4424 // TODO(mbelshe): should we log more stats?
4425 LOG(INFO) << "PLT: "
4426 << (finish - start).InMilliseconds()
4427 << "ms "
4428 << url.spec();
4429}
4430
[email protected]cc0445f2009-10-13 16:09:084431void RenderView::focusAccessibilityObject(
4432 const WebAccessibilityObject& acc_obj) {
[email protected]e846d0d2009-05-20 00:53:064433#if defined(OS_WIN)
[email protected]c7287a92009-11-04 20:06:154434 // TODO(dglazkov): Current logic implies that focus change can only be made
4435 // after at least one call to RenderView::OnGetAccessibilityInfo, which is
4436 // where accessibility is initialized. We should determine whether that's
4437 // right.
4438 if (!accessibility_.get())
4439 return;
[email protected]e846d0d2009-05-20 00:53:064440
4441 // Retrieve the accessibility object id of the AccessibilityObject.
[email protected]c7287a92009-11-04 20:06:154442 int acc_obj_id = accessibility_->addOrGetId(acc_obj);
[email protected]e846d0d2009-05-20 00:53:064443
4444 // If id is valid, alert the browser side that an accessibility focus change
4445 // occurred.
4446 if (acc_obj_id >= 0)
4447 Send(new ViewHostMsg_AccessibilityFocusChange(routing_id_, acc_obj_id));
4448
4449#else // defined(OS_WIN)
4450 // TODO(port): accessibility not yet implemented
4451 NOTIMPLEMENTED();
4452#endif
4453}
[email protected]daa8c58e2009-06-15 17:21:104454
[email protected]e9e07992010-02-17 21:04:364455void RenderView::SendForms(WebFrame* frame) {
4456 WebVector<WebFormElement> web_forms;
4457 frame->forms(web_forms);
4458
4459 std::vector<FormFieldValues> forms;
4460 for (size_t i = 0; i < web_forms.size(); ++i) {
4461 const WebFormElement& web_form = web_forms[i];
4462
4463 if (web_form.autoComplete()) {
4464 scoped_ptr<FormFieldValues> form(FormFieldValues::Create(web_form));
4465 if (form.get())
4466 forms.push_back(*form);
4467 }
4468 }
4469
4470 if (!forms.empty())
4471 Send(new ViewHostMsg_FormsSeen(routing_id_, forms));
4472}
4473
[email protected]a3018be2010-03-09 04:28:484474void RenderView::didChangeAccessibilityObjectState(
4475 const WebKit::WebAccessibilityObject& acc_obj) {
4476#if defined(OS_WIN)
4477 // TODO(dglazkov): Current logic implies that a state change can only be made
4478 // after at least one call to RenderView::OnGetAccessibilityInfo, which is
4479 // where accessibility is initialized. We should determine whether that's
4480 // right.
4481 if (!accessibility_.get())
4482 return;
4483
4484 // Retrieve the accessibility object id of the AccessibilityObject.
4485 int acc_obj_id = accessibility_->addOrGetId(acc_obj);
4486
4487 // If id is valid, alert the browser side that an accessibility object state
4488 // change occurred.
4489 if (acc_obj_id >= 0)
4490 Send(new ViewHostMsg_AccessibilityObjectStateChange(routing_id_,
4491 acc_obj_id));
4492
4493#else // defined(OS_WIN)
4494 // TODO(port): accessibility not yet implemented
4495 NOTIMPLEMENTED();
4496#endif
4497}
4498
[email protected]daa8c58e2009-06-15 17:21:104499void RenderView::SendPasswordForms(WebFrame* frame) {
[email protected]979c28b2009-11-07 01:30:484500 WebVector<WebFormElement> forms;
[email protected]dd7daa82009-08-10 05:46:454501 frame->forms(forms);
[email protected]daa8c58e2009-06-15 17:21:104502
4503 std::vector<PasswordForm> password_forms;
4504 for (size_t i = 0; i < forms.size(); ++i) {
[email protected]979c28b2009-11-07 01:30:484505 const WebFormElement& form = forms[i];
[email protected]daa8c58e2009-06-15 17:21:104506
4507 // Respect autocomplete=off.
[email protected]979c28b2009-11-07 01:30:484508 if (form.autoComplete()) {
[email protected]daa8c58e2009-06-15 17:21:104509 scoped_ptr<PasswordForm> password_form(
4510 PasswordFormDomManager::CreatePasswordForm(form));
4511 if (password_form.get())
4512 password_forms.push_back(*password_form);
4513 }
4514 }
4515
4516 if (!password_forms.empty())
4517 Send(new ViewHostMsg_PasswordFormsSeen(routing_id_, password_forms));
4518}
[email protected]0fda7272009-06-26 15:49:334519
4520void RenderView::Print(WebFrame* frame, bool script_initiated) {
4521 DCHECK(frame);
4522 if (print_helper_.get() == NULL) {
4523 print_helper_.reset(new PrintWebViewHelper(this));
4524 }
4525 print_helper_->Print(frame, script_initiated);
4526}
[email protected]446705872009-09-10 07:22:484527
4528void RenderView::OnSetEditCommandsForNextKeyEvent(
4529 const EditCommands& edit_commands) {
4530 edit_commands_ = edit_commands;
4531}
4532
[email protected]61f5a7b2009-12-22 22:21:204533void RenderView::OnExecuteCode(const ViewMsg_ExecuteCode_Params& params) {
[email protected]26aa0482009-09-30 16:55:274534 WebFrame* main_frame = webview() ? webview()->mainFrame() : NULL;
[email protected]912256b32009-09-18 09:47:354535 if (!main_frame) {
[email protected]61f5a7b2009-12-22 22:21:204536 Send(new ViewMsg_ExecuteCodeFinished(routing_id_, params.request_id,
4537 false));
[email protected]912256b32009-09-18 09:47:354538 return;
4539 }
4540
[email protected]fa7b6b542009-11-03 05:02:304541 WebDataSource* ds = main_frame->dataSource();
4542 NavigationState* navigation_state = NavigationState::FromDataSource(ds);
4543 if (!navigation_state->user_script_idle_scheduler()->has_run()) {
[email protected]61f5a7b2009-12-22 22:21:204544 pending_code_execution_queue_.push(
4545 linked_ptr<ViewMsg_ExecuteCode_Params>(
4546 new ViewMsg_ExecuteCode_Params(params)));
[email protected]fa7b6b542009-11-03 05:02:304547 return;
4548 }
4549
[email protected]61f5a7b2009-12-22 22:21:204550 ExecuteCodeImpl(main_frame, params);
[email protected]fa7b6b542009-11-03 05:02:304551}
4552
4553void RenderView::ExecuteCodeImpl(WebFrame* frame,
[email protected]61f5a7b2009-12-22 22:21:204554 const ViewMsg_ExecuteCode_Params& params) {
[email protected]d146b832009-12-23 02:45:484555 // Don't execute scripts in gallery pages.
4556 GURL frame_url = GURL(frame->url());
4557 if (frame_url.host() == GURL(extension_urls::kGalleryBrowsePrefix).host()) {
4558 Send(new ViewMsg_ExecuteCodeFinished(routing_id_, params.request_id, true));
4559 return;
4560 }
4561
[email protected]20ad2692009-11-20 18:27:204562 std::vector<WebFrame*> frame_vector;
4563 frame_vector.push_back(frame);
[email protected]61f5a7b2009-12-22 22:21:204564 if (params.all_frames)
[email protected]20ad2692009-11-20 18:27:204565 GetAllChildFrames(frame, &frame_vector);
4566
4567 for (std::vector<WebFrame*>::iterator frame_it = frame_vector.begin();
4568 frame_it != frame_vector.end(); ++frame_it) {
4569 WebFrame* frame = *frame_it;
[email protected]61f5a7b2009-12-22 22:21:204570 if (params.is_javascript) {
4571 if (!UrlMatchesPermissions(frame->url(), params.host_permissions))
4572 continue;
4573
[email protected]20ad2692009-11-20 18:27:204574 std::vector<WebScriptSource> sources;
4575 sources.push_back(
[email protected]61f5a7b2009-12-22 22:21:204576 WebScriptSource(WebString::fromUTF8(params.code)));
4577 UserScriptSlave::InsertInitExtensionCode(&sources, params.extension_id);
[email protected]20ad2692009-11-20 18:27:204578 frame->executeScriptInIsolatedWorld(
[email protected]61f5a7b2009-12-22 22:21:204579 UserScriptSlave::GetIsolatedWorldId(params.extension_id),
[email protected]20ad2692009-11-20 18:27:204580 &sources.front(), sources.size(), EXTENSION_GROUP_CONTENT_SCRIPTS);
4581 } else {
[email protected]61f5a7b2009-12-22 22:21:204582 frame->insertStyleText(WebString::fromUTF8(params.code), WebString());
[email protected]20ad2692009-11-20 18:27:204583 }
[email protected]912256b32009-09-18 09:47:354584 }
4585
[email protected]61f5a7b2009-12-22 22:21:204586 Send(new ViewMsg_ExecuteCodeFinished(routing_id_, params.request_id, true));
[email protected]912256b32009-09-18 09:47:354587}
4588
[email protected]60c42a8c72009-10-09 04:08:594589void RenderView::Close() {
4590 // We need to grab a pointer to the doomed WebView before we destroy it.
4591 WebView* doomed = webview();
4592 RenderWidget::Close();
4593 Singleton<ViewMap>::get()->erase(doomed);
4594}
4595
[email protected]446705872009-09-10 07:22:484596void RenderView::DidHandleKeyEvent() {
4597 edit_commands_.clear();
4598}
4599
[email protected]941e4552010-02-01 21:23:434600#if defined(OS_MACOSX)
4601void RenderView::OnWasHidden() {
4602 RenderWidget::OnWasHidden();
4603
4604 // Inform plugins that their container is no longer visible.
4605 std::set<WebPluginDelegateProxy*>::iterator plugin_it;
4606 for (plugin_it = plugin_delegates_.begin();
4607 plugin_it != plugin_delegates_.end(); ++plugin_it) {
4608 (*plugin_it)->SetContainerVisibility(false);
4609 }
4610}
4611
4612void RenderView::OnWasRestored(bool needs_repainting) {
4613 RenderWidget::OnWasRestored(needs_repainting);
4614
4615 // Inform plugins that their container is now visible.
4616 std::set<WebPluginDelegateProxy*>::iterator plugin_it;
4617 for (plugin_it = plugin_delegates_.begin();
4618 plugin_it != plugin_delegates_.end(); ++plugin_it) {
4619 (*plugin_it)->SetContainerVisibility(true);
4620 }
4621}
[email protected]1e6e3c992010-02-08 15:52:134622
4623void RenderView::OnSetFocus(bool enable) {
4624 RenderWidget::OnSetFocus(enable);
4625
4626 // RenderWidget's call to setFocus can cause the underlying webview's
4627 // activation state to change just like a call to setIsActive.
4628 if (enable && webview() && webview()->isActive()) {
4629 std::set<WebPluginDelegateProxy*>::iterator plugin_it;
4630 for (plugin_it = plugin_delegates_.begin();
4631 plugin_it != plugin_delegates_.end(); ++plugin_it) {
4632 (*plugin_it)->SetWindowFocus(true);
4633 }
4634 }
4635}
[email protected]941e4552010-02-01 21:23:434636#endif // OS_MACOSX
4637
[email protected]83dde542009-09-11 20:59:554638void RenderView::EnsureDocumentTag() {
4639 // TODO(darin): There's actually no reason for this to be here. We should
4640 // have the browser side manage the document tag.
4641#if defined(OS_MACOSX)
4642 if (!has_document_tag_) {
4643 // Make the call to get the tag.
4644 Send(new ViewHostMsg_GetDocumentTag(routing_id_, &document_tag_));
4645 has_document_tag_ = true;
4646 }
4647#endif
4648}
[email protected]12636df2009-09-28 22:32:214649
[email protected]43f28f832010-02-03 02:28:484650#if defined(OS_MACOSX)
4651gfx::PluginWindowHandle RenderView::AllocateFakePluginWindowHandle() {
4652 gfx::PluginWindowHandle window = NULL;
4653 Send(new ViewHostMsg_AllocateFakePluginWindowHandle(
4654 routing_id(), &window));
4655 return window;
4656}
4657
4658void RenderView::DestroyFakePluginWindowHandle(gfx::PluginWindowHandle window) {
4659 if (window)
4660 Send(new ViewHostMsg_DestroyFakePluginWindowHandle(routing_id(), window));
4661}
4662
[email protected]44ce0b12010-03-12 16:45:334663void RenderView::AcceleratedSurfaceSetIOSurface(gfx::PluginWindowHandle window,
4664 int32 width,
4665 int32 height,
4666 uint64 io_surface_identifier) {
4667 Send(new ViewHostMsg_AcceleratedSurfaceSetIOSurface(
[email protected]43f28f832010-02-03 02:28:484668 routing_id(), window, width, height, io_surface_identifier));
4669}
4670
[email protected]44ce0b12010-03-12 16:45:334671void RenderView::AcceleratedSurfaceSetTransportDIB(
4672 gfx::PluginWindowHandle window,
4673 int32 width,
4674 int32 height,
4675 TransportDIB::Handle transport_dib) {
4676 Send(new ViewHostMsg_AcceleratedSurfaceSetTransportDIB(
[email protected]1aef98132010-02-23 18:00:074677 routing_id(), window, width, height, transport_dib));
4678}
4679
[email protected]44ce0b12010-03-12 16:45:334680TransportDIB::Handle RenderView::AcceleratedSurfaceAllocTransportDIB(
4681 size_t size) {
[email protected]1aef98132010-02-23 18:00:074682 TransportDIB::Handle dib_handle;
4683 // Assume this is a synchronous RPC.
4684 if (Send(new ViewHostMsg_AllocTransportDIB(size, &dib_handle)))
4685 return dib_handle;
4686 // Return an invalid handle if Send() fails.
4687 return TransportDIB::DefaultHandleValue();
4688}
4689
[email protected]44ce0b12010-03-12 16:45:334690void RenderView::AcceleratedSurfaceFreeTransportDIB(TransportDIB::Id dib_id) {
[email protected]1aef98132010-02-23 18:00:074691 Send(new ViewHostMsg_FreeTransportDIB(dib_id));
4692}
4693
[email protected]44ce0b12010-03-12 16:45:334694void RenderView::AcceleratedSurfaceBuffersSwapped(
4695 gfx::PluginWindowHandle window) {
4696 Send(new ViewHostMsg_AcceleratedSurfaceBuffersSwapped(routing_id(), window));
[email protected]43f28f832010-02-03 02:28:484697}
4698#endif
[email protected]58c321d2010-02-19 12:11:284699
4700WebKit::WebGeolocationServiceInterface* RenderView::getGeolocationService() {
4701 if (!geolocation_dispatcher_.get())
4702 geolocation_dispatcher_.reset(new GeolocationDispatcher(this));
4703 return geolocation_dispatcher_.get();
4704}