blob: 6888fbb72d18e4b408bcd8adebf444b382260516 [file] [log] [blame]
[email protected]05d478752009-04-08 23:38:161// Copyright (c) 2009 The Chromium Authors. All rights reserved.
license.botbf09a502008-08-24 00:55:552// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
initial.commit09911bf2008-07-26 23:55:294
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"
initial.commit09911bf2008-07-26 23:55:2916#include "base/command_line.h"
[email protected]bb063b72009-03-27 23:18:5017#include "base/compiler_specific.h"
[email protected]4646f292009-05-20 03:49:0518#include "base/field_trial.h"
[email protected]18bcc3c2009-01-27 21:39:1519#include "base/gfx/native_widget_types.h"
[email protected]8380c092009-06-25 17:45:5120#include "base/process_util.h"
[email protected]7b291f92009-08-14 05:43:5321#include "base/singleton.h"
initial.commit09911bf2008-07-26 23:55:2922#include "base/string_piece.h"
23#include "base/string_util.h"
[email protected]6c8afae52009-01-22 02:24:5724#include "build/build_config.h"
[email protected]81e63782009-02-27 19:35:0925#include "chrome/common/bindings_policy.h"
[email protected]ef916272009-07-08 21:40:5526#include "chrome/common/child_process_logging.h"
initial.commit09911bf2008-07-26 23:55:2927#include "chrome/common/chrome_switches.h"
[email protected]f0af6a72009-05-30 05:25:1728#include "chrome/common/chrome_constants.h"
initial.commit09911bf2008-07-26 23:55:2929#include "chrome/common/jstemplate_builder.h"
[email protected]630e26b2008-10-14 22:55:1730#include "chrome/common/page_zoom.h"
[email protected]8beff0762009-09-29 02:18:3031#include "chrome/common/plugin_messages.h"
[email protected]e09ba552009-02-05 03:26:2932#include "chrome/common/render_messages.h"
[email protected]9b6f40e2009-06-11 15:54:2633#include "chrome/common/renderer_preferences.h"
initial.commit09911bf2008-07-26 23:55:2934#include "chrome/common/thumbnail_score.h"
[email protected]6de74452009-02-25 18:04:5935#include "chrome/common/url_constants.h"
initial.commit09911bf2008-07-26 23:55:2936#include "chrome/renderer/about_handler.h"
[email protected]5fb88962009-04-16 19:03:2537#include "chrome/renderer/audio_message_filter.h"
[email protected]e4ac5df2009-03-17 15:33:1138#include "chrome/renderer/devtools_agent.h"
39#include "chrome/renderer/devtools_client.h"
[email protected]912256b32009-09-18 09:47:3540#include "chrome/renderer/extension_groups.h"
[email protected]f816c012009-06-26 21:48:3241#include "chrome/renderer/extensions/event_bindings.h"
[email protected]0f6053962009-07-09 19:26:3542#include "chrome/renderer/extensions/extension_process_bindings.h"
[email protected]7120f132009-07-20 21:05:3743#include "chrome/renderer/extensions/renderer_extension_bindings.h"
initial.commit09911bf2008-07-26 23:55:2944#include "chrome/renderer/localized_error.h"
[email protected]6f56d482009-02-20 05:02:5645#include "chrome/renderer/media/audio_renderer_impl.h"
[email protected]ed3fb032009-06-16 19:50:5646#include "chrome/renderer/navigation_state.h"
[email protected]90e908552009-10-05 01:40:1247#include "chrome/renderer/notification_provider.h"
[email protected]8beff0762009-09-29 02:18:3048#include "chrome/renderer/plugin_channel_host.h"
[email protected]d81c1e52009-06-03 22:09:5049#include "chrome/renderer/print_web_view_helper.h"
[email protected]39008c02009-02-11 23:59:2550#include "chrome/renderer/render_process.h"
[email protected]0938d3c2009-01-09 20:37:3551#include "chrome/renderer/user_script_slave.h"
initial.commit09911bf2008-07-26 23:55:2952#include "chrome/renderer/visitedlink_slave.h"
[email protected]ba4b17f2009-02-11 21:32:2953#include "chrome/renderer/webplugin_delegate_proxy.h"
[email protected]eb47a132009-03-04 00:39:5654#include "chrome/renderer/webworker_proxy.h"
[email protected]34ac8f32009-02-22 23:03:2755#include "grit/generated_resources.h"
56#include "grit/renderer_resources.h"
[email protected]f11ca0732009-04-11 00:09:3457#include "net/base/data_url.h"
initial.commit09911bf2008-07-26 23:55:2958#include "net/base/escape.h"
59#include "net/base/net_errors.h"
[email protected]c399a8a2008-11-22 19:38:0060#include "skia/ext/bitmap_platform_device.h"
[email protected]83c9e6552008-12-03 16:22:1061#include "skia/ext/image_operations.h"
[email protected]726985e22009-06-18 21:09:2862#include "webkit/api/public/WebDataSource.h"
[email protected]afdcf5c2009-05-10 20:30:4163#include "webkit/api/public/WebDragData.h"
[email protected]daa8c58e2009-06-15 17:21:1064#include "webkit/api/public/WebForm.h"
[email protected]dd7daa82009-08-10 05:46:4565#include "webkit/api/public/WebFrame.h"
[email protected]ca948a22009-06-25 19:36:1766#include "webkit/api/public/WebHistoryItem.h"
[email protected]581b87eb2009-07-23 23:06:5667#include "webkit/api/public/WebNode.h"
[email protected]afdcf5c2009-05-10 20:30:4168#include "webkit/api/public/WebPoint.h"
69#include "webkit/api/public/WebRect.h"
70#include "webkit/api/public/WebScriptSource.h"
[email protected]91733b62009-09-18 06:21:0971#include "webkit/api/public/WebSecurityOrigin.h"
[email protected]afdcf5c2009-05-10 20:30:4172#include "webkit/api/public/WebSize.h"
[email protected]726985e22009-06-18 21:09:2873#include "webkit/api/public/WebURL.h"
74#include "webkit/api/public/WebURLError.h"
75#include "webkit/api/public/WebURLRequest.h"
76#include "webkit/api/public/WebURLResponse.h"
77#include "webkit/api/public/WebVector.h"
[email protected]f430b5712009-08-21 21:46:3178#include "webkit/appcache/appcache_interfaces.h"
[email protected]ba4b17f2009-02-11 21:32:2979#include "webkit/default_plugin/default_plugin_shared.h"
[email protected]ca948a22009-06-25 19:36:1780#include "webkit/glue/glue_serialize.h"
initial.commit09911bf2008-07-26 23:55:2981#include "webkit/glue/dom_operations.h"
82#include "webkit/glue/dom_serializer.h"
[email protected]f11ca0732009-04-11 00:09:3483#include "webkit/glue/image_decoder.h"
[email protected]8e296bbd2009-07-22 21:37:1784#include "webkit/glue/media/buffered_data_source.h"
[email protected]8380c092009-06-25 17:45:5185#include "webkit/glue/media/simple_data_source.h"
initial.commit09911bf2008-07-26 23:55:2986#include "webkit/glue/password_form.h"
[email protected]ba4b17f2009-02-11 21:32:2987#include "webkit/glue/plugins/plugin_list.h"
[email protected]8a3b7962009-09-04 05:53:2388#include "webkit/glue/plugins/webplugin_delegate_impl.h"
initial.commit09911bf2008-07-26 23:55:2989#include "webkit/glue/searchable_form_data.h"
[email protected]6a983b42009-03-20 20:12:2590#include "webkit/glue/webaccessibilitymanager_impl.h"
[email protected]611cad42009-03-16 18:51:3491#include "webkit/glue/webdevtoolsagent_delegate.h"
initial.commit09911bf2008-07-26 23:55:2992#include "webkit/glue/webdropdata.h"
initial.commit09911bf2008-07-26 23:55:2993#include "webkit/glue/webkit_glue.h"
[email protected]add51772009-06-11 18:25:1794#include "webkit/glue/webmediaplayer_impl.h"
[email protected]f103ab72009-09-02 17:10:5995#include "webkit/glue/webplugin_impl.h"
initial.commit09911bf2008-07-26 23:55:2996#include "webkit/glue/webview.h"
initial.commit09911bf2008-07-26 23:55:2997
[email protected]6c8afae52009-01-22 02:24:5798#if defined(OS_WIN)
99// TODO(port): these files are currently Windows only because they concern:
[email protected]6c8afae52009-01-22 02:24:57100// * theming
[email protected]6c8afae52009-01-22 02:24:57101#include "base/gfx/native_theme.h"
[email protected]6c8afae52009-01-22 02:24:57102#endif
103
[email protected]c20210e62009-04-03 21:39:26104using base::Time;
[email protected]e1acf6f2008-10-27 20:43:33105using base::TimeDelta;
[email protected]15d79e12009-08-02 19:23:45106using webkit_glue::AltErrorPageResourceFetcher;
[email protected]daa8c58e2009-06-15 17:21:10107using webkit_glue::AutofillForm;
[email protected]b0950a72009-09-29 23:16:17108using webkit_glue::ImageResourceFetcher;
[email protected]ed3fb032009-06-16 19:50:56109using webkit_glue::PasswordForm;
[email protected]daa8c58e2009-06-15 17:21:10110using webkit_glue::PasswordFormDomManager;
111using webkit_glue::SearchableFormData;
[email protected]1c83eb42009-09-11 21:08:41112using WebKit::WebColor;
113using WebKit::WebColorName;
[email protected]0dea3ea2009-03-31 23:30:59114using WebKit::WebConsoleMessage;
[email protected]e6f546c32009-07-01 17:12:55115using WebKit::WebData;
[email protected]726985e22009-06-18 21:09:28116using WebKit::WebDataSource;
[email protected]e80c73b2009-04-07 23:24:58117using WebKit::WebDragData;
[email protected]1d9f4132009-09-08 17:29:25118using WebKit::WebDragOperation;
119using WebKit::WebDragOperationsMask;
[email protected]79dbc662009-09-04 05:42:51120using WebKit::WebEditingAction;
[email protected]daa8c58e2009-06-15 17:21:10121using WebKit::WebForm;
[email protected]dd7daa82009-08-10 05:46:45122using WebKit::WebFrame;
[email protected]ca948a22009-06-25 19:36:17123using WebKit::WebHistoryItem;
[email protected]3d9689372009-09-10 04:29:17124using WebKit::WebMediaPlayer;
125using WebKit::WebMediaPlayerClient;
[email protected]4873c7d2009-07-16 06:36:28126using WebKit::WebNavigationPolicy;
[email protected]726985e22009-06-18 21:09:28127using WebKit::WebNavigationType;
[email protected]79dbc662009-09-04 05:42:51128using WebKit::WebNode;
[email protected]3d9689372009-09-10 04:29:17129using WebKit::WebPlugin;
130using WebKit::WebPluginParams;
[email protected]48c9cf2d2009-09-16 16:47:52131using WebKit::WebPoint;
[email protected]88efb7ec2009-07-14 16:32:59132using WebKit::WebPopupMenuInfo;
[email protected]79dbc662009-09-04 05:42:51133using WebKit::WebRange;
[email protected]b3f2b912009-04-09 16:18:52134using WebKit::WebRect;
[email protected]4f999132009-03-31 18:08:40135using WebKit::WebScriptSource;
[email protected]e3d60e5d2009-09-25 21:08:29136using WebKit::WebSecurityOrigin;
[email protected]2fab253a2009-08-17 23:00:59137using WebKit::WebSettings;
[email protected]8649fb32009-06-26 17:51:02138using WebKit::WebSize;
[email protected]726985e22009-06-18 21:09:28139using WebKit::WebString;
[email protected]79dbc662009-09-04 05:42:51140using WebKit::WebTextAffinity;
[email protected]de570ef2009-07-29 18:27:52141using WebKit::WebTextDirection;
[email protected]726985e22009-06-18 21:09:28142using WebKit::WebURL;
143using WebKit::WebURLError;
144using WebKit::WebURLRequest;
145using WebKit::WebURLResponse;
[email protected]4873c7d2009-07-16 06:36:28146using WebKit::WebVector;
147using WebKit::WebWidget;
[email protected]27ba8532009-04-24 20:22:43148using WebKit::WebWorker;
149using WebKit::WebWorkerClient;
[email protected]e1acf6f2008-10-27 20:43:33150
initial.commit09911bf2008-07-26 23:55:29151//-----------------------------------------------------------------------------
152
153// define to write the time necessary for thumbnail/DOM text retrieval,
154// respectively, into the system debug log
155// #define TIME_BITMAP_RETRIEVAL
156// #define TIME_TEXT_RETRIEVAL
157
158// maximum number of characters in the document to index, any text beyond this
159// point will be clipped
[email protected]6c8afae52009-01-22 02:24:57160static const size_t kMaxIndexChars = 65535;
initial.commit09911bf2008-07-26 23:55:29161
162// Size of the thumbnails that we'll generate
[email protected]8b4f4892009-09-04 21:52:37163static const int kThumbnailWidth = 212;
164static const int kThumbnailHeight = 132;
initial.commit09911bf2008-07-26 23:55:29165
166// Delay in milliseconds that we'll wait before capturing the page contents
167// and thumbnail.
168static const int kDelayForCaptureMs = 500;
169
170// Typically, we capture the page data once the page is loaded.
171// Sometimes, the page never finishes to load, preventing the page capture
172// To workaround this problem, we always perform a capture after the following
173// delay.
174static const int kDelayForForcedCaptureMs = 6000;
175
[email protected]81a34412009-01-05 19:17:24176// The default value for RenderView.delay_seconds_for_form_state_sync_, see
177// that variable for more.
178const int kDefaultDelaySecondsForFormStateSync = 5;
initial.commit09911bf2008-07-26 23:55:29179
180// The next available page ID to use. This ensures that the page IDs are
181// globally unique in the renderer.
182static int32 next_page_id_ = 1;
183
[email protected]0aa55312008-10-17 21:53:08184// The maximum number of popups that can be spawned from one page.
185static const int kMaximumNumberOfUnacknowledgedPopups = 25;
186
initial.commit09911bf2008-07-26 23:55:29187static const char* const kUnreachableWebDataURL =
[email protected]60e448982009-05-06 04:21:16188 "chrome://chromewebdata/";
initial.commit09911bf2008-07-26 23:55:29189
[email protected]50b691c2008-10-31 19:08:35190static const char* const kBackForwardNavigationScheme = "history";
191
[email protected]726985e22009-06-18 21:09:28192static void GetRedirectChain(WebDataSource* ds, std::vector<GURL>* result) {
193 WebVector<WebURL> urls;
194 ds->redirectChain(urls);
195 result->reserve(urls.size());
196 for (size_t i = 0; i < urls.size(); ++i)
197 result->push_back(urls[i]);
198}
199
initial.commit09911bf2008-07-26 23:55:29200///////////////////////////////////////////////////////////////////////////////
201
[email protected]2fab253a2009-08-17 23:00:59202RenderView::RenderView(RenderThreadBase* render_thread,
203 const WebPreferences& webkit_preferences)
[email protected]81a34412009-01-05 19:17:24204 : RenderWidget(render_thread, true),
[email protected]81e63782009-02-27 19:35:09205 enabled_bindings_(0),
[email protected]e75cb49e2009-01-05 23:13:21206 target_url_status_(TARGET_NONE),
[email protected]81a34412009-01-05 19:17:24207 is_loading_(false),
[email protected]e75cb49e2009-01-05 23:13:21208 navigation_gesture_(NavigationGestureUnknown),
[email protected]81a34412009-01-05 19:17:24209 page_id_(-1),
210 last_page_id_sent_to_browser_(-1),
211 last_indexed_page_id_(-1),
[email protected]81a34412009-01-05 19:17:24212 opened_by_user_gesture_(true),
[email protected]bb063b72009-03-27 23:18:50213 ALLOW_THIS_IN_INITIALIZER_LIST(method_factory_(this)),
[email protected]e4ac5df2009-03-17 15:33:11214 devtools_agent_(NULL),
215 devtools_client_(NULL),
[email protected]81a34412009-01-05 19:17:24216 history_back_list_count_(0),
217 history_forward_list_count_(0),
[email protected]81a34412009-01-05 19:17:24218 has_unload_listener_(false),
219 decrement_shared_popup_at_destruction_(false),
[email protected]81a34412009-01-05 19:17:24220 form_field_autofill_request_id_(0),
221 popup_notification_visible_(false),
[email protected]8922e1f2009-10-03 05:01:26222 spelling_panel_visible_(false),
[email protected]0666aef2009-05-13 19:48:08223 delay_seconds_for_form_state_sync_(kDefaultDelaySecondsForFormStateSync),
224 preferred_width_(0),
[email protected]5c4266922009-07-10 16:41:27225 send_preferred_width_changes_(false),
[email protected]5f450e52009-07-28 13:28:11226 determine_page_text_after_loading_stops_(false),
[email protected]7b291f92009-08-14 05:43:53227 view_type_(ViewType::INVALID),
228 browser_window_id_(-1),
[email protected]83dde542009-09-11 20:59:55229 last_top_level_navigation_page_id_(-1),
230#if defined(OS_MACOSX)
231 has_document_tag_(false),
232#endif
[email protected]98324892009-09-09 21:16:05233 document_tag_(0),
[email protected]2fab253a2009-08-17 23:00:59234 webkit_preferences_(webkit_preferences) {
[email protected]7b291f92009-08-14 05:43:53235 Singleton<RenderViewSet>()->render_view_set_.insert(this);
initial.commit09911bf2008-07-26 23:55:29236}
237
238RenderView::~RenderView() {
[email protected]7b291f92009-08-14 05:43:53239 Singleton<RenderViewSet>()->render_view_set_.erase(this);
[email protected]0aa55312008-10-17 21:53:08240 if (decrement_shared_popup_at_destruction_)
241 shared_popup_counter_->data--;
242
[email protected]b0950a72009-09-29 23:16:17243 // Dispose of un-disposed image fetchers.
244 for (ImageResourceFetcherSet::iterator i = image_fetchers_.begin();
245 i != image_fetchers_.end(); ++i) {
246 delete *i;
247 }
248
[email protected]83dde542009-09-11 20:59:55249#if defined(OS_MACOSX)
[email protected]98324892009-09-09 21:16:05250 // Tell the spellchecker that the document is closed.
[email protected]83dde542009-09-11 20:59:55251 if (has_document_tag_)
252 Send(new ViewHostMsg_DocumentWithTagClosed(routing_id_, document_tag_));
253#endif
[email protected]98324892009-09-09 21:16:05254
[email protected]5fb88962009-04-16 19:03:25255 render_thread_->RemoveFilter(audio_message_filter_);
[email protected]90e908552009-10-05 01:40:12256 render_thread_->RemoveFilter(notification_provider_.get());
initial.commit09911bf2008-07-26 23:55:29257}
258
259/*static*/
[email protected]0aa55312008-10-17 21:53:08260RenderView* RenderView::Create(
[email protected]81a34412009-01-05 19:17:24261 RenderThreadBase* render_thread,
[email protected]18bcc3c2009-01-27 21:39:15262 gfx::NativeViewId parent_hwnd,
[email protected]0aa55312008-10-17 21:53:08263 int32 opener_id,
[email protected]80d96fa2009-06-10 22:34:51264 const RendererPreferences& renderer_prefs,
[email protected]0aa55312008-10-17 21:53:08265 const WebPreferences& webkit_prefs,
266 SharedRenderViewCounter* counter,
267 int32 routing_id) {
initial.commit09911bf2008-07-26 23:55:29268 DCHECK(routing_id != MSG_ROUTING_NONE);
[email protected]2fab253a2009-08-17 23:00:59269 scoped_refptr<RenderView> view = new RenderView(render_thread, webkit_prefs);
initial.commit09911bf2008-07-26 23:55:29270 view->Init(parent_hwnd,
initial.commit09911bf2008-07-26 23:55:29271 opener_id,
[email protected]80d96fa2009-06-10 22:34:51272 renderer_prefs,
[email protected]0aa55312008-10-17 21:53:08273 counter,
initial.commit09911bf2008-07-26 23:55:29274 routing_id); // adds reference
275 return view;
276}
277
278/*static*/
279void RenderView::SetNextPageID(int32 next_page_id) {
280 // This method should only be called during process startup, and the given
281 // page id had better not exceed our current next page id!
[email protected]4646f292009-05-20 03:49:05282 DCHECK_EQ(next_page_id_, 1);
initial.commit09911bf2008-07-26 23:55:29283 DCHECK(next_page_id >= next_page_id_);
284 next_page_id_ = next_page_id;
285}
286
[email protected]1dbafaf72009-09-23 19:43:56287void RenderView::UserMetricsRecordAction(const std::wstring& action) {
288 Send(new ViewHostMsg_UserMetricsRecordAction(routing_id_, action));
289}
290
[email protected]fb466342009-07-15 00:43:08291void RenderView::PluginCrashed(base::ProcessId pid,
292 const FilePath& plugin_path) {
293 Send(new ViewHostMsg_CrashedPlugin(routing_id_, pid, plugin_path));
initial.commit09911bf2008-07-26 23:55:29294}
295
[email protected]18bcc3c2009-01-27 21:39:15296void RenderView::Init(gfx::NativeViewId parent_hwnd,
initial.commit09911bf2008-07-26 23:55:29297 int32 opener_id,
[email protected]80d96fa2009-06-10 22:34:51298 const RendererPreferences& renderer_prefs,
[email protected]0aa55312008-10-17 21:53:08299 SharedRenderViewCounter* counter,
initial.commit09911bf2008-07-26 23:55:29300 int32 routing_id) {
301 DCHECK(!webview());
302
303 if (opener_id != MSG_ROUTING_NONE)
304 opener_id_ = opener_id;
305
[email protected]0aa55312008-10-17 21:53:08306 if (counter) {
307 shared_popup_counter_ = counter;
308 shared_popup_counter_->data++;
309 decrement_shared_popup_at_destruction_ = true;
310 } else {
311 shared_popup_counter_ = new SharedRenderViewCounter(0);
312 decrement_shared_popup_at_destruction_ = false;
313 }
314
[email protected]58bfc6b2009-06-24 09:45:02315 devtools_agent_.reset(new DevToolsAgent(routing_id, this));
[email protected]9b9d7282009-04-08 14:13:04316
[email protected]90e908552009-10-05 01:40:12317 notification_provider_ = new NotificationProvider(this);
318
[email protected]04fc9482009-09-18 22:13:03319 webwidget_ = WebView::Create(this);
[email protected]2fab253a2009-08-17 23:00:59320 webkit_preferences_.Apply(webview());
[email protected]b4bb2502009-10-01 22:35:27321 webview()->initializeMainFrame(this);
initial.commit09911bf2008-07-26 23:55:29322
[email protected]d3ba77272009-09-03 00:06:09323 OnSetRendererPrefs(renderer_prefs);
324
initial.commit09911bf2008-07-26 23:55:29325 routing_id_ = routing_id;
[email protected]81a34412009-01-05 19:17:24326 render_thread_->AddRoute(routing_id_, this);
initial.commit09911bf2008-07-26 23:55:29327 // Take a reference on behalf of the RenderThread. This will be balanced
328 // when we receive ViewMsg_Close.
329 AddRef();
330
331 // If this is a popup, we must wait for the CreatingNew_ACK message before
332 // completing initialization. Otherwise, we can finish it now.
333 if (opener_id == MSG_ROUTING_NONE) {
334 did_show_ = true;
335 CompleteInit(parent_hwnd);
336 }
337
338 host_window_ = parent_hwnd;
initial.commit09911bf2008-07-26 23:55:29339
[email protected]58bfc6b2009-06-24 09:45:02340 const CommandLine& command_line = *CommandLine::ForCurrentProcess();
[email protected]81e63782009-02-27 19:35:09341 if (command_line.HasSwitch(switches::kDomAutomationController))
342 enabled_bindings_ |= BindingsPolicy::DOM_AUTOMATION;
initial.commit09911bf2008-07-26 23:55:29343
[email protected]5fb88962009-04-16 19:03:25344 audio_message_filter_ = new AudioMessageFilter(routing_id_);
345 render_thread_->AddFilter(audio_message_filter_);
[email protected]90e908552009-10-05 01:40:12346 render_thread_->AddFilter(notification_provider_.get());
initial.commit09911bf2008-07-26 23:55:29347}
348
349void RenderView::OnMessageReceived(const IPC::Message& message) {
[email protected]26aa0482009-09-30 16:55:27350 WebFrame* main_frame = webview() ? webview()->mainFrame() : NULL;
[email protected]ef916272009-07-08 21:40:55351 child_process_logging::ScopedActiveURLSetter url_setter(
[email protected]dd7daa82009-08-10 05:46:45352 main_frame ? main_frame->url() : WebURL());
[email protected]f8b6b6f2009-03-10 16:48:26353
[email protected]b2abac72009-02-26 12:39:28354 // If this is developer tools renderer intercept tools messages first.
[email protected]e4ac5df2009-03-17 15:33:11355 if (devtools_client_.get() && devtools_client_->OnMessageReceived(message))
[email protected]b2abac72009-02-26 12:39:28356 return;
[email protected]b4b967e2009-04-22 11:33:05357 if (devtools_agent_.get() && devtools_agent_->OnMessageReceived(message))
358 return;
[email protected]b2abac72009-02-26 12:39:28359
initial.commit09911bf2008-07-26 23:55:29360 IPC_BEGIN_MESSAGE_MAP(RenderView, message)
initial.commit09911bf2008-07-26 23:55:29361 IPC_MESSAGE_HANDLER(ViewMsg_CaptureThumbnail, SendThumbnail)
initial.commit09911bf2008-07-26 23:55:29362 IPC_MESSAGE_HANDLER(ViewMsg_PrintPages, OnPrintPages)
[email protected]82270452009-06-19 15:58:01363 IPC_MESSAGE_HANDLER(ViewMsg_PrintingDone, OnPrintingDone)
initial.commit09911bf2008-07-26 23:55:29364 IPC_MESSAGE_HANDLER(ViewMsg_Navigate, OnNavigate)
365 IPC_MESSAGE_HANDLER(ViewMsg_Stop, OnStop)
366 IPC_MESSAGE_HANDLER(ViewMsg_LoadAlternateHTMLText, OnLoadAlternateHTMLText)
367 IPC_MESSAGE_HANDLER(ViewMsg_StopFinding, OnStopFinding)
368 IPC_MESSAGE_HANDLER(ViewMsg_Undo, OnUndo)
369 IPC_MESSAGE_HANDLER(ViewMsg_Redo, OnRedo)
370 IPC_MESSAGE_HANDLER(ViewMsg_Cut, OnCut)
371 IPC_MESSAGE_HANDLER(ViewMsg_Copy, OnCopy)
[email protected]c0cc3092009-09-12 08:27:27372#if defined(OS_MACOSX)
[email protected]a954bf72009-09-12 07:30:35373 IPC_MESSAGE_HANDLER(ViewMsg_CopyToFindPboard, OnCopyToFindPboard)
[email protected]c0cc3092009-09-12 08:27:27374#endif
initial.commit09911bf2008-07-26 23:55:29375 IPC_MESSAGE_HANDLER(ViewMsg_Paste, OnPaste)
376 IPC_MESSAGE_HANDLER(ViewMsg_Replace, OnReplace)
[email protected]98324892009-09-09 21:16:05377 IPC_MESSAGE_HANDLER(ViewMsg_ToggleSpellPanel, OnToggleSpellPanel)
378 IPC_MESSAGE_HANDLER(ViewMsg_AdvanceToNextMisspelling,
379 OnAdvanceToNextMisspelling)
[email protected]bbbd545c2008-12-15 20:18:04380 IPC_MESSAGE_HANDLER(ViewMsg_ToggleSpellCheck, OnToggleSpellCheck)
initial.commit09911bf2008-07-26 23:55:29381 IPC_MESSAGE_HANDLER(ViewMsg_Delete, OnDelete)
382 IPC_MESSAGE_HANDLER(ViewMsg_SelectAll, OnSelectAll)
383 IPC_MESSAGE_HANDLER(ViewMsg_CopyImageAt, OnCopyImageAt)
[email protected]4b59ae602009-06-23 20:58:15384 IPC_MESSAGE_HANDLER(ViewMsg_ExecuteEditCommand, OnExecuteEditCommand)
initial.commit09911bf2008-07-26 23:55:29385 IPC_MESSAGE_HANDLER(ViewMsg_Find, OnFind)
[email protected]5c4266922009-07-10 16:41:27386 IPC_MESSAGE_HANDLER(ViewMsg_DeterminePageText, OnDeterminePageText)
[email protected]630e26b2008-10-14 22:55:17387 IPC_MESSAGE_HANDLER(ViewMsg_Zoom, OnZoom)
initial.commit09911bf2008-07-26 23:55:29388 IPC_MESSAGE_HANDLER(ViewMsg_SetPageEncoding, OnSetPageEncoding)
[email protected]a697f4c2009-09-14 22:30:18389 IPC_MESSAGE_HANDLER(ViewMsg_ResetPageEncodingToDefault,
390 OnResetPageEncodingToDefault)
[email protected]b2abac72009-02-26 12:39:28391 IPC_MESSAGE_HANDLER(ViewMsg_SetupDevToolsClient, OnSetupDevToolsClient)
[email protected]bf5c2ff392009-07-08 16:24:33392 IPC_MESSAGE_HANDLER(ViewMsg_DownloadFavIcon, OnDownloadFavIcon)
initial.commit09911bf2008-07-26 23:55:29393 IPC_MESSAGE_HANDLER(ViewMsg_ScriptEvalRequest, OnScriptEvalRequest)
[email protected]1810e132009-03-24 23:35:48394 IPC_MESSAGE_HANDLER(ViewMsg_CSSInsertRequest, OnCSSInsertRequest)
initial.commit09911bf2008-07-26 23:55:29395 IPC_MESSAGE_HANDLER(ViewMsg_AddMessageToConsole, OnAddMessageToConsole)
initial.commit09911bf2008-07-26 23:55:29396 IPC_MESSAGE_HANDLER(ViewMsg_ReservePageIDRange, OnReservePageIDRange)
397 IPC_MESSAGE_HANDLER(ViewMsg_UploadFile, OnUploadFileRequest)
398 IPC_MESSAGE_HANDLER(ViewMsg_FormFill, OnFormFill)
399 IPC_MESSAGE_HANDLER(ViewMsg_FillPasswordForm, OnFillPasswordForm)
400 IPC_MESSAGE_HANDLER(ViewMsg_DragTargetDragEnter, OnDragTargetDragEnter)
401 IPC_MESSAGE_HANDLER(ViewMsg_DragTargetDragOver, OnDragTargetDragOver)
402 IPC_MESSAGE_HANDLER(ViewMsg_DragTargetDragLeave, OnDragTargetDragLeave)
403 IPC_MESSAGE_HANDLER(ViewMsg_DragTargetDrop, OnDragTargetDrop)
[email protected]18cb2572008-08-21 20:34:45404 IPC_MESSAGE_HANDLER(ViewMsg_AllowBindings, OnAllowBindings)
initial.commit09911bf2008-07-26 23:55:29405 IPC_MESSAGE_HANDLER(ViewMsg_SetDOMUIProperty, OnSetDOMUIProperty)
[email protected]266eb6f2008-09-30 23:56:50406 IPC_MESSAGE_HANDLER(ViewMsg_DragSourceEndedOrMoved,
407 OnDragSourceEndedOrMoved)
initial.commit09911bf2008-07-26 23:55:29408 IPC_MESSAGE_HANDLER(ViewMsg_DragSourceSystemDragEnded,
409 OnDragSourceSystemDragEnded)
410 IPC_MESSAGE_HANDLER(ViewMsg_SetInitialFocus, OnSetInitialFocus)
411 IPC_MESSAGE_HANDLER(ViewMsg_FindReplyACK, OnFindReplyAck)
412 IPC_MESSAGE_HANDLER(ViewMsg_UpdateTargetURL_ACK, OnUpdateTargetURLAck)
413 IPC_MESSAGE_HANDLER(ViewMsg_UpdateWebPreferences, OnUpdateWebPreferences)
414 IPC_MESSAGE_HANDLER(ViewMsg_SetAltErrorPageURL, OnSetAltErrorPageURL)
415 IPC_MESSAGE_HANDLER(ViewMsg_InstallMissingPlugin, OnInstallMissingPlugin)
416 IPC_MESSAGE_HANDLER(ViewMsg_RunFileChooserResponse, OnFileChooserResponse)
417 IPC_MESSAGE_HANDLER(ViewMsg_EnableViewSourceMode, OnEnableViewSourceMode)
418 IPC_MESSAGE_HANDLER(ViewMsg_UpdateBackForwardListCount,
419 OnUpdateBackForwardListCount)
420 IPC_MESSAGE_HANDLER(ViewMsg_GetAllSavableResourceLinksForCurrentPage,
421 OnGetAllSavableResourceLinksForCurrentPage)
[email protected]f09c7182009-03-10 12:54:04422 IPC_MESSAGE_HANDLER(
423 ViewMsg_GetSerializedHtmlDataForCurrentPageWithLocalLinks,
424 OnGetSerializedHtmlDataForCurrentPageWithLocalLinks)
initial.commit09911bf2008-07-26 23:55:29425 IPC_MESSAGE_HANDLER(ViewMsg_GetApplicationInfo, OnGetApplicationInfo)
[email protected]266eb6f2008-09-30 23:56:50426 IPC_MESSAGE_HANDLER(ViewMsg_GetAccessibilityInfo, OnGetAccessibilityInfo)
427 IPC_MESSAGE_HANDLER(ViewMsg_ClearAccessibilityInfo,
428 OnClearAccessibilityInfo)
initial.commit09911bf2008-07-26 23:55:29429 IPC_MESSAGE_HANDLER(ViewMsg_ShouldClose, OnMsgShouldClose)
430 IPC_MESSAGE_HANDLER(ViewMsg_ClosePage, OnClosePage)
431 IPC_MESSAGE_HANDLER(ViewMsg_ThemeChanged, OnThemeChanged)
[email protected]18cb2572008-08-21 20:34:45432 IPC_MESSAGE_HANDLER(ViewMsg_HandleMessageFromExternalHost,
433 OnMessageFromExternalHost)
[email protected]0aa55312008-10-17 21:53:08434 IPC_MESSAGE_HANDLER(ViewMsg_DisassociateFromPopupCount,
435 OnDisassociateFromPopupCount)
[email protected]0ebf3872008-11-07 21:35:03436 IPC_MESSAGE_HANDLER(ViewMsg_AutofillSuggestions,
437 OnReceivedAutofillSuggestions)
[email protected]2c4410d2009-05-06 23:46:22438 IPC_MESSAGE_HANDLER(ViewMsg_PopupNotificationVisibilityChanged,
439 OnPopupNotificationVisibilityChanged)
[email protected]30f75e62009-02-25 22:01:00440 IPC_MESSAGE_HANDLER(ViewMsg_MoveOrResizeStarted, OnMoveOrResizeStarted)
[email protected]309d7a282009-03-24 09:18:27441 IPC_MESSAGE_HANDLER(ViewMsg_ExtensionResponse, OnExtensionResponse)
[email protected]7120f132009-07-20 21:05:37442 IPC_MESSAGE_HANDLER(ViewMsg_ExtensionMessageInvoke,
443 OnExtensionMessageInvoke)
[email protected]05d478752009-04-08 23:38:16444 IPC_MESSAGE_HANDLER(ViewMsg_ClearFocusedNode, OnClearFocusedNode)
[email protected]699ab0d2009-04-23 23:19:14445 IPC_MESSAGE_HANDLER(ViewMsg_SetBackground, OnSetBackground)
[email protected]0666aef2009-05-13 19:48:08446 IPC_MESSAGE_HANDLER(ViewMsg_EnableIntrinsicWidthChangedMode,
447 OnEnableIntrinsicWidthChangedMode)
[email protected]80d96fa2009-06-10 22:34:51448 IPC_MESSAGE_HANDLER(ViewMsg_SetRendererPrefs, OnSetRendererPrefs)
[email protected]7b291f92009-08-14 05:43:53449 IPC_MESSAGE_HANDLER(ViewMsg_UpdateBrowserWindowId,
450 OnUpdateBrowserWindowId)
451 IPC_MESSAGE_HANDLER(ViewMsg_NotifyRenderViewType,
452 OnNotifyRendererViewType)
[email protected]581b87eb2009-07-23 23:06:56453 IPC_MESSAGE_HANDLER(ViewMsg_MediaPlayerActionAt, OnMediaPlayerActionAt)
[email protected]8c66c5a2009-07-22 17:26:34454 IPC_MESSAGE_HANDLER(ViewMsg_SetActive, OnSetActive)
[email protected]446705872009-09-10 07:22:48455 IPC_MESSAGE_HANDLER(ViewMsg_SetEditCommandsForNextKeyEvent,
456 OnSetEditCommandsForNextKeyEvent);
[email protected]912256b32009-09-18 09:47:35457 IPC_MESSAGE_HANDLER(ViewMsg_ExecuteCode,
458 OnExecuteCode)
[email protected]634a6f92008-12-01 21:39:31459
initial.commit09911bf2008-07-26 23:55:29460 // Have the super handle all other messages.
461 IPC_MESSAGE_UNHANDLED(RenderWidget::OnMessageReceived(message))
462 IPC_END_MESSAGE_MAP()
463}
464
initial.commit09911bf2008-07-26 23:55:29465void RenderView::SendThumbnail() {
[email protected]26aa0482009-09-30 16:55:27466 WebFrame* main_frame = webview()->mainFrame();
initial.commit09911bf2008-07-26 23:55:29467 if (!main_frame)
468 return;
469
470 // get the URL for this page
[email protected]dd7daa82009-08-10 05:46:45471 GURL url(main_frame->url());
initial.commit09911bf2008-07-26 23:55:29472 if (url.is_empty())
473 return;
474
475 if (size_.IsEmpty())
476 return; // Don't create an empty thumbnail!
477
478 ThumbnailScore score;
479 SkBitmap thumbnail;
[email protected]8649fb32009-06-26 17:51:02480 if (!CaptureThumbnail(webview(), kThumbnailWidth, kThumbnailHeight,
[email protected]b6e4bec2008-11-12 01:17:15481 &thumbnail, &score))
482 return;
483
initial.commit09911bf2008-07-26 23:55:29484 // send the thumbnail message to the browser process
[email protected]674741932009-02-04 23:44:46485 Send(new ViewHostMsg_Thumbnail(routing_id_, url, score, thumbnail));
initial.commit09911bf2008-07-26 23:55:29486}
487
[email protected]068637222009-01-29 16:58:07488void RenderView::OnPrintPages() {
initial.commit09911bf2008-07-26 23:55:29489 DCHECK(webview());
[email protected]aa82249f2009-07-16 17:23:58490 if (webview()) {
491 // If the user has selected text in the currently focused frame we print
492 // only that frame (this makes print selection work for multiple frames).
[email protected]26aa0482009-09-30 16:55:27493 if (webview()->focusedFrame()->hasSelection())
494 Print(webview()->focusedFrame(), false);
[email protected]aa82249f2009-07-16 17:23:58495 else
[email protected]26aa0482009-09-30 16:55:27496 Print(webview()->mainFrame(), false);
[email protected]aa82249f2009-07-16 17:23:58497 }
initial.commit09911bf2008-07-26 23:55:29498}
499
[email protected]82270452009-06-19 15:58:01500void RenderView::OnPrintingDone(int document_cookie, bool success) {
501 // Ignoring document cookie here since only one print job can be outstanding
502 // per renderer and document_cookie is 0 when printing is successful.
503 DCHECK(print_helper_.get());
504 if (print_helper_.get() != NULL) {
505 print_helper_->DidFinishPrinting(success);
506 }
507}
508
initial.commit09911bf2008-07-26 23:55:29509void RenderView::CapturePageInfo(int load_id, bool preliminary_capture) {
510 if (load_id != page_id_)
511 return; // this capture call is no longer relevant due to navigation
512 if (load_id == last_indexed_page_id_)
513 return; // we already indexed this page
514
515 if (!webview())
516 return;
517
[email protected]26aa0482009-09-30 16:55:27518 WebFrame* main_frame = webview()->mainFrame();
initial.commit09911bf2008-07-26 23:55:29519 if (!main_frame)
520 return;
521
522 // Don't index/capture pages that are in view source mode.
[email protected]dd7daa82009-08-10 05:46:45523 if (main_frame->isViewSourceModeEnabled())
initial.commit09911bf2008-07-26 23:55:29524 return;
525
526 // Don't index/capture pages that failed to load. This only checks the top
527 // level frame so the thumbnail may contain a frame that failed to load.
[email protected]dd7daa82009-08-10 05:46:45528 WebDataSource* ds = main_frame->dataSource();
[email protected]726985e22009-06-18 21:09:28529 if (ds && ds->hasUnreachableURL())
initial.commit09911bf2008-07-26 23:55:29530 return;
531
532 if (!preliminary_capture)
533 last_indexed_page_id_ = load_id;
534
535 // get the URL for this page
[email protected]dd7daa82009-08-10 05:46:45536 GURL url(main_frame->url());
initial.commit09911bf2008-07-26 23:55:29537 if (url.is_empty())
538 return;
539
540 // full text
541 std::wstring contents;
542 CaptureText(main_frame, &contents);
543 if (contents.size()) {
544 // Send the text to the browser for indexing.
545 Send(new ViewHostMsg_PageContents(url, load_id, contents));
546 }
547
[email protected]5c4266922009-07-10 16:41:27548 // Send over text content of this page to the browser.
549 if (determine_page_text_after_loading_stops_) {
550 determine_page_text_after_loading_stops_ = false;
551 Send(new ViewMsg_DeterminePageText_Reply(routing_id_, contents));
552 }
553
initial.commit09911bf2008-07-26 23:55:29554 // thumbnail
555 SendThumbnail();
556}
557
558void RenderView::CaptureText(WebFrame* frame, std::wstring* contents) {
559 contents->clear();
560 if (!frame)
561 return;
562
[email protected]0faf0bd92008-09-09 20:53:27563 // Don't index any https pages. People generally don't want their bank
564 // accounts, etc. indexed on their computer, especially since some of these
565 // things are not marked cachable.
566 // TODO(brettw) we may want to consider more elaborate heuristics such as
567 // the cachability of the page. We may also want to consider subframes (this
568 // test will still index subframes if the subframe is SSL).
[email protected]dd7daa82009-08-10 05:46:45569 if (GURL(frame->url()).SchemeIsSecure())
[email protected]0faf0bd92008-09-09 20:53:27570 return;
571
initial.commit09911bf2008-07-26 23:55:29572#ifdef TIME_TEXT_RETRIEVAL
573 double begin = time_util::GetHighResolutionTimeNow();
574#endif
575
576 // get the contents of the frame
[email protected]dd7daa82009-08-10 05:46:45577 *contents = UTF16ToWideHack(frame->contentAsText(kMaxIndexChars));
initial.commit09911bf2008-07-26 23:55:29578
579#ifdef TIME_TEXT_RETRIEVAL
580 double end = time_util::GetHighResolutionTimeNow();
581 char buf[128];
582 sprintf_s(buf, "%d chars retrieved for indexing in %gms\n",
583 contents.size(), (end - begin)*1000);
584 OutputDebugStringA(buf);
585#endif
586
587 // When the contents are clipped to the maximum, we don't want to have a
588 // partial word indexed at the end that might have been clipped. Therefore,
589 // terminate the string at the last space to ensure no words are clipped.
590 if (contents->size() == kMaxIndexChars) {
591 size_t last_space_index = contents->find_last_of(kWhitespaceWide);
592 if (last_space_index == std::wstring::npos)
593 return; // don't index if we got a huge block of text with no spaces
594 contents->resize(last_space_index);
595 }
596}
597
[email protected]8649fb32009-06-26 17:51:02598bool RenderView::CaptureThumbnail(WebView* view,
initial.commit09911bf2008-07-26 23:55:29599 int w,
600 int h,
601 SkBitmap* thumbnail,
602 ThumbnailScore* score) {
603#ifdef TIME_BITMAP_RETRIEVAL
604 double begin = time_util::GetHighResolutionTimeNow();
605#endif
606
[email protected]4873c7d2009-07-16 06:36:28607 view->layout();
608 const WebSize& size = view->size();
[email protected]b6e4bec2008-11-12 01:17:15609
[email protected]8649fb32009-06-26 17:51:02610 skia::PlatformCanvas canvas;
611 if (!canvas.initialize(size.width, size.height, true))
612 return false;
[email protected]8c89e7792009-08-19 21:18:34613 view->paint(webkit_glue::ToWebCanvas(&canvas),
614 WebRect(0, 0, size.width, size.height));
[email protected]8649fb32009-06-26 17:51:02615
616 skia::BitmapPlatformDevice& device =
617 static_cast<skia::BitmapPlatformDevice&>(canvas.getTopPlatformDevice());
618
619 const SkBitmap& src_bmp = device.accessBitmap(false);
initial.commit09911bf2008-07-26 23:55:29620
[email protected]cab34d6a2009-09-24 01:14:52621 SkRect dest_rect = { 0, 0, SkIntToScalar(w), SkIntToScalar(h) };
initial.commit09911bf2008-07-26 23:55:29622 float dest_aspect = dest_rect.width() / dest_rect.height();
623
624 // Get the src rect so that we can preserve the aspect ratio while filling
625 // the destination.
626 SkIRect src_rect;
627 if (src_bmp.width() < dest_rect.width() ||
628 src_bmp.height() < dest_rect.height()) {
629 // Source image is smaller: we clip the part of source image within the
630 // dest rect, and then stretch it to fill the dest rect. We don't respect
631 // the aspect ratio in this case.
632 src_rect.set(0, 0, static_cast<S16CPU>(dest_rect.width()),
633 static_cast<S16CPU>(dest_rect.height()));
634 score->good_clipping = false;
635 } else {
636 float src_aspect = static_cast<float>(src_bmp.width()) / src_bmp.height();
637 if (src_aspect > dest_aspect) {
638 // Wider than tall, clip horizontally: we center the smaller thumbnail in
639 // the wider screen.
640 S16CPU new_width = static_cast<S16CPU>(src_bmp.height() * dest_aspect);
641 S16CPU x_offset = (src_bmp.width() - new_width) / 2;
642 src_rect.set(x_offset, 0, new_width + x_offset, src_bmp.height());
643 score->good_clipping = false;
644 } else {
645 src_rect.set(0, 0, src_bmp.width(),
646 static_cast<S16CPU>(src_bmp.width() / dest_aspect));
647 score->good_clipping = true;
648 }
649 }
650
[email protected]26aa0482009-09-30 16:55:27651 score->at_top = (view->mainFrame()->scrollOffset().height == 0);
initial.commit09911bf2008-07-26 23:55:29652
653 SkBitmap subset;
[email protected]8649fb32009-06-26 17:51:02654 device.accessBitmap(false).extractSubset(&subset, src_rect);
initial.commit09911bf2008-07-26 23:55:29655
656 // Resample the subset that we want to get it the right size.
[email protected]465b34b72008-12-12 20:19:14657 *thumbnail = skia::ImageOperations::Resize(
658 subset, skia::ImageOperations::RESIZE_LANCZOS3, w, h);
initial.commit09911bf2008-07-26 23:55:29659
660 score->boring_score = CalculateBoringScore(thumbnail);
661
662#ifdef TIME_BITMAP_RETRIEVAL
663 double end = time_util::GetHighResolutionTimeNow();
664 char buf[128];
665 sprintf_s(buf, "thumbnail in %gms\n", (end - begin) * 1000);
666 OutputDebugStringA(buf);
667#endif
[email protected]b6e4bec2008-11-12 01:17:15668 return true;
initial.commit09911bf2008-07-26 23:55:29669}
670
671double RenderView::CalculateBoringScore(SkBitmap* bitmap) {
672 int histogram[256] = {0};
673 color_utils::BuildLumaHistogram(bitmap, histogram);
674
675 int color_count = *std::max_element(histogram, histogram + 256);
676 int pixel_count = bitmap->width() * bitmap->height();
677 return static_cast<double>(color_count) / pixel_count;
678}
679
680void RenderView::OnNavigate(const ViewMsg_Navigate_Params& params) {
681 if (!webview())
682 return;
683
[email protected]8c785c62009-07-13 14:20:15684 if (devtools_agent_.get())
685 devtools_agent_->OnNavigate();
686
[email protected]ef916272009-07-08 21:40:55687 child_process_logging::ScopedActiveURLSetter url_setter(params.url);
[email protected]f8b6b6f2009-03-10 16:48:26688
initial.commit09911bf2008-07-26 23:55:29689 AboutHandler::MaybeHandle(params.url);
690
691 bool is_reload = params.reload;
692
[email protected]26aa0482009-09-30 16:55:27693 WebFrame* main_frame = webview()->mainFrame();
[email protected]dd7daa82009-08-10 05:46:45694 if (is_reload && main_frame->currentHistoryItem().isNull()) {
initial.commit09911bf2008-07-26 23:55:29695 // We cannot reload if we do not have any history state. This happens, for
696 // example, when recovering from a crash. Our workaround here is a bit of
697 // a hack since it means that reload after a crashed tab does not cause an
698 // end-to-end cache validation.
699 is_reload = false;
700 }
701
[email protected]77f17a82009-05-21 04:42:54702 // A navigation resulting from loading a javascript URL should not be treated
703 // as a browser initiated event. Instead, we want it to look as if the page
704 // initiated any load resulting from JS execution.
705 if (!params.url.SchemeIs(chrome::kJavaScriptScheme)) {
[email protected]daa8c58e2009-06-15 17:21:10706 pending_navigation_state_.reset(NavigationState::CreateBrowserInitiated(
[email protected]77f17a82009-05-21 04:42:54707 params.page_id, params.transition, params.request_time));
708 }
initial.commit09911bf2008-07-26 23:55:29709
[email protected]04d3c6e2009-05-22 17:00:13710 // If we are reloading, then WebKit will use the history state of the current
711 // page, so we should just ignore any given history state. Otherwise, if we
712 // have history state, then we need to navigate to it, which corresponds to a
713 // back/forward navigation event.
[email protected]e6f546c32009-07-01 17:12:55714 if (is_reload) {
[email protected]dd7daa82009-08-10 05:46:45715 main_frame->reload();
[email protected]e6f546c32009-07-01 17:12:55716 } else if (!params.state.empty()) {
[email protected]04d3c6e2009-05-22 17:00:13717 // We must know the page ID of the page we are navigating back to.
[email protected]f929f2f22009-06-12 16:56:58718 DCHECK_NE(params.page_id, -1);
[email protected]dd7daa82009-08-10 05:46:45719 main_frame->loadHistoryItem(
[email protected]ca948a22009-06-25 19:36:17720 webkit_glue::HistoryItemFromString(params.state));
[email protected]04d3c6e2009-05-22 17:00:13721 } else {
722 // Navigate to the given URL.
[email protected]726985e22009-06-18 21:09:28723 WebURLRequest request(params.url);
initial.commit09911bf2008-07-26 23:55:29724
[email protected]e6f546c32009-07-01 17:12:55725 // A session history navigation should have been accompanied by state.
726 DCHECK_EQ(params.page_id, -1);
[email protected]04d3c6e2009-05-22 17:00:13727
[email protected]dd7daa82009-08-10 05:46:45728 if (main_frame->isViewSourceModeEnabled())
[email protected]e6f546c32009-07-01 17:12:55729 request.setCachePolicy(WebURLRequest::ReturnCacheDataElseLoad);
[email protected]04d3c6e2009-05-22 17:00:13730
[email protected]726985e22009-06-18 21:09:28731 if (params.referrer.is_valid()) {
732 request.setHTTPHeaderField(WebString::fromUTF8("Referer"),
733 WebString::fromUTF8(params.referrer.spec()));
734 }
[email protected]04d3c6e2009-05-22 17:00:13735
[email protected]dd7daa82009-08-10 05:46:45736 main_frame->loadRequest(request);
[email protected]c0588052008-10-27 23:01:50737 }
738
[email protected]77f17a82009-05-21 04:42:54739 // In case LoadRequest failed before DidCreateDataSource was called.
740 pending_navigation_state_.reset();
initial.commit09911bf2008-07-26 23:55:29741}
742
743// Stop loading the current page
744void RenderView::OnStop() {
745 if (webview())
[email protected]b4bb2502009-10-01 22:35:27746 webview()->mainFrame()->stopLoading();
initial.commit09911bf2008-07-26 23:55:29747}
748
[email protected]e6f546c32009-07-01 17:12:55749void RenderView::OnLoadAlternateHTMLText(const std::string& html,
initial.commit09911bf2008-07-26 23:55:29750 bool new_navigation,
751 const GURL& display_url,
752 const std::string& security_info) {
753 if (!webview())
754 return;
755
[email protected]e6f546c32009-07-01 17:12:55756 pending_navigation_state_.reset(NavigationState::CreateBrowserInitiated(
757 new_navigation ? -1 : page_id_, PageTransition::LINK, Time::Now()));
758 pending_navigation_state_->set_security_info(security_info);
initial.commit09911bf2008-07-26 23:55:29759
[email protected]26aa0482009-09-30 16:55:27760 webview()->mainFrame()->loadHTMLString(
761 html, GURL(kUnreachableWebDataURL), display_url, !new_navigation);
[email protected]e6f546c32009-07-01 17:12:55762
763 pending_navigation_state_.reset();
initial.commit09911bf2008-07-26 23:55:29764}
765
766void RenderView::OnCopyImageAt(int x, int y) {
[email protected]26aa0482009-09-30 16:55:27767 webview()->copyImageAt(WebPoint(x, y));
initial.commit09911bf2008-07-26 23:55:29768}
769
[email protected]68b1e922009-06-23 16:00:25770void RenderView::OnExecuteEditCommand(const std::string& name,
771 const std::string& value) {
[email protected]26aa0482009-09-30 16:55:27772 if (!webview() || !webview()->focusedFrame())
[email protected]68b1e922009-06-23 16:00:25773 return;
774
[email protected]26aa0482009-09-30 16:55:27775 webview()->focusedFrame()->executeCommand(
[email protected]dd7daa82009-08-10 05:46:45776 WebString::fromUTF8(name), WebString::fromUTF8(value));
[email protected]68b1e922009-06-23 16:00:25777}
778
[email protected]b2abac72009-02-26 12:39:28779void RenderView::OnSetupDevToolsClient() {
[email protected]e4ac5df2009-03-17 15:33:11780 DCHECK(!devtools_client_.get());
781 devtools_client_.reset(new DevToolsClient(this));
[email protected]b2abac72009-02-26 12:39:28782}
783
initial.commit09911bf2008-07-26 23:55:29784void RenderView::OnStopFinding(bool clear_selection) {
785 WebView* view = webview();
786 if (!view)
787 return;
788
789 if (clear_selection)
[email protected]26aa0482009-09-30 16:55:27790 view->focusedFrame()->executeCommand(WebString::fromUTF8("Unselect"));
initial.commit09911bf2008-07-26 23:55:29791
[email protected]26aa0482009-09-30 16:55:27792 WebFrame* frame = view->mainFrame();
initial.commit09911bf2008-07-26 23:55:29793 while (frame) {
[email protected]dd7daa82009-08-10 05:46:45794 frame->stopFinding(clear_selection);
[email protected]b4bb2502009-10-01 22:35:27795 frame = frame->traverseNext(false);
initial.commit09911bf2008-07-26 23:55:29796 }
797}
798
799void RenderView::OnFindReplyAck() {
800 // Check if there is any queued up request waiting to be sent.
801 if (queued_find_reply_message_.get()) {
802 // Send the search result over to the browser process.
803 Send(queued_find_reply_message_.get());
804 queued_find_reply_message_.release();
805 }
806}
807
808void RenderView::OnUpdateTargetURLAck() {
809 // Check if there is a targeturl waiting to be sent.
810 if (target_url_status_ == TARGET_PENDING) {
811 Send(new ViewHostMsg_UpdateTargetURL(routing_id_, page_id_,
812 pending_target_url_));
813 }
814
815 target_url_status_ = TARGET_NONE;
816}
817
818void RenderView::OnUndo() {
819 if (!webview())
820 return;
821
[email protected]26aa0482009-09-30 16:55:27822 webview()->focusedFrame()->executeCommand(WebString::fromUTF8("Undo"));
[email protected]dd7daa82009-08-10 05:46:45823 UserMetricsRecordAction(L"Undo");
initial.commit09911bf2008-07-26 23:55:29824}
825
826void RenderView::OnRedo() {
827 if (!webview())
828 return;
829
[email protected]26aa0482009-09-30 16:55:27830 webview()->focusedFrame()->executeCommand(WebString::fromUTF8("Redo"));
[email protected]dd7daa82009-08-10 05:46:45831 UserMetricsRecordAction(L"Redo");
initial.commit09911bf2008-07-26 23:55:29832}
833
834void RenderView::OnCut() {
835 if (!webview())
836 return;
837
[email protected]26aa0482009-09-30 16:55:27838 webview()->focusedFrame()->executeCommand(WebString::fromUTF8("Cut"));
[email protected]dd7daa82009-08-10 05:46:45839 UserMetricsRecordAction(L"Cut");
initial.commit09911bf2008-07-26 23:55:29840}
841
842void RenderView::OnCopy() {
843 if (!webview())
844 return;
845
[email protected]26aa0482009-09-30 16:55:27846 webview()->focusedFrame()->executeCommand(WebString::fromUTF8("Copy"));
[email protected]dd7daa82009-08-10 05:46:45847 UserMetricsRecordAction(L"Copy");
initial.commit09911bf2008-07-26 23:55:29848}
849
[email protected]c0cc3092009-09-12 08:27:27850#if defined(OS_MACOSX)
[email protected]a954bf72009-09-12 07:30:35851void RenderView::OnCopyToFindPboard() {
852 if (!webview())
853 return;
854
855 // Since the find pasteboard supports only plain text, this can be simpler
856 // than the |OnCopy()| case.
[email protected]26aa0482009-09-30 16:55:27857 WebFrame* frame = webview()->focusedFrame();
[email protected]a954bf72009-09-12 07:30:35858 if (frame->hasSelection()) {
859 string16 selection = frame->selectionAsText();
860 RenderThread::current()->Send(
861 new ViewHostMsg_ClipboardFindPboardWriteStringAsync(selection));
862 }
863
864 UserMetricsRecordAction(L"CopyToFindPboard");
865}
[email protected]c0cc3092009-09-12 08:27:27866#endif
[email protected]a954bf72009-09-12 07:30:35867
initial.commit09911bf2008-07-26 23:55:29868void RenderView::OnPaste() {
869 if (!webview())
870 return;
871
[email protected]26aa0482009-09-30 16:55:27872 webview()->focusedFrame()->executeCommand(WebString::fromUTF8("Paste"));
[email protected]dd7daa82009-08-10 05:46:45873 UserMetricsRecordAction(L"Paste");
initial.commit09911bf2008-07-26 23:55:29874}
875
876void RenderView::OnReplace(const std::wstring& text) {
877 if (!webview())
878 return;
879
[email protected]26aa0482009-09-30 16:55:27880 webview()->focusedFrame()->replaceSelection(WideToUTF16Hack(text));
initial.commit09911bf2008-07-26 23:55:29881}
882
[email protected]98324892009-09-09 21:16:05883void RenderView::OnAdvanceToNextMisspelling() {
884 if (!webview())
885 return;
[email protected]26aa0482009-09-30 16:55:27886 webview()->focusedFrame()->executeCommand(
[email protected]98324892009-09-09 21:16:05887 WebString::fromUTF8("AdvanceToNextMisspelling"));
888}
889
890void RenderView::OnToggleSpellPanel(bool is_currently_visible) {
891 if (!webview())
892 return;
893 // We need to tell the webView whether the spelling panel is visible or not so
894 // that it won't need to make ipc calls later.
[email protected]8922e1f2009-10-03 05:01:26895 spelling_panel_visible_ = is_currently_visible;
[email protected]26aa0482009-09-30 16:55:27896 webview()->focusedFrame()->executeCommand(
[email protected]98324892009-09-09 21:16:05897 WebString::fromUTF8("ToggleSpellPanel"));
898}
899
[email protected]bbbd545c2008-12-15 20:18:04900void RenderView::OnToggleSpellCheck() {
901 if (!webview())
902 return;
903
[email protected]26aa0482009-09-30 16:55:27904 WebFrame* frame = webview()->focusedFrame();
[email protected]dd7daa82009-08-10 05:46:45905 frame->enableContinuousSpellChecking(
906 !frame->isContinuousSpellCheckingEnabled());
[email protected]bbbd545c2008-12-15 20:18:04907}
908
initial.commit09911bf2008-07-26 23:55:29909void RenderView::OnDelete() {
910 if (!webview())
911 return;
912
[email protected]26aa0482009-09-30 16:55:27913 webview()->focusedFrame()->executeCommand(WebString::fromUTF8("Delete"));
[email protected]dd7daa82009-08-10 05:46:45914 UserMetricsRecordAction(L"DeleteSelection");
initial.commit09911bf2008-07-26 23:55:29915}
916
917void RenderView::OnSelectAll() {
918 if (!webview())
919 return;
920
[email protected]26aa0482009-09-30 16:55:27921 webview()->focusedFrame()->executeCommand(
[email protected]a100d76bb2009-08-14 17:50:22922 WebString::fromUTF8("SelectAll"));
923 UserMetricsRecordAction(L"SelectAll");
initial.commit09911bf2008-07-26 23:55:29924}
925
926void RenderView::OnSetInitialFocus(bool reverse) {
927 if (!webview())
928 return;
[email protected]26aa0482009-09-30 16:55:27929 webview()->setInitialFocus(reverse);
initial.commit09911bf2008-07-26 23:55:29930}
931
932///////////////////////////////////////////////////////////////////////////////
933
934// Tell the embedding application that the URL of the active page has changed
935void RenderView::UpdateURL(WebFrame* frame) {
[email protected]dd7daa82009-08-10 05:46:45936 WebDataSource* ds = frame->dataSource();
initial.commit09911bf2008-07-26 23:55:29937 DCHECK(ds);
938
[email protected]726985e22009-06-18 21:09:28939 const WebURLRequest& request = ds->request();
940 const WebURLRequest& original_request = ds->originalRequest();
941 const WebURLResponse& response = ds->response();
initial.commit09911bf2008-07-26 23:55:29942
[email protected]daa8c58e2009-06-15 17:21:10943 NavigationState* navigation_state = NavigationState::FromDataSource(ds);
944 DCHECK(navigation_state);
initial.commit09911bf2008-07-26 23:55:29945
946 ViewHostMsg_FrameNavigate_Params params;
[email protected]726985e22009-06-18 21:09:28947 params.http_status_code = response.httpStatusCode();
initial.commit09911bf2008-07-26 23:55:29948 params.is_post = false;
949 params.page_id = page_id_;
[email protected]726985e22009-06-18 21:09:28950 params.is_content_filtered = response.isContentFiltered();
[email protected]e6f546c32009-07-01 17:12:55951 if (!navigation_state->security_info().empty()) {
initial.commit09911bf2008-07-26 23:55:29952 // SSL state specified in the request takes precedence over the one in the
953 // response.
954 // So far this is only intended for error pages that are not expected to be
955 // over ssl, so we should not get any clash.
[email protected]726985e22009-06-18 21:09:28956 DCHECK(response.securityInfo().isEmpty());
[email protected]e6f546c32009-07-01 17:12:55957 params.security_info = navigation_state->security_info();
initial.commit09911bf2008-07-26 23:55:29958 } else {
[email protected]726985e22009-06-18 21:09:28959 params.security_info = response.securityInfo();
initial.commit09911bf2008-07-26 23:55:29960 }
961
962 // Set the URL to be displayed in the browser UI to the user.
[email protected]726985e22009-06-18 21:09:28963 if (ds->hasUnreachableURL()) {
964 params.url = ds->unreachableURL();
initial.commit09911bf2008-07-26 23:55:29965 } else {
[email protected]726985e22009-06-18 21:09:28966 params.url = request.url();
initial.commit09911bf2008-07-26 23:55:29967 }
968
[email protected]726985e22009-06-18 21:09:28969 GetRedirectChain(ds, &params.redirects);
970 params.should_update_history = !ds->hasUnreachableURL();
initial.commit09911bf2008-07-26 23:55:29971
972 const SearchableFormData* searchable_form_data =
[email protected]daa8c58e2009-06-15 17:21:10973 navigation_state->searchable_form_data();
initial.commit09911bf2008-07-26 23:55:29974 if (searchable_form_data) {
975 params.searchable_form_url = searchable_form_data->url();
976 params.searchable_form_element_name = searchable_form_data->element_name();
977 params.searchable_form_encoding = searchable_form_data->encoding();
978 }
979
980 const PasswordForm* password_form_data =
[email protected]daa8c58e2009-06-15 17:21:10981 navigation_state->password_form_data();
initial.commit09911bf2008-07-26 23:55:29982 if (password_form_data)
983 params.password_form = *password_form_data;
984
985 params.gesture = navigation_gesture_;
986 navigation_gesture_ = NavigationGestureUnknown;
987
[email protected]dd7daa82009-08-10 05:46:45988 if (!frame->parent()) {
initial.commit09911bf2008-07-26 23:55:29989 // Top-level navigation.
990
991 // Update contents MIME type for main frame.
[email protected]9c5645b2009-08-11 03:37:55992 params.contents_mime_type = ds->response().mimeType().utf8();
initial.commit09911bf2008-07-26 23:55:29993
[email protected]daa8c58e2009-06-15 17:21:10994 params.transition = navigation_state->transition_type();
initial.commit09911bf2008-07-26 23:55:29995 if (!PageTransition::IsMainFrame(params.transition)) {
996 // If the main frame does a load, it should not be reported as a subframe
997 // navigation. This can occur in the following case:
998 // 1. You're on a site with frames.
999 // 2. You do a subframe navigation. This is stored with transition type
1000 // MANUAL_SUBFRAME.
1001 // 3. You navigate to some non-frame site, say, google.com.
1002 // 4. You navigate back to the page from step 2. Since it was initially
1003 // MANUAL_SUBFRAME, it will be that same transition type here.
1004 // We don't want that, because any navigation that changes the toplevel
1005 // frame should be tracked as a toplevel navigation (this allows us to
1006 // update the URL bar, etc).
1007 params.transition = PageTransition::LINK;
1008 }
1009
initial.commit09911bf2008-07-26 23:55:291010 // If we have a valid consumed client redirect source,
1011 // the page contained a client redirect (meta refresh, document.loc...),
1012 // so we set the referrer and transition to match.
1013 if (completed_client_redirect_src_.is_valid()) {
[email protected]77e09a92008-08-01 18:11:041014 DCHECK(completed_client_redirect_src_ == params.redirects[0]);
initial.commit09911bf2008-07-26 23:55:291015 params.referrer = completed_client_redirect_src_;
1016 params.transition = static_cast<PageTransition::Type>(
1017 params.transition | PageTransition::CLIENT_REDIRECT);
1018 } else {
1019 // Bug 654101: the referrer will be empty on https->http transitions. It
1020 // would be nice if we could get the real referrer from somewhere.
[email protected]726985e22009-06-18 21:09:281021 params.referrer = GURL(
1022 original_request.httpHeaderField(WebString::fromUTF8("Referer")));
initial.commit09911bf2008-07-26 23:55:291023 }
1024
[email protected]726985e22009-06-18 21:09:281025 string16 method = request.httpMethod();
1026 if (EqualsASCII(method, "POST"))
initial.commit09911bf2008-07-26 23:55:291027 params.is_post = true;
1028
[email protected]c2a797d2009-09-21 16:46:321029 // Save some histogram data so we can compute the average memory used per
1030 // page load of the glyphs.
1031 UMA_HISTOGRAM_COUNTS_10000("Memory.GlyphPagesPerLoad",
1032 webkit_glue::GetGlyphPageCount());
1033
initial.commit09911bf2008-07-26 23:55:291034 Send(new ViewHostMsg_FrameNavigate(routing_id_, params));
1035 } else {
1036 // Subframe navigation: the type depends on whether this navigation
1037 // generated a new session history entry. When they do generate a session
1038 // history entry, it means the user initiated the navigation and we should
1039 // mark it as such. This test checks if this is the first time UpdateURL
1040 // has been called since WillNavigateToURL was called to initiate the load.
1041 if (page_id_ > last_page_id_sent_to_browser_)
1042 params.transition = PageTransition::MANUAL_SUBFRAME;
1043 else
1044 params.transition = PageTransition::AUTO_SUBFRAME;
1045
initial.commit09911bf2008-07-26 23:55:291046 Send(new ViewHostMsg_FrameNavigate(routing_id_, params));
1047 }
1048
1049 last_page_id_sent_to_browser_ =
1050 std::max(last_page_id_sent_to_browser_, page_id_);
1051
1052 // If we end up reusing this WebRequest (for example, due to a #ref click),
[email protected]daa8c58e2009-06-15 17:21:101053 // we don't want the transition type to persist. Just clear it.
1054 navigation_state->set_transition_type(PageTransition::LINK);
[email protected]266eb6f2008-09-30 23:56:501055
[email protected]6c8afae52009-01-22 02:24:571056#if defined(OS_WIN)
[email protected]6a983b42009-03-20 20:12:251057 if (web_accessibility_manager_.get()) {
[email protected]be645db2009-02-06 20:36:331058 // Clear accessibility info cache.
[email protected]6a983b42009-03-20 20:12:251059 web_accessibility_manager_->ClearAccObjMap(-1, true);
[email protected]266eb6f2008-09-30 23:56:501060 }
[email protected]6c8afae52009-01-22 02:24:571061#else
[email protected]7d926f92009-03-03 14:26:541062 // TODO(port): accessibility not yet implemented. See http://crbug.com/8288.
[email protected]6c8afae52009-01-22 02:24:571063#endif
initial.commit09911bf2008-07-26 23:55:291064}
1065
1066// Tell the embedding application that the title of the active page has changed
[email protected]3d9689372009-09-10 04:29:171067void RenderView::UpdateTitle(WebFrame* frame, const string16& title) {
initial.commit09911bf2008-07-26 23:55:291068 // Ignore all but top level navigations...
[email protected]3d9689372009-09-10 04:29:171069 if (!frame->parent()) {
[email protected]f0af6a72009-05-30 05:25:171070 Send(new ViewHostMsg_UpdateTitle(
[email protected]3d9689372009-09-10 04:29:171071 routing_id_,
1072 page_id_,
1073 UTF16ToWideHack(title.length() > chrome::kMaxTitleChars ?
1074 title.substr(0, chrome::kMaxTitleChars) : title)));
[email protected]f0af6a72009-05-30 05:25:171075 }
initial.commit09911bf2008-07-26 23:55:291076}
1077
1078void RenderView::UpdateEncoding(WebFrame* frame,
[email protected]41fc0322009-09-04 22:23:401079 const std::string& encoding_name) {
initial.commit09911bf2008-07-26 23:55:291080 // Only update main frame's encoding_name.
[email protected]26aa0482009-09-30 16:55:271081 if (webview()->mainFrame() == frame &&
initial.commit09911bf2008-07-26 23:55:291082 last_encoding_name_ != encoding_name) {
[email protected]e38f40152008-09-12 23:08:301083 // Save the encoding name for later comparing.
initial.commit09911bf2008-07-26 23:55:291084 last_encoding_name_ = encoding_name;
1085
[email protected]e38f40152008-09-12 23:08:301086 Send(new ViewHostMsg_UpdateEncoding(routing_id_, last_encoding_name_));
initial.commit09911bf2008-07-26 23:55:291087 }
1088}
1089
[email protected]f4d34b52008-11-24 23:05:011090// Sends the previous session history state to the browser so it will be saved
1091// before we navigate to a new page. This must be called *before* the page ID
1092// has been updated so we know what it was.
initial.commit09911bf2008-07-26 23:55:291093void RenderView::UpdateSessionHistory(WebFrame* frame) {
1094 // If we have a valid page ID at this point, then it corresponds to the page
1095 // we are navigating away from. Otherwise, this is the first navigation, so
1096 // there is no past session history to record.
1097 if (page_id_ == -1)
1098 return;
1099
[email protected]ca948a22009-06-25 19:36:171100 const WebHistoryItem& item =
[email protected]26aa0482009-09-30 16:55:271101 webview()->mainFrame()->previousHistoryItem();
[email protected]ca948a22009-06-25 19:36:171102 if (item.isNull())
initial.commit09911bf2008-07-26 23:55:291103 return;
[email protected]ca948a22009-06-25 19:36:171104
1105 Send(new ViewHostMsg_UpdateState(
1106 routing_id_, page_id_, webkit_glue::HistoryItemToString(item)));
initial.commit09911bf2008-07-26 23:55:291107}
1108
[email protected]3d9689372009-09-10 04:29:171109void RenderView::OpenURL(
1110 const GURL& url, const GURL& referrer, WebNavigationPolicy policy) {
1111 Send(new ViewHostMsg_OpenURL(
1112 routing_id_, url, referrer, NavigationPolicyToDisposition(policy)));
1113}
1114
[email protected]79dbc662009-09-04 05:42:511115// WebViewDelegate ------------------------------------------------------------
initial.commit09911bf2008-07-26 23:55:291116
[email protected]a2f6bc112009-06-27 16:27:251117void RenderView::DidPaint() {
[email protected]26aa0482009-09-30 16:55:271118 WebFrame* main_frame = webview()->mainFrame();
[email protected]a2f6bc112009-06-27 16:27:251119
[email protected]dd7daa82009-08-10 05:46:451120 if (main_frame->provisionalDataSource()) {
[email protected]a2f6bc112009-06-27 16:27:251121 // If we have a provisional frame we are between the start
1122 // and commit stages of loading...ignore this paint.
1123 return;
1124 }
1125
[email protected]dd7daa82009-08-10 05:46:451126 WebDataSource* ds = main_frame->dataSource();
[email protected]a2f6bc112009-06-27 16:27:251127 NavigationState* navigation_state = NavigationState::FromDataSource(ds);
[email protected]78a3a6f2009-07-02 16:15:011128 DCHECK(navigation_state);
1129
1130 Time now = Time::Now();
1131 if (navigation_state->first_paint_time().is_null()) {
1132 navigation_state->set_first_paint_time(now);
1133 }
1134 if (navigation_state->first_paint_after_load_time().is_null() &&
1135 !navigation_state->finish_load_time().is_null()) {
1136 navigation_state->set_first_paint_after_load_time(now);
[email protected]a2f6bc112009-06-27 16:27:251137 }
1138}
1139
initial.commit09911bf2008-07-26 23:55:291140void RenderView::LoadNavigationErrorPage(WebFrame* frame,
[email protected]726985e22009-06-18 21:09:281141 const WebURLRequest& failed_request,
1142 const WebURLError& error,
initial.commit09911bf2008-07-26 23:55:291143 const std::string& html,
1144 bool replace) {
[email protected]726985e22009-06-18 21:09:281145 GURL failed_url = error.unreachableURL;
initial.commit09911bf2008-07-26 23:55:291146
1147 std::string alt_html;
1148 if (html.empty()) {
1149 // Use a local error page.
1150 int resource_id;
1151 DictionaryValue error_strings;
[email protected]726985e22009-06-18 21:09:281152 if (error.reason == net::ERR_CACHE_MISS &&
1153 EqualsASCII(failed_request.httpMethod(), "POST")) {
initial.commit09911bf2008-07-26 23:55:291154 GetFormRepostErrorValues(failed_url, &error_strings);
1155 resource_id = IDR_ERROR_NO_DETAILS_HTML;
1156 } else {
1157 GetLocalizedErrorValues(error, &error_strings);
1158 resource_id = IDR_NET_ERROR_HTML;
1159 }
[email protected]8e50b602009-03-03 22:59:431160 error_strings.SetString(L"textdirection",
1161 (l10n_util::GetTextDirection() == l10n_util::RIGHT_TO_LEFT) ?
1162 L"rtl" : L"ltr");
initial.commit09911bf2008-07-26 23:55:291163
1164 alt_html = GetAltHTMLForTemplate(error_strings, resource_id);
1165 } else {
1166 alt_html = html;
1167 }
1168
[email protected]dd7daa82009-08-10 05:46:451169 frame->loadHTMLString(alt_html,
[email protected]e6f546c32009-07-01 17:12:551170 GURL(kUnreachableWebDataURL),
1171 failed_url,
1172 replace);
initial.commit09911bf2008-07-26 23:55:291173}
1174
[email protected]7ccddb8c2009-08-04 17:36:551175void RenderView::BindDOMAutomationController(WebFrame* frame) {
initial.commit09911bf2008-07-26 23:55:291176 dom_automation_controller_.set_message_sender(this);
1177 dom_automation_controller_.set_routing_id(routing_id_);
[email protected]7ccddb8c2009-08-04 17:36:551178 dom_automation_controller_.BindToJavascript(frame,
initial.commit09911bf2008-07-26 23:55:291179 L"domAutomationController");
1180}
1181
[email protected]b6ce15972009-07-14 22:14:011182void RenderView::DidCreateScriptContextForFrame(WebFrame* webframe) {
[email protected]7120f132009-07-20 21:05:371183 EventBindings::HandleContextCreated(webframe, false);
[email protected]f816c012009-06-26 21:48:321184}
1185
[email protected]b6ce15972009-07-14 22:14:011186void RenderView::DidDestroyScriptContextForFrame(WebFrame* webframe) {
[email protected]f816c012009-06-26 21:48:321187 EventBindings::HandleContextDestroyed(webframe);
1188}
1189
[email protected]b6ce15972009-07-14 22:14:011190void RenderView::DidCreateIsolatedScriptContext(WebFrame* webframe) {
[email protected]7120f132009-07-20 21:05:371191 EventBindings::HandleContextCreated(webframe, true);
[email protected]b6ce15972009-07-14 22:14:011192}
1193
initial.commit09911bf2008-07-26 23:55:291194bool RenderView::RunJavaScriptMessage(int type,
1195 const std::wstring& message,
1196 const std::wstring& default_value,
[email protected]a455d3812009-03-05 20:18:071197 const GURL& frame_url,
initial.commit09911bf2008-07-26 23:55:291198 std::wstring* result) {
1199 bool success = false;
1200 std::wstring result_temp;
1201 if (!result)
1202 result = &result_temp;
initial.commit09911bf2008-07-26 23:55:291203
[email protected]12636df2009-09-28 22:32:211204 SendAndRunNestedMessageLoop(new ViewHostMsg_RunJavaScriptMessage(
1205 routing_id_, message, default_value, frame_url, type, &success, result));
initial.commit09911bf2008-07-26 23:55:291206 return success;
1207}
1208
1209void RenderView::AddGURLSearchProvider(const GURL& osd_url, bool autodetected) {
1210 if (!osd_url.is_empty())
1211 Send(new ViewHostMsg_PageHasOSDD(routing_id_, page_id_, osd_url,
1212 autodetected));
1213}
1214
[email protected]0ebf3872008-11-07 21:35:031215void RenderView::QueryFormFieldAutofill(const std::wstring& field_name,
1216 const std::wstring& text,
1217 int64 node_id) {
1218 static int message_id_counter = 0;
1219 form_field_autofill_request_id_ = message_id_counter++;
1220 Send(new ViewHostMsg_QueryFormFieldAutofill(routing_id_,
1221 field_name, text,
1222 node_id,
1223 form_field_autofill_request_id_));
1224}
1225
[email protected]4d2b6fb2009-03-20 22:28:171226void RenderView::RemoveStoredAutofillEntry(const std::wstring& name,
1227 const std::wstring& value) {
1228 Send(new ViewHostMsg_RemoveAutofillEntry(routing_id_, name, value));
1229}
1230
[email protected]0ebf3872008-11-07 21:35:031231void RenderView::OnReceivedAutofillSuggestions(
1232 int64 node_id,
1233 int request_id,
[email protected]8d0f15c2008-11-11 01:01:091234 const std::vector<std::wstring>& suggestions,
[email protected]0ebf3872008-11-07 21:35:031235 int default_suggestion_index) {
1236 if (!webview() || request_id != form_field_autofill_request_id_)
1237 return;
1238
1239 webview()->AutofillSuggestionsForNode(node_id, suggestions,
1240 default_suggestion_index);
1241}
1242
[email protected]2c4410d2009-05-06 23:46:221243void RenderView::OnPopupNotificationVisibilityChanged(bool visible) {
[email protected]634a6f92008-12-01 21:39:311244 popup_notification_visible_ = visible;
1245}
1246
initial.commit09911bf2008-07-26 23:55:291247uint32 RenderView::GetCPBrowsingContext() {
1248 uint32 context = 0;
1249 Send(new ViewHostMsg_GetCPBrowsingContext(&context));
1250 return context;
1251}
1252
[email protected]b62d1a8c2009-01-13 23:54:571253void RenderView::RunFileChooser(bool multi_select,
[email protected]b949f1112009-04-12 20:03:081254 const string16& title,
1255 const FilePath& default_filename,
initial.commit09911bf2008-07-26 23:55:291256 WebFileChooserCallback* file_chooser) {
1257 if (file_chooser_.get()) {
1258 // TODO(brettw): bug 1235154: This should be a synchronous message to deal
1259 // with the fact that web pages can programatically trigger this. With the
1260 // asnychronous messages, we can get an additional call when one is pending,
1261 // which this test is for. For now, we just ignore the additional file
1262 // chooser request. WebKit doesn't do anything to expect the callback, so
1263 // we can just ignore calling it.
1264 delete file_chooser;
1265 return;
1266 }
1267 file_chooser_.reset(file_chooser);
[email protected]b62d1a8c2009-01-13 23:54:571268 Send(new ViewHostMsg_RunFileChooser(routing_id_, multi_select, title,
[email protected]b949f1112009-04-12 20:03:081269 default_filename));
initial.commit09911bf2008-07-26 23:55:291270}
1271
initial.commit09911bf2008-07-26 23:55:291272void RenderView::AddSearchProvider(const std::string& url) {
1273 AddGURLSearchProvider(GURL(url),
1274 false); // not autodetected
1275}
1276
[email protected]f103ab72009-09-02 17:10:591277void RenderView::OnMissingPluginStatus(
1278 WebPluginDelegateProxy* delegate,
1279 int status) {
[email protected]6c8afae52009-01-22 02:24:571280#if defined(OS_WIN)
[email protected]f103ab72009-09-02 17:10:591281 if (!first_default_plugin_) {
initial.commit09911bf2008-07-26 23:55:291282 // Show the InfoBar for the first available plugin.
1283 if (status == default_plugin::MISSING_PLUGIN_AVAILABLE) {
[email protected]f103ab72009-09-02 17:10:591284 first_default_plugin_ = delegate->AsWeakPtr();
initial.commit09911bf2008-07-26 23:55:291285 Send(new ViewHostMsg_MissingPluginStatus(routing_id_, status));
1286 }
1287 } else {
1288 // Closes the InfoBar if user clicks on the plugin (instead of the InfoBar)
1289 // to start the download/install.
1290 if (status == default_plugin::MISSING_PLUGIN_USER_STARTED_DOWNLOAD) {
1291 Send(new ViewHostMsg_MissingPluginStatus(routing_id_, status));
1292 }
1293 }
[email protected]6c8afae52009-01-22 02:24:571294#else
1295 // TODO(port): plugins current not supported
1296 NOTIMPLEMENTED();
1297#endif
initial.commit09911bf2008-07-26 23:55:291298}
1299
[email protected]48c9cf2d2009-09-16 16:47:521300// WebKit::WebViewClient ------------------------------------------------------
1301
1302WebView* RenderView::createView(WebFrame* creator) {
1303 // Check to make sure we aren't overloading on popups.
1304 if (shared_popup_counter_->data > kMaximumNumberOfUnacknowledgedPopups)
1305 return NULL;
1306
1307 // This window can't be closed from a window.close() call until we receive a
1308 // message from the Browser process explicitly allowing it.
1309 popup_notification_visible_ = true;
1310
1311 int32 routing_id = MSG_ROUTING_NONE;
1312 bool user_gesture = creator->isProcessingUserGesture();
1313
[email protected]48c9cf2d2009-09-16 16:47:521314 render_thread_->Send(
[email protected]12636df2009-09-28 22:32:211315 new ViewHostMsg_CreateWindow(routing_id_, user_gesture, &routing_id));
1316 if (routing_id == MSG_ROUTING_NONE)
[email protected]48c9cf2d2009-09-16 16:47:521317 return NULL;
[email protected]48c9cf2d2009-09-16 16:47:521318
[email protected]48c9cf2d2009-09-16 16:47:521319 RenderView* view = RenderView::Create(render_thread_,
[email protected]12636df2009-09-28 22:32:211320 NULL,
1321 routing_id_,
[email protected]48c9cf2d2009-09-16 16:47:521322 renderer_preferences_,
1323 webkit_preferences_,
[email protected]12636df2009-09-28 22:32:211324 shared_popup_counter_,
1325 routing_id);
[email protected]48c9cf2d2009-09-16 16:47:521326 view->opened_by_user_gesture_ = user_gesture;
1327
1328 // Record the security origin of the creator.
[email protected]91733b62009-09-18 06:21:091329 GURL creator_url(creator->securityOrigin().toString().utf8());
[email protected]48c9cf2d2009-09-16 16:47:521330 if (!creator_url.is_valid() || !creator_url.IsStandard())
1331 creator_url = GURL();
1332 view->creator_url_ = creator_url;
1333
1334 // Copy over the alternate error page URL so we can have alt error pages in
1335 // the new render view (we don't need the browser to send the URL back down).
1336 view->alternate_error_page_url_ = alternate_error_page_url_;
1337
1338 return view->webview();
1339}
1340
1341WebWidget* RenderView::createPopupMenu(bool activatable) {
1342 RenderWidget* widget = RenderWidget::Create(routing_id_,
1343 render_thread_,
1344 activatable);
1345 return widget->webwidget();
1346}
1347
1348WebWidget* RenderView::createPopupMenu(const WebPopupMenuInfo& info) {
1349 RenderWidget* widget = RenderWidget::Create(routing_id_,
1350 render_thread_,
1351 true);
1352 widget->ConfigureAsExternalPopupMenu(info);
1353 return widget->webwidget();
1354}
1355
1356void RenderView::didAddMessageToConsole(
1357 const WebConsoleMessage& message, const WebString& source_name,
1358 unsigned source_line) {
1359 Send(new ViewHostMsg_AddMessageToConsole(routing_id_,
1360 UTF16ToWideHack(message.text),
1361 static_cast<int32>(source_line),
1362 UTF16ToWideHack(source_name)));
1363}
1364
1365void RenderView::printPage(WebFrame* frame) {
[email protected]71a14262009-09-22 20:02:581366 DCHECK(frame);
1367 Print(frame, true);
[email protected]48c9cf2d2009-09-16 16:47:521368}
1369
1370void RenderView::didStartLoading() {
1371 if (is_loading_) {
1372 DLOG(WARNING) << "didStartLoading called while loading";
1373 return;
1374 }
1375
1376 is_loading_ = true;
1377 // Clear the pointer so that we can assign it only when there is an unknown
1378 // plugin on a page.
1379 first_default_plugin_.reset();
1380
1381 Send(new ViewHostMsg_DidStartLoading(routing_id_));
1382}
1383
1384void RenderView::didStopLoading() {
1385 if (!is_loading_) {
1386 DLOG(WARNING) << "DidStopLoading called while not loading";
1387 return;
1388 }
1389
1390 is_loading_ = false;
1391
1392 // NOTE: For now we're doing the safest thing, and sending out notification
1393 // when done loading. This currently isn't an issue as the favicon is only
1394 // displayed when done loading. Ideally we would send notification when
1395 // finished parsing the head, but webkit doesn't support that yet.
1396 // The feed discovery code would also benefit from access to the head.
[email protected]26aa0482009-09-30 16:55:271397 GURL favicon_url(webview()->mainFrame()->favIconURL());
[email protected]48c9cf2d2009-09-16 16:47:521398 if (!favicon_url.is_empty())
1399 Send(new ViewHostMsg_UpdateFavIconURL(routing_id_, page_id_, favicon_url));
1400
[email protected]26aa0482009-09-30 16:55:271401 AddGURLSearchProvider(webview()->mainFrame()->openSearchDescriptionURL(),
[email protected]48c9cf2d2009-09-16 16:47:521402 true); // autodetected
1403
1404 Send(new ViewHostMsg_DidStopLoading(routing_id_));
1405
1406 MessageLoop::current()->PostDelayedTask(FROM_HERE,
1407 method_factory_.NewRunnableMethod(&RenderView::CapturePageInfo, page_id_,
1408 false),
1409 kDelayForCaptureMs);
1410
1411 // The page is loaded. Try to process the file we need to upload if any.
1412 ProcessPendingUpload();
1413
1414 // Since the page is done loading, we are sure we don't need to try
1415 // again.
1416 ResetPendingUpload();
1417}
1418
[email protected]04fc9482009-09-18 22:13:031419bool RenderView::shouldBeginEditing(const WebRange& range) {
1420 return true;
1421}
1422
1423bool RenderView::shouldEndEditing(const WebRange& range) {
1424 return true;
1425}
1426
1427bool RenderView::shouldInsertNode(const WebNode& node, const WebRange& range,
1428 WebEditingAction action) {
1429 return true;
1430}
1431
1432bool RenderView::shouldInsertText(const WebString& text, const WebRange& range,
1433 WebEditingAction action) {
1434 return true;
1435}
1436
1437bool RenderView::shouldChangeSelectedRange(const WebRange& from_range,
1438 const WebRange& to_range,
1439 WebTextAffinity affinity,
1440 bool still_selecting) {
1441 return true;
1442}
1443
1444bool RenderView::shouldDeleteRange(const WebRange& range) {
1445 return true;
1446}
1447
1448bool RenderView::shouldApplyStyle(const WebString& style,
1449 const WebRange& range) {
1450 return true;
1451}
1452
1453bool RenderView::isSmartInsertDeleteEnabled() {
1454 return true;
1455}
1456
1457bool RenderView::isSelectTrailingWhitespaceEnabled() {
1458#if defined(OS_WIN)
1459 return true;
1460#else
1461 return false;
1462#endif
1463}
1464
1465void RenderView::setInputMethodEnabled(bool enabled) {
1466 // Save the updated IME status and mark the input focus has been updated.
1467 // The IME status is to be sent to a browser process next time when
1468 // the input caret is rendered.
1469 if (!ime_control_busy_) {
1470 ime_control_updated_ = true;
1471 ime_control_new_state_ = enabled;
1472 }
1473}
1474
1475void RenderView::didChangeSelection(bool is_empty_selection) {
1476#if defined(OS_LINUX)
1477 if (!handling_input_event_)
1478 return;
1479 // TODO(estade): investigate incremental updates to the selection so that we
1480 // don't send the entire selection over IPC every time.
1481 if (!is_empty_selection) {
1482 // Sometimes we get repeated didChangeSelection calls from webkit when
1483 // the selection hasn't actually changed. We don't want to report these
1484 // because it will cause us to continually claim the X clipboard.
1485 const std::string& this_selection =
[email protected]26aa0482009-09-30 16:55:271486 webview()->focusedFrame()->selectionAsText().utf8();
[email protected]04fc9482009-09-18 22:13:031487 if (this_selection == last_selection_)
1488 return;
1489
1490 Send(new ViewHostMsg_SelectionChanged(routing_id_,
1491 this_selection));
1492 last_selection_ = this_selection;
1493 } else {
1494 last_selection_.clear();
1495 }
1496#endif
1497}
1498
1499void RenderView::didExecuteCommand(const WebString& command_name) {
1500 const std::wstring& name = UTF16ToWideHack(command_name);
1501 if (StartsWith(name, L"Move", true) ||
1502 StartsWith(name, L"Insert", true) ||
1503 StartsWith(name, L"Delete", true))
1504 return;
1505 UserMetricsRecordAction(name);
1506}
1507
[email protected]b2528b72009-09-24 06:57:101508bool RenderView::handleCurrentKeyboardEvent() {
1509 if (edit_commands_.empty())
1510 return false;
1511
[email protected]26aa0482009-09-30 16:55:271512 WebFrame* frame = webview()->focusedFrame();
[email protected]b2528b72009-09-24 06:57:101513 if (!frame)
1514 return false;
1515
1516 EditCommands::iterator it = edit_commands_.begin();
1517 EditCommands::iterator end = edit_commands_.end();
1518
[email protected]507b33ea2009-09-29 03:56:511519 bool did_execute_command = false;
[email protected]b2528b72009-09-24 06:57:101520 for (; it != end; ++it) {
[email protected]e6e15012009-09-30 14:59:331521 // In gtk and cocoa, it's possible to bind multiple edit commands to one
1522 // key (but it's the exception). Once one edit command is not executed, it
1523 // seems safest to not execute the rest.
[email protected]b2528b72009-09-24 06:57:101524 if (!frame->executeCommand(WebString::fromUTF8(it->name),
1525 WebString::fromUTF8(it->value)))
1526 break;
[email protected]507b33ea2009-09-29 03:56:511527 did_execute_command = true;
[email protected]b2528b72009-09-24 06:57:101528 }
1529
[email protected]507b33ea2009-09-29 03:56:511530 return did_execute_command;
[email protected]b2528b72009-09-24 06:57:101531}
1532
[email protected]1dbafaf72009-09-23 19:43:561533void RenderView::spellCheck(
1534 const WebString& text, int& misspelled_offset, int& misspelled_length) {
1535 EnsureDocumentTag();
1536 Send(new ViewHostMsg_SpellCheck(
1537 routing_id_, UTF16ToWideHack(text), document_tag_,
1538 &misspelled_offset, &misspelled_length));
1539}
1540
1541WebString RenderView::autoCorrectWord(const WebKit::WebString& word) {
1542 std::wstring autocorrect_word;
1543 const CommandLine& command_line = *CommandLine::ForCurrentProcess();
[email protected]b86c8c12009-10-05 22:01:261544 if (command_line.HasSwitch(switches::kExperimentalSpellcheckerFeatures)) {
[email protected]1dbafaf72009-09-23 19:43:561545 EnsureDocumentTag();
1546 Send(new ViewHostMsg_GetAutoCorrectWord(
1547 routing_id_, UTF16ToWideHack(word), document_tag_, &autocorrect_word));
1548 }
1549 return WideToUTF16Hack(autocorrect_word);
1550}
1551
[email protected]c49085c72009-10-02 16:28:561552void RenderView::showSpellingUI(bool show) {
1553 Send(new ViewHostMsg_ShowSpellingPanel(routing_id_, show));
1554}
1555
[email protected]8922e1f2009-10-03 05:01:261556bool RenderView::isShowingSpellingUI() {
1557 return spelling_panel_visible_;
1558}
1559
[email protected]1dbafaf72009-09-23 19:43:561560void RenderView::updateSpellingUIWithMisspelledWord(const WebString& word) {
1561 Send(new ViewHostMsg_UpdateSpellingPanelWithMisspelledWord(
1562 routing_id_, UTF16ToWideHack(word)));
1563}
1564
[email protected]48c9cf2d2009-09-16 16:47:521565void RenderView::runModalAlertDialog(
1566 WebFrame* frame, const WebString& message) {
1567 RunJavaScriptMessage(MessageBoxFlags::kIsJavascriptAlert,
1568 UTF16ToWideHack(message),
1569 std::wstring(),
1570 frame->url(),
1571 NULL);
1572}
1573
1574bool RenderView::runModalConfirmDialog(
1575 WebFrame* frame, const WebString& message) {
1576 return RunJavaScriptMessage(MessageBoxFlags::kIsJavascriptConfirm,
1577 UTF16ToWideHack(message),
1578 std::wstring(),
1579 frame->url(),
1580 NULL);
1581}
1582
1583bool RenderView::runModalPromptDialog(
1584 WebFrame* frame, const WebString& message, const WebString& default_value,
1585 WebString* actual_value) {
1586 std::wstring result;
1587 bool ok = RunJavaScriptMessage(MessageBoxFlags::kIsJavascriptPrompt,
1588 UTF16ToWideHack(message),
1589 UTF16ToWideHack(default_value),
1590 frame->url(),
1591 &result);
1592 if (ok)
1593 actual_value->assign(WideToUTF16Hack(result));
1594 return ok;
1595}
1596
1597bool RenderView::runModalBeforeUnloadDialog(
1598 WebFrame* frame, const WebString& message) {
1599 bool success = false;
1600 // This is an ignored return value, but is included so we can accept the same
1601 // response as RunJavaScriptMessage.
1602 std::wstring ignored_result;
[email protected]12636df2009-09-28 22:32:211603 SendAndRunNestedMessageLoop(new ViewHostMsg_RunBeforeUnloadConfirm(
[email protected]48c9cf2d2009-09-16 16:47:521604 routing_id_, frame->url(), UTF16ToWideHack(message), &success,
[email protected]12636df2009-09-28 22:32:211605 &ignored_result));
[email protected]48c9cf2d2009-09-16 16:47:521606 return success;
1607}
1608
1609void RenderView::setStatusText(const WebString& text) {
1610}
1611
1612void RenderView::setMouseOverURL(const WebURL& url) {
[email protected]8d32b9832009-09-17 06:21:011613 GURL latest_url(url);
[email protected]48c9cf2d2009-09-16 16:47:521614 if (latest_url == target_url_)
1615 return;
1616 // Tell the browser to display a destination link.
1617 if (target_url_status_ == TARGET_INFLIGHT ||
1618 target_url_status_ == TARGET_PENDING) {
1619 // If we have a request in-flight, save the URL to be sent when we
1620 // receive an ACK to the in-flight request. We can happily overwrite
1621 // any existing pending sends.
1622 pending_target_url_ = latest_url;
1623 target_url_status_ = TARGET_PENDING;
1624 } else {
1625 Send(new ViewHostMsg_UpdateTargetURL(routing_id_, page_id_, latest_url));
1626 target_url_ = latest_url;
1627 target_url_status_ = TARGET_INFLIGHT;
1628 }
1629}
1630
1631void RenderView::setToolTipText(const WebString& text, WebTextDirection hint) {
1632 Send(new ViewHostMsg_SetTooltipText(routing_id_, UTF16ToWideHack(text),
1633 hint));
1634}
1635
1636void RenderView::startDragging(const WebPoint& from, const WebDragData& data,
1637 WebDragOperationsMask allowed_ops) {
1638 Send(new ViewHostMsg_StartDragging(routing_id_,
1639 WebDropData(data),
1640 allowed_ops));
1641}
1642
[email protected]28b92df2009-09-25 17:35:451643bool RenderView::acceptsLoadDrops() {
1644 return renderer_preferences_.can_accept_load_drops;
1645}
1646
[email protected]48c9cf2d2009-09-16 16:47:521647void RenderView::focusNext() {
1648 Send(new ViewHostMsg_TakeFocus(routing_id_, false));
1649}
1650
1651void RenderView::focusPrevious() {
1652 Send(new ViewHostMsg_TakeFocus(routing_id_, true));
1653}
1654
1655void RenderView::navigateBackForwardSoon(int offset) {
1656 history_back_list_count_ += offset;
1657 history_forward_list_count_ -= offset;
1658
1659 Send(new ViewHostMsg_GoToEntryAtOffset(routing_id_, offset));
1660}
1661
1662int RenderView::historyBackListCount() {
1663 return history_back_list_count_;
1664}
1665
1666int RenderView::historyForwardListCount() {
1667 return history_forward_list_count_;
1668}
1669
1670void RenderView::didAddHistoryItem() {
1671 // We don't want to update the history length for the start page
1672 // navigation.
[email protected]26aa0482009-09-30 16:55:271673 WebFrame* main_frame = webview()->mainFrame();
[email protected]48c9cf2d2009-09-16 16:47:521674 DCHECK(main_frame != NULL);
1675
1676 WebDataSource* ds = main_frame->dataSource();
1677 DCHECK(ds != NULL);
1678
1679 NavigationState* navigation_state = NavigationState::FromDataSource(ds);
1680 DCHECK(navigation_state);
1681 if (navigation_state->transition_type() == PageTransition::START_PAGE)
1682 return;
1683
1684 history_back_list_count_++;
1685 history_forward_list_count_ = 0;
1686}
1687
[email protected]8922e1f2009-10-03 05:01:261688void RenderView::didUpdateInspectorSettings() {
1689 Send(new ViewHostMsg_UpdateInspectorSettings(
1690 routing_id_, webview()->inspectorSettings().utf8()));
1691}
1692
[email protected]79dbc662009-09-04 05:42:511693// WebKit::WebWidgetClient ----------------------------------------------------
1694
initial.commit09911bf2008-07-26 23:55:291695// We are supposed to get a single call to Show for a newly created RenderView
1696// that was created via RenderView::CreateWebView. So, we wait until this
1697// point to dispatch the ShowView message.
1698//
1699// This method provides us with the information about how to display the newly
1700// created RenderView (i.e., as a constrained popup or as a new tab).
1701//
[email protected]4873c7d2009-07-16 06:36:281702void RenderView::show(WebNavigationPolicy policy) {
initial.commit09911bf2008-07-26 23:55:291703 DCHECK(!did_show_) << "received extraneous Show call";
1704 DCHECK(opener_id_ != MSG_ROUTING_NONE);
1705
1706 if (did_show_)
1707 return;
1708 did_show_ = true;
1709
1710 // NOTE: initial_pos_ may still have its default values at this point, but
1711 // that's okay. It'll be ignored if disposition is not NEW_POPUP, or the
1712 // browser process will impose a default position otherwise.
[email protected]4873c7d2009-07-16 06:36:281713 Send(new ViewHostMsg_ShowView(opener_id_, routing_id_,
1714 NavigationPolicyToDisposition(policy), initial_pos_,
1715 opened_by_user_gesture_, creator_url_));
[email protected]2533ce12009-05-09 00:02:241716 SetPendingWindowRect(initial_pos_);
initial.commit09911bf2008-07-26 23:55:291717}
1718
[email protected]4873c7d2009-07-16 06:36:281719void RenderView::closeWidgetSoon() {
[email protected]2c4410d2009-05-06 23:46:221720 if (!popup_notification_visible_)
[email protected]4873c7d2009-07-16 06:36:281721 RenderWidget::closeWidgetSoon();
[email protected]634a6f92008-12-01 21:39:311722}
1723
[email protected]4873c7d2009-07-16 06:36:281724void RenderView::runModal() {
initial.commit09911bf2008-07-26 23:55:291725 DCHECK(did_show_) << "should already have shown the view";
1726
[email protected]12636df2009-09-28 22:32:211727 SendAndRunNestedMessageLoop(new ViewHostMsg_RunModal(routing_id_));
initial.commit09911bf2008-07-26 23:55:291728}
1729
[email protected]3d9689372009-09-10 04:29:171730// WebKit::WebFrameClient -----------------------------------------------------
1731
1732WebPlugin* RenderView::createPlugin(
1733 WebFrame* frame, const WebPluginParams& params) {
1734 return new webkit_glue::WebPluginImpl(frame, params, AsWeakPtr());
1735}
1736
1737WebWorker* RenderView::createWorker(WebFrame* frame, WebWorkerClient* client) {
1738 return new WebWorkerProxy(client, RenderThread::current(), routing_id_);
1739}
1740
1741WebMediaPlayer* RenderView::createMediaPlayer(
1742 WebFrame* frame, WebMediaPlayerClient* client) {
1743 scoped_refptr<media::FilterFactoryCollection> factory =
1744 new media::FilterFactoryCollection();
1745 // Add in any custom filter factories first.
1746 const CommandLine* cmd_line = CommandLine::ForCurrentProcess();
1747 if (!cmd_line->HasSwitch(switches::kDisableAudio)) {
1748 // Add the chrome specific audio renderer.
1749 factory->AddFactory(
1750 AudioRendererImpl::CreateFactory(audio_message_filter()));
1751 }
1752
1753 // TODO(hclam): obtain the following parameters from |client|.
1754 webkit_glue::MediaResourceLoaderBridgeFactory* bridge_factory =
1755 new webkit_glue::MediaResourceLoaderBridgeFactory(
1756 GURL::EmptyGURL(), // referrer
1757 "null", // frame origin
1758 "null", // main_frame_origin
1759 base::GetCurrentProcId(),
1760 appcache::kNoHostId,
1761 routing_id());
1762
1763 if (!cmd_line->HasSwitch(switches::kSimpleDataSource)) {
1764 // Add the chrome specific media data source.
1765 factory->AddFactory(
1766 webkit_glue::BufferedDataSource::CreateFactory(MessageLoop::current(),
1767 bridge_factory));
1768 } else {
1769 factory->AddFactory(
1770 webkit_glue::SimpleDataSource::CreateFactory(MessageLoop::current(),
1771 bridge_factory));
1772 }
1773 return new webkit_glue::WebMediaPlayerImpl(client, factory);
1774}
1775
1776void RenderView::willClose(WebFrame* frame) {
1777 if (!frame->parent()) {
1778 const GURL& url = frame->url();
1779 if (url.SchemeIs("http") || url.SchemeIs("https"))
1780 DumpLoadHistograms();
1781 }
1782}
1783
1784void RenderView::loadURLExternally(
1785 WebFrame* frame, const WebURLRequest& request,
1786 WebNavigationPolicy policy) {
[email protected]efce17b2009-09-11 18:04:591787 GURL referrer(request.httpHeaderField(WebString::fromUTF8("Referer")));
1788 if (policy == WebKit::WebNavigationPolicyDownload) {
1789 Send(new ViewHostMsg_DownloadUrl(routing_id_, request.url(), referrer));
1790 } else {
1791 OpenURL(request.url(), referrer, policy);
1792 }
[email protected]3d9689372009-09-10 04:29:171793}
1794
1795WebNavigationPolicy RenderView::decidePolicyForNavigation(
1796 WebFrame* frame, const WebURLRequest& request, WebNavigationType type,
1797 WebNavigationPolicy default_policy, bool is_redirect) {
1798 // Webkit is asking whether to navigate to a new URL.
1799 // This is fine normally, except if we're showing UI from one security
1800 // context and they're trying to navigate to a different context.
1801 const GURL& url = request.url();
1802
1803 // If the browser is interested, then give it a chance to look at top level
1804 // navigations
1805 if (renderer_preferences_.browser_handles_top_level_requests &&
1806 // Only send once.
1807 last_top_level_navigation_page_id_ != page_id_ &&
1808 // Not interested in reloads.
1809 type != WebKit::WebNavigationTypeReload &&
1810 type != WebKit::WebNavigationTypeFormSubmitted &&
1811 // Must be a top level frame.
1812 frame->parent() == NULL) {
1813 // Skip if navigation is on the same page (using '#').
1814 GURL frame_origin = GURL(frame->url()).GetOrigin();
1815 if (url.GetOrigin() != frame_origin || url.ref().empty()) {
1816 last_top_level_navigation_page_id_ = page_id_;
1817 OpenURL(url, GURL(), default_policy);
1818 return WebKit::WebNavigationPolicyIgnore; // Suppress the load here.
1819 }
1820 }
1821
1822 // A content initiated navigation may have originated from a link-click,
1823 // script, drag-n-drop operation, etc.
1824 bool is_content_initiated =
1825 NavigationState::FromDataSource(frame->provisionalDataSource())->
1826 is_content_initiated();
1827
1828 // We only care about navigations that are within the current tab (as opposed
1829 // to, for example, opening a new window).
1830 // But we sometimes navigate to about:blank to clear a tab, and we want to
1831 // still allow that.
1832 if (default_policy == WebKit::WebNavigationPolicyCurrentTab &&
1833 is_content_initiated && frame->parent() == NULL &&
1834 !url.SchemeIs(chrome::kAboutScheme)) {
1835 // When we received such unsolicited navigations, we sometimes want to
1836 // punt them up to the browser to handle.
1837 if (BindingsPolicy::is_dom_ui_enabled(enabled_bindings_) ||
1838 BindingsPolicy::is_extension_enabled(enabled_bindings_) ||
1839 frame->isViewSourceModeEnabled() ||
1840 url.SchemeIs(chrome::kViewSourceScheme) ||
1841 url.SchemeIs(chrome::kPrintScheme)) {
1842 OpenURL(url, GURL(), default_policy);
1843 return WebKit::WebNavigationPolicyIgnore; // Suppress the load here.
1844 }
1845 }
1846
1847 // Detect when a page is "forking" a new tab that can be safely rendered in
1848 // its own process. This is done by sites like Gmail that try to open links
1849 // in new windows without script connections back to the original page. We
1850 // treat such cases as browser navigations (in which we will create a new
1851 // renderer for a cross-site navigation), rather than WebKit navigations.
1852 //
1853 // We use the following heuristic to decide whether to fork a new page in its
1854 // own process:
1855 // The parent page must open a new tab to about:blank, set the new tab's
1856 // window.opener to null, and then redirect the tab to a cross-site URL using
1857 // JavaScript.
1858 bool is_fork =
1859 // Must start from a tab showing about:blank, which is later redirected.
[email protected]e0d481582009-09-15 21:06:251860 GURL(frame->url()) == GURL(chrome::kAboutBlankURL) &&
[email protected]3d9689372009-09-10 04:29:171861 // Must be the first real navigation of the tab.
[email protected]48c9cf2d2009-09-16 16:47:521862 historyBackListCount() < 1 &&
1863 historyForwardListCount() < 1 &&
[email protected]3d9689372009-09-10 04:29:171864 // The parent page must have set the child's window.opener to null before
1865 // redirecting to the desired URL.
1866 frame->opener() == NULL &&
1867 // Must be a top-level frame.
1868 frame->parent() == NULL &&
1869 // Must not have issued the request from this page.
1870 is_content_initiated &&
1871 // Must be targeted at the current tab.
1872 default_policy == WebKit::WebNavigationPolicyCurrentTab &&
1873 // Must be a JavaScript navigation, which appears as "other".
1874 type == WebKit::WebNavigationTypeOther;
1875 if (is_fork) {
1876 // Open the URL via the browser, not via WebKit.
1877 OpenURL(url, GURL(), default_policy);
1878 return WebKit::WebNavigationPolicyIgnore;
1879 }
1880
1881 return default_policy;
1882}
1883
1884void RenderView::willSubmitForm(WebFrame* frame, const WebForm& form) {
1885 NavigationState* navigation_state =
1886 NavigationState::FromDataSource(frame->provisionalDataSource());
1887
1888 if (navigation_state->transition_type() == PageTransition::LINK)
1889 navigation_state->set_transition_type(PageTransition::FORM_SUBMIT);
1890
1891 // Save these to be processed when the ensuing navigation is committed.
1892 navigation_state->set_searchable_form_data(
1893 SearchableFormData::Create(form));
1894 navigation_state->set_password_form_data(
1895 PasswordFormDomManager::CreatePasswordForm(form));
1896
1897 if (form.isAutoCompleteEnabled()) {
1898 scoped_ptr<AutofillForm> autofill_form(AutofillForm::Create(form));
1899 if (autofill_form.get())
1900 Send(new ViewHostMsg_AutofillFormSubmitted(routing_id_, *autofill_form));
1901 }
1902}
1903
1904void RenderView::willPerformClientRedirect(
1905 WebFrame* frame, const WebURL& from, const WebURL& to, double interval,
1906 double fire_time) {
1907 // Ignore
1908}
1909
1910void RenderView::didCancelClientRedirect(WebFrame* frame) {
1911 // Ignore
1912}
1913
1914void RenderView::didCompleteClientRedirect(
1915 WebFrame* frame, const WebURL& from) {
1916 if (!frame->parent())
1917 completed_client_redirect_src_ = from;
1918}
1919
1920void RenderView::didCreateDataSource(WebFrame* frame, WebDataSource* ds) {
1921 // The rest of RenderView assumes that a WebDataSource will always have a
1922 // non-null NavigationState.
1923 if (pending_navigation_state_.get()) {
1924 ds->setExtraData(pending_navigation_state_.release());
1925 } else {
1926 ds->setExtraData(NavigationState::CreateContentInitiated());
1927 }
1928}
1929
1930void RenderView::didStartProvisionalLoad(WebFrame* frame) {
1931 WebDataSource* ds = frame->provisionalDataSource();
1932 NavigationState* navigation_state = NavigationState::FromDataSource(ds);
1933
1934 navigation_state->set_start_load_time(Time::Now());
1935
1936 // Update the request time if WebKit has better knowledge of it.
1937 if (navigation_state->request_time().is_null()) {
1938 double event_time = ds->triggeringEventTime();
1939 if (event_time != 0.0)
1940 navigation_state->set_request_time(Time::FromDoubleT(event_time));
1941 }
1942
1943 bool is_top_most = !frame->parent();
1944 if (is_top_most) {
1945 navigation_gesture_ = frame->isProcessingUserGesture() ?
1946 NavigationGestureUnknown : NavigationGestureAuto;
1947
1948 // Make sure redirect tracking state is clear for the new load.
1949 completed_client_redirect_src_ = GURL();
1950 } else if (frame->parent()->isLoading()) {
1951 // Take note of AUTO_SUBFRAME loads here, so that we can know how to
1952 // load an error page. See DidFailProvisionalLoadWithError.
1953 navigation_state->set_transition_type(PageTransition::AUTO_SUBFRAME);
1954 }
1955
1956 Send(new ViewHostMsg_DidStartProvisionalLoadForFrame(
1957 routing_id_, is_top_most, ds->request().url()));
1958}
1959
1960void RenderView::didReceiveServerRedirectForProvisionalLoad(WebFrame* frame) {
1961 if (frame->parent())
1962 return;
1963 // Received a redirect on the main frame.
1964 WebDataSource* data_source = frame->provisionalDataSource();
1965 if (!data_source) {
1966 // Should only be invoked when we have a data source.
1967 NOTREACHED();
1968 return;
1969 }
1970 std::vector<GURL> redirects;
1971 GetRedirectChain(data_source, &redirects);
1972 if (redirects.size() >= 2) {
1973 Send(new ViewHostMsg_DidRedirectProvisionalLoad(
1974 routing_id_, page_id_, redirects[redirects.size() - 2],
1975 redirects[redirects.size() - 1]));
1976 }
1977}
1978
1979void RenderView::didFailProvisionalLoad(
1980 WebFrame* frame, const WebURLError& error) {
1981 // Notify the browser that we failed a provisional load with an error.
1982 //
1983 // Note: It is important this notification occur before DidStopLoading so the
1984 // SSL manager can react to the provisional load failure before being
1985 // notified the load stopped.
1986 //
1987 WebDataSource* ds = frame->provisionalDataSource();
1988 DCHECK(ds);
1989
1990 const WebURLRequest& failed_request = ds->request();
1991
1992 bool show_repost_interstitial =
1993 (error.reason == net::ERR_CACHE_MISS &&
1994 EqualsASCII(failed_request.httpMethod(), "POST"));
1995 Send(new ViewHostMsg_DidFailProvisionalLoadWithError(
1996 routing_id_, !frame->parent(), error.reason, error.unreachableURL,
1997 show_repost_interstitial));
1998
1999 // Don't display an error page if this is simply a cancelled load. Aside
2000 // from being dumb, WebCore doesn't expect it and it will cause a crash.
2001 if (error.reason == net::ERR_ABORTED)
2002 return;
2003
2004 // Make sure we never show errors in view source mode.
2005 frame->enableViewSourceMode(false);
2006
2007 NavigationState* navigation_state = NavigationState::FromDataSource(ds);
2008
2009 // If this is a failed back/forward/reload navigation, then we need to do a
2010 // 'replace' load. This is necessary to avoid messing up session history.
2011 // Otherwise, we do a normal load, which simulates a 'go' navigation as far
2012 // as session history is concerned.
2013 //
2014 // AUTO_SUBFRAME loads should always be treated as loads that do not advance
2015 // the page id.
2016 //
2017 bool replace =
2018 navigation_state->pending_page_id() != -1 ||
2019 navigation_state->transition_type() == PageTransition::AUTO_SUBFRAME;
2020
2021 // If we failed on a browser initiated request, then make sure that our error
2022 // page load is regarded as the same browser initiated request.
2023 if (!navigation_state->is_content_initiated()) {
2024 pending_navigation_state_.reset(NavigationState::CreateBrowserInitiated(
2025 navigation_state->pending_page_id(),
2026 navigation_state->transition_type(),
2027 navigation_state->request_time()));
2028 }
2029
2030 // Provide the user with a more helpful error page?
2031 if (MaybeLoadAlternateErrorPage(frame, error, replace))
2032 return;
2033
2034 // Fallback to a local error page.
2035 LoadNavigationErrorPage(frame, failed_request, error, std::string(),
2036 replace);
2037}
2038
2039void RenderView::didReceiveDocumentData(
2040 WebFrame* frame, const char* data, size_t data_len,
2041 bool& prevent_default) {
2042 NavigationState* navigation_state =
2043 NavigationState::FromDataSource(frame->dataSource());
2044 if (!navigation_state->postpone_loading_data())
2045 return;
2046
2047 // We're going to call commitDocumentData ourselves...
2048 prevent_default = true;
2049
2050 // Continue buffering the response data for the original 404 page. If it
2051 // grows too large, then we'll just let it through.
2052 navigation_state->append_postponed_data(data, data_len);
2053 if (navigation_state->postponed_data().size() >= 512) {
2054 navigation_state->set_postpone_loading_data(false);
2055 frame->commitDocumentData(navigation_state->postponed_data().data(),
2056 navigation_state->postponed_data().size());
2057 navigation_state->clear_postponed_data();
2058 }
2059}
2060
2061void RenderView::didCommitProvisionalLoad(
2062 WebFrame* frame, bool is_new_navigation) {
2063 NavigationState* navigation_state =
2064 NavigationState::FromDataSource(frame->dataSource());
2065
2066 navigation_state->set_commit_load_time(Time::Now());
2067 if (is_new_navigation) {
2068 // When we perform a new navigation, we need to update the previous session
2069 // history entry with state for the page we are leaving.
2070 UpdateSessionHistory(frame);
2071
2072 // We bump our Page ID to correspond with the new session history entry.
2073 page_id_ = next_page_id_++;
2074
2075 MessageLoop::current()->PostDelayedTask(FROM_HERE,
2076 method_factory_.NewRunnableMethod(&RenderView::CapturePageInfo,
2077 page_id_, true),
2078 kDelayForForcedCaptureMs);
2079 } else {
2080 // Inspect the navigation_state on this frame to see if the navigation
2081 // corresponds to a session history navigation... Note: |frame| may or
2082 // may not be the toplevel frame, but for the case of capturing session
2083 // history, the first committed frame suffices. We keep track of whether
2084 // we've seen this commit before so that only capture session history once
2085 // per navigation.
2086 //
2087 // Note that we need to check if the page ID changed. In the case of a
2088 // reload, the page ID doesn't change, and UpdateSessionHistory gets the
2089 // previous URL and the current page ID, which would be wrong.
2090 if (navigation_state->pending_page_id() != -1 &&
2091 navigation_state->pending_page_id() != page_id_ &&
2092 !navigation_state->request_committed()) {
2093 // This is a successful session history navigation!
2094 UpdateSessionHistory(frame);
2095 page_id_ = navigation_state->pending_page_id();
2096 }
2097 }
2098
2099 // Remember that we've already processed this request, so we don't update
2100 // the session history again. We do this regardless of whether this is
2101 // a session history navigation, because if we attempted a session history
2102 // navigation without valid HistoryItem state, WebCore will think it is a
2103 // new navigation.
2104 navigation_state->set_request_committed(true);
2105
2106 UpdateURL(frame);
2107
2108 // If this committed load was initiated by a client redirect, we're
2109 // at the last stop now, so clear it.
2110 completed_client_redirect_src_ = GURL();
2111
2112 // Check whether we have new encoding name.
[email protected]26aa0482009-09-30 16:55:272113 UpdateEncoding(frame, frame->view()->pageEncoding().utf8());
[email protected]3d9689372009-09-10 04:29:172114}
2115
2116void RenderView::didClearWindowObject(WebFrame* frame) {
2117 if (BindingsPolicy::is_dom_automation_enabled(enabled_bindings_))
2118 BindDOMAutomationController(frame);
2119 if (BindingsPolicy::is_dom_ui_enabled(enabled_bindings_)) {
2120 dom_ui_bindings_.set_message_sender(this);
2121 dom_ui_bindings_.set_routing_id(routing_id_);
2122 dom_ui_bindings_.BindToJavascript(frame, L"chrome");
2123 }
2124 if (BindingsPolicy::is_external_host_enabled(enabled_bindings_)) {
2125 external_host_bindings_.set_message_sender(this);
2126 external_host_bindings_.set_routing_id(routing_id_);
2127 external_host_bindings_.BindToJavascript(frame, L"externalHost");
2128 }
2129}
2130
2131void RenderView::didCreateDocumentElement(WebFrame* frame) {
2132 if (RenderThread::current()) { // Will be NULL during unit tests.
2133 RenderThread::current()->user_script_slave()->InjectScripts(
2134 frame, UserScript::DOCUMENT_START);
2135 }
[email protected]078b34612009-09-19 19:31:512136 if (view_type_ == ViewType::EXTENSION_TOOLSTRIP ||
2137 view_type_ == ViewType::EXTENSION_MOLE) {
2138 InjectToolstripCSS();
2139 ExtensionProcessBindings::SetViewType(webview(), view_type_);
2140 }
[email protected]3d9689372009-09-10 04:29:172141
[email protected]912256b32009-09-18 09:47:352142 while (!pending_code_execution_queue_.empty()) {
2143 scoped_refptr<CodeExecutionInfo> info =
2144 pending_code_execution_queue_.front();
2145 OnExecuteCode(info->request_id, info->extension_id, info->is_js_code,
2146 info->code_string);
2147 pending_code_execution_queue_.pop();
2148 }
2149
[email protected]3d9689372009-09-10 04:29:172150 // Notify the browser about non-blank documents loading in the top frame.
2151 GURL url = frame->url();
[email protected]e0d481582009-09-15 21:06:252152 if (url.is_valid() && url.spec() != chrome::kAboutBlankURL) {
[email protected]26aa0482009-09-30 16:55:272153 if (frame == webview()->mainFrame())
[email protected]3d9689372009-09-10 04:29:172154 Send(new ViewHostMsg_DocumentAvailableInMainFrame(routing_id_));
2155 }
2156}
2157
2158void RenderView::didReceiveTitle(WebFrame* frame, const WebString& title) {
2159 UpdateTitle(frame, title);
2160
2161 // Also check whether we have new encoding name.
[email protected]26aa0482009-09-30 16:55:272162 UpdateEncoding(frame, frame->view()->pageEncoding().utf8());
[email protected]3d9689372009-09-10 04:29:172163}
2164
2165void RenderView::didFinishDocumentLoad(WebFrame* frame) {
2166 WebDataSource* ds = frame->dataSource();
2167 NavigationState* navigation_state = NavigationState::FromDataSource(ds);
2168 DCHECK(navigation_state);
2169 navigation_state->set_finish_document_load_time(Time::Now());
2170
2171 Send(new ViewHostMsg_DocumentLoadedInFrame(routing_id_));
2172
2173 // The document has now been fully loaded. Scan for password forms to be
2174 // sent up to the browser.
2175 SendPasswordForms(frame);
2176
2177 // Check whether we have new encoding name.
[email protected]26aa0482009-09-30 16:55:272178 UpdateEncoding(frame, frame->view()->pageEncoding().utf8());
[email protected]3d9689372009-09-10 04:29:172179
2180 if (RenderThread::current()) { // Will be NULL during unit tests.
2181 RenderThread::current()->user_script_slave()->InjectScripts(
2182 frame, UserScript::DOCUMENT_END);
2183 }
2184}
2185
2186void RenderView::didHandleOnloadEvents(WebFrame* frame) {
2187 // Ignore
2188}
2189
2190void RenderView::didFailLoad(WebFrame* frame, const WebURLError& error) {
2191 // Ignore
2192}
2193
2194void RenderView::didFinishLoad(WebFrame* frame) {
2195 WebDataSource* ds = frame->dataSource();
2196 NavigationState* navigation_state = NavigationState::FromDataSource(ds);
2197 DCHECK(navigation_state);
2198 navigation_state->set_finish_load_time(Time::Now());
2199}
2200
2201void RenderView::didChangeLocationWithinPage(
2202 WebFrame* frame, bool is_new_navigation) {
2203 // If this was a reference fragment navigation that we initiated, then we
2204 // could end up having a non-null pending navigation state. We just need to
2205 // update the ExtraData on the datasource so that others who read the
2206 // ExtraData will get the new NavigationState. Similarly, if we did not
2207 // initiate this navigation, then we need to take care to reset any pre-
2208 // existing navigation state to a content-initiated navigation state.
2209 // DidCreateDataSource conveniently takes care of this for us.
2210 didCreateDataSource(frame, frame->dataSource());
2211
2212 didCommitProvisionalLoad(frame, is_new_navigation);
2213
[email protected]26aa0482009-09-30 16:55:272214 UpdateTitle(frame, frame->view()->mainFrame()->dataSource()->pageTitle());
[email protected]3d9689372009-09-10 04:29:172215}
2216
[email protected]476b6f82009-09-10 21:00:592217void RenderView::didUpdateCurrentHistoryItem(WebFrame* frame) {
2218 if (!nav_state_sync_timer_.IsRunning()) {
2219 nav_state_sync_timer_.Start(
2220 TimeDelta::FromSeconds(delay_seconds_for_form_state_sync_), this,
2221 &RenderView::SyncNavigationState);
2222 }
2223}
2224
[email protected]3d9689372009-09-10 04:29:172225void RenderView::assignIdentifierToRequest(
2226 WebFrame* frame, unsigned identifier, const WebURLRequest& request) {
2227 // Ignore
2228}
2229
2230void RenderView::willSendRequest(
2231 WebFrame* frame, unsigned identifier, WebURLRequest& request,
2232 const WebURLResponse& redirect_response) {
2233 request.setRequestorID(routing_id_);
2234}
2235
2236void RenderView::didReceiveResponse(
2237 WebFrame* frame, unsigned identifier, const WebURLResponse& response) {
2238 // Consider loading an alternate error page for 404 responses.
2239 if (response.httpStatusCode() != 404)
2240 return;
2241
2242 // Only do this for responses that correspond to a provisional data source
2243 // of the top-most frame. If we have a provisional data source, then we
2244 // can't have any sub-resources yet, so we know that this response must
2245 // correspond to a frame load.
2246 if (!frame->provisionalDataSource() || frame->parent())
2247 return;
2248
2249 // If we are in view source mode, then just let the user see the source of
2250 // the server's 404 error page.
2251 if (frame->isViewSourceModeEnabled())
2252 return;
2253
2254 // Can we even load an alternate error page for this URL?
2255 if (!GetAlternateErrorPageURL(response.url(), HTTP_404).is_valid())
2256 return;
2257
2258 NavigationState* navigation_state =
2259 NavigationState::FromDataSource(frame->provisionalDataSource());
2260 navigation_state->set_postpone_loading_data(true);
2261 navigation_state->clear_postponed_data();
2262}
2263
2264void RenderView::didFinishResourceLoad(
2265 WebFrame* frame, unsigned identifier) {
2266 NavigationState* navigation_state =
2267 NavigationState::FromDataSource(frame->dataSource());
2268 if (!navigation_state->postpone_loading_data())
2269 return;
2270
2271 // The server returned a 404 and the content was < 512 bytes (which we
2272 // suppressed). Go ahead and fetch the alternate page content.
2273
2274 const GURL& frame_url = frame->url();
2275
2276 const GURL& error_page_url = GetAlternateErrorPageURL(frame_url, HTTP_404);
2277 DCHECK(error_page_url.is_valid());
2278
2279 WebURLError original_error;
2280 original_error.unreachableURL = frame_url;
2281
2282 navigation_state->set_alt_error_page_fetcher(
2283 new AltErrorPageResourceFetcher(
2284 error_page_url, frame, original_error,
2285 NewCallback(this, &RenderView::AltErrorPageFinished)));
2286}
2287
2288void RenderView::didFailResourceLoad(
2289 WebFrame* frame, unsigned identifier, const WebURLError& error) {
2290 // Ignore
2291}
2292
2293void RenderView::didLoadResourceFromMemoryCache(
2294 WebFrame* frame, const WebURLRequest& request,
2295 const WebURLResponse& response) {
2296 // Let the browser know we loaded a resource from the memory cache. This
2297 // message is needed to display the correct SSL indicators.
2298 Send(new ViewHostMsg_DidLoadResourceFromMemoryCache(
2299 routing_id_,
2300 request.url(),
[email protected]91733b62009-09-18 06:21:092301 frame->securityOrigin().toString().utf8(),
2302 frame->top()->securityOrigin().toString().utf8(),
[email protected]3d9689372009-09-10 04:29:172303 response.securityInfo()));
2304}
2305
[email protected]e3d60e5d2009-09-25 21:08:292306void RenderView::didDisplayInsecureContent(WebKit::WebFrame* frame) {
2307 Send(new ViewHostMsg_DidDisplayInsecureContent(routing_id_));
2308}
2309
2310void RenderView::didRunInsecureContent(
2311 WebFrame* frame, const WebSecurityOrigin& origin) {
2312 Send(new ViewHostMsg_DidRunInsecureContent(
2313 routing_id_,
2314 origin.toString().utf8()));
2315}
2316
[email protected]3d9689372009-09-10 04:29:172317void RenderView::didExhaustMemoryAvailableForScript(WebFrame* frame) {
2318 Send(new ViewHostMsg_JSOutOfMemory(routing_id_));
2319}
2320
2321void RenderView::didChangeContentsSize(WebFrame* frame, const WebSize& size) {
2322 // We don't always want to send the change messages over IPC, only if we've
2323 // be put in that mode by getting a |ViewMsg_EnableIntrinsicWidthChangedMode|
2324 // message.
[email protected]f87eee052009-09-10 21:39:092325 if (send_preferred_width_changes_) {
[email protected]3d9689372009-09-10 04:29:172326 // WebCore likes to tell us things have changed even when they haven't, so
2327 // cache the width and only send the IPC message when we're sure the
2328 // width is different.
[email protected]26aa0482009-09-30 16:55:272329 int width = webview()->mainFrame()->contentsPreferredWidth();
[email protected]3d9689372009-09-10 04:29:172330 if (width != preferred_width_) {
2331 Send(new ViewHostMsg_DidContentsPreferredWidthChange(routing_id_, width));
2332 preferred_width_ = width;
2333 }
2334 }
2335}
2336
[email protected]8922e1f2009-10-03 05:01:262337void RenderView::reportFindInPageMatchCount(int request_id, int count,
2338 bool final_update) {
2339 // If we have a message that has been queued up, then we should just replace
2340 // it. The ACK from the browser will make sure it gets sent when the browser
2341 // wants it.
2342 if (queued_find_reply_message_.get()) {
2343 IPC::Message* msg = new ViewHostMsg_Find_Reply(
2344 routing_id_,
2345 request_id,
2346 count,
2347 gfx::Rect(),
2348 -1, // Don't update active match ordinal.
2349 final_update);
2350 queued_find_reply_message_.reset(msg);
2351 } else {
2352 // Send the search result over to the browser process.
2353 Send(new ViewHostMsg_Find_Reply(
2354 routing_id_,
2355 request_id,
2356 count,
2357 gfx::Rect(),
2358 -1, // // Don't update active match ordinal.
2359 final_update));
2360 }
2361}
2362
2363void RenderView::reportFindInPageSelection(int request_id,
2364 int active_match_ordinal,
2365 const WebRect& selection_rect) {
2366 // Send the search result over to the browser process.
2367 Send(new ViewHostMsg_Find_Reply(routing_id_,
2368 request_id,
2369 -1,
2370 selection_rect,
2371 active_match_ordinal,
2372 false));
2373}
2374
[email protected]79dbc662009-09-04 05:42:512375// webkit_glue::WebPluginPageDelegate -----------------------------------------
2376
[email protected]f103ab72009-09-02 17:10:592377webkit_glue::WebPluginDelegate* RenderView::CreatePluginDelegate(
2378 const GURL& url,
2379 const std::string& mime_type,
[email protected]f103ab72009-09-02 17:10:592380 std::string* actual_mime_type) {
2381 if (!PluginChannelHost::IsListening())
2382 return NULL;
2383
2384 GURL policy_url;
[email protected]26aa0482009-09-30 16:55:272385 WebFrame* main_frame = webview()->mainFrame();
[email protected]f103ab72009-09-02 17:10:592386 if (main_frame)
2387 policy_url = main_frame->url();
2388
2389 FilePath path;
[email protected]610c0892009-09-08 19:46:182390 render_thread_->Send(new ViewHostMsg_GetPluginPath(
2391 url, policy_url, mime_type, &path, actual_mime_type));
[email protected]f103ab72009-09-02 17:10:592392 if (path.value().empty())
2393 return NULL;
2394
2395 const std::string* mime_type_to_use;
2396 if (!actual_mime_type->empty())
2397 mime_type_to_use = actual_mime_type;
2398 else
2399 mime_type_to_use = &mime_type;
2400
[email protected]d032f492009-09-29 00:33:462401 bool in_process_plugin = RenderProcess::current()->in_process_plugins();
2402 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kInternalNaCl)) {
2403 if (mime_type == "application/x-nacl-srpc") {
2404 in_process_plugin = true;
2405 }
2406 }
2407 if (in_process_plugin) {
[email protected]f103ab72009-09-02 17:10:592408#if defined(OS_WIN) // In-proc plugins aren't supported on Linux or Mac.
[email protected]8a3b7962009-09-04 05:53:232409 return WebPluginDelegateImpl::Create(
[email protected]f103ab72009-09-02 17:10:592410 path, *mime_type_to_use, gfx::NativeViewFromId(host_window_));
2411#else
2412 NOTIMPLEMENTED();
2413 return NULL;
2414#endif
2415 }
2416
[email protected]610c0892009-09-08 19:46:182417 return new WebPluginDelegateProxy(*mime_type_to_use, AsWeakPtr());
[email protected]f103ab72009-09-02 17:10:592418}
2419
2420void RenderView::CreatedPluginWindow(gfx::PluginWindowHandle window) {
2421#if defined(OS_LINUX)
2422 RenderThread::current()->Send(new ViewHostMsg_CreatePluginContainer(
2423 routing_id(), window));
2424#endif
2425}
2426
2427void RenderView::WillDestroyPluginWindow(gfx::PluginWindowHandle window) {
2428#if defined(OS_LINUX)
2429 RenderThread::current()->Send(new ViewHostMsg_DestroyPluginContainer(
2430 routing_id(), window));
2431#endif
2432 CleanupWindowInPluginMoves(window);
2433}
2434
2435void RenderView::DidMovePlugin(const webkit_glue::WebPluginGeometry& move) {
2436 SchedulePluginMove(move);
2437}
2438
2439void RenderView::DidStartLoadingForPlugin() {
2440 // TODO(darin): Make is_loading_ be a counter!
[email protected]48c9cf2d2009-09-16 16:47:522441 didStartLoading();
[email protected]f103ab72009-09-02 17:10:592442}
2443
2444void RenderView::DidStopLoadingForPlugin() {
2445 // TODO(darin): Make is_loading_ be a counter!
[email protected]48c9cf2d2009-09-16 16:47:522446 didStopLoading();
[email protected]f103ab72009-09-02 17:10:592447}
2448
2449void RenderView::ShowModalHTMLDialogForPlugin(
2450 const GURL& url,
2451 const gfx::Size& size,
2452 const std::string& json_arguments,
2453 std::string* json_retval) {
[email protected]12636df2009-09-28 22:32:212454 SendAndRunNestedMessageLoop(new ViewHostMsg_ShowModalHTMLDialog(
[email protected]f103ab72009-09-02 17:10:592455 routing_id_, url, size.width(), size.height(), json_arguments,
[email protected]12636df2009-09-28 22:32:212456 json_retval));
[email protected]f103ab72009-09-02 17:10:592457}
2458
initial.commit09911bf2008-07-26 23:55:292459void RenderView::SyncNavigationState() {
2460 if (!webview())
2461 return;
2462
[email protected]26aa0482009-09-30 16:55:272463 const WebHistoryItem& item = webview()->mainFrame()->currentHistoryItem();
[email protected]ca948a22009-06-25 19:36:172464 if (item.isNull())
initial.commit09911bf2008-07-26 23:55:292465 return;
[email protected]ca948a22009-06-25 19:36:172466
2467 Send(new ViewHostMsg_UpdateState(
2468 routing_id_, page_id_, webkit_glue::HistoryItemToString(item)));
initial.commit09911bf2008-07-26 23:55:292469}
2470
2471void RenderView::ShowContextMenu(WebView* webview,
[email protected]581b87eb2009-07-23 23:06:562472 ContextNodeType node_type,
initial.commit09911bf2008-07-26 23:55:292473 int x,
2474 int y,
2475 const GURL& link_url,
[email protected]574a1d62009-07-17 03:23:462476 const GURL& src_url,
initial.commit09911bf2008-07-26 23:55:292477 const GURL& page_url,
2478 const GURL& frame_url,
[email protected]574a1d62009-07-17 03:23:462479 const ContextMenuMediaParams& media_params,
initial.commit09911bf2008-07-26 23:55:292480 const std::wstring& selection_text,
2481 const std::wstring& misspelled_word,
[email protected]6aa376b2008-09-23 18:49:522482 int edit_flags,
[email protected]c9825a42009-05-01 22:51:502483 const std::string& security_info,
2484 const std::string& frame_charset) {
[email protected]e09ba552009-02-05 03:26:292485 ContextMenuParams params;
[email protected]581b87eb2009-07-23 23:06:562486 params.node_type = node_type;
initial.commit09911bf2008-07-26 23:55:292487 params.x = x;
2488 params.y = y;
[email protected]574a1d62009-07-17 03:23:462489 params.src_url = src_url;
initial.commit09911bf2008-07-26 23:55:292490 params.link_url = link_url;
[email protected]e6c79812009-04-22 22:31:422491 params.unfiltered_link_url = link_url;
initial.commit09911bf2008-07-26 23:55:292492 params.page_url = page_url;
2493 params.frame_url = frame_url;
[email protected]574a1d62009-07-17 03:23:462494 params.media_params = media_params;
initial.commit09911bf2008-07-26 23:55:292495 params.selection_text = selection_text;
2496 params.misspelled_word = misspelled_word;
[email protected]be645db2009-02-06 20:36:332497 params.spellcheck_enabled =
[email protected]26aa0482009-09-30 16:55:272498 webview->focusedFrame()->isContinuousSpellCheckingEnabled();
initial.commit09911bf2008-07-26 23:55:292499 params.edit_flags = edit_flags;
[email protected]6aa376b2008-09-23 18:49:522500 params.security_info = security_info;
[email protected]c9825a42009-05-01 22:51:502501 params.frame_charset = frame_charset;
initial.commit09911bf2008-07-26 23:55:292502 Send(new ViewHostMsg_ContextMenu(routing_id_, params));
2503}
2504
[email protected]b0950a72009-09-29 23:16:172505bool RenderView::DownloadImage(int id, const GURL& image_url, int image_size) {
2506 // Make sure webview was not shut down.
2507 if (!webview())
2508 return false;
2509 // Create an image resource fetcher and assign it with a call back object.
2510 image_fetchers_.insert(new ImageResourceFetcher(
[email protected]26aa0482009-09-30 16:55:272511 image_url, webview()->mainFrame(), id, image_size,
[email protected]b0950a72009-09-29 23:16:172512 NewCallback(this, &RenderView::DidDownloadImage)));
2513 return true;
2514}
2515
2516void RenderView::DidDownloadImage(ImageResourceFetcher* fetcher,
initial.commit09911bf2008-07-26 23:55:292517 const SkBitmap& image) {
[email protected]b0950a72009-09-29 23:16:172518 // Notify requester of image download status.
2519 Send(new ViewHostMsg_DidDownloadFavIcon(routing_id_,
2520 fetcher->id(),
2521 fetcher->image_url(),
2522 image.isNull(),
2523 image));
2524 // Dispose of the image fetcher.
2525 DCHECK(image_fetchers_.find(fetcher) != image_fetchers_.end());
2526 image_fetchers_.erase(fetcher);
2527 // We're in the callback from the ImageResourceFetcher, best to delay
2528 // deletion.
2529 MessageLoop::current()->DeleteSoon(FROM_HERE, fetcher);
initial.commit09911bf2008-07-26 23:55:292530}
2531
[email protected]bf5c2ff392009-07-08 16:24:332532void RenderView::OnDownloadFavIcon(int id,
2533 const GURL& image_url,
2534 int image_size) {
[email protected]f11ca0732009-04-11 00:09:342535 bool data_image_failed = false;
2536 if (image_url.SchemeIs("data")) {
2537 SkBitmap data_image = ImageFromDataUrl(image_url);
2538 data_image_failed = data_image.empty();
2539 if (!data_image_failed) {
[email protected]bf5c2ff392009-07-08 16:24:332540 Send(new ViewHostMsg_DidDownloadFavIcon(routing_id_, id, image_url, false,
2541 data_image));
[email protected]f11ca0732009-04-11 00:09:342542 }
2543 }
2544
[email protected]bf5c2ff392009-07-08 16:24:332545 if (data_image_failed ||
[email protected]b0950a72009-09-29 23:16:172546 !DownloadImage(id, image_url, image_size)) {
[email protected]bf5c2ff392009-07-08 16:24:332547 Send(new ViewHostMsg_DidDownloadFavIcon(routing_id_, id, image_url, true,
2548 SkBitmap()));
2549 }
initial.commit09911bf2008-07-26 23:55:292550}
2551
[email protected]f11ca0732009-04-11 00:09:342552SkBitmap RenderView::ImageFromDataUrl(const GURL& url) const {
2553 std::string mime_type, char_set, data;
2554 if (net::DataURL::Parse(url, &mime_type, &char_set, &data) && !data.empty()) {
2555 // Decode the favicon using WebKit's image decoder.
2556 webkit_glue::ImageDecoder decoder(gfx::Size(kFavIconSize, kFavIconSize));
2557 const unsigned char* src_data =
2558 reinterpret_cast<const unsigned char*>(&data[0]);
2559
2560 return decoder.Decode(src_data, data.size());
2561 }
2562 return SkBitmap();
2563}
2564
initial.commit09911bf2008-07-26 23:55:292565void RenderView::OnGetApplicationInfo(int page_id) {
2566 webkit_glue::WebApplicationInfo app_info;
2567 if (page_id == page_id_)
2568 webkit_glue::GetApplicationInfo(webview(), &app_info);
2569
2570 // Prune out any data URLs in the set of icons. The browser process expects
2571 // any icon with a data URL to have originated from a favicon. We don't want
2572 // to decode arbitrary data URLs in the browser process. See
2573 // http://b/issue?id=1162972
2574 for (size_t i = 0; i < app_info.icons.size(); ++i) {
[email protected]6de74452009-02-25 18:04:592575 if (app_info.icons[i].url.SchemeIs(chrome::kDataScheme)) {
initial.commit09911bf2008-07-26 23:55:292576 app_info.icons.erase(app_info.icons.begin() + i);
2577 --i;
2578 }
2579 }
2580
2581 Send(new ViewHostMsg_DidGetApplicationInfo(routing_id_, page_id, app_info));
2582}
2583
[email protected]7ccddb8c2009-08-04 17:36:552584GURL RenderView::GetAlternateErrorPageURL(const GURL& failed_url,
initial.commit09911bf2008-07-26 23:55:292585 ErrorPageType error_type) {
[email protected]7ccddb8c2009-08-04 17:36:552586 if (failed_url.SchemeIsSecure()) {
initial.commit09911bf2008-07-26 23:55:292587 // If the URL that failed was secure, then the embedding web page was not
2588 // expecting a network attacker to be able to manipulate its contents. As
2589 // we fetch alternate error pages over HTTP, we would be allowing a network
2590 // attacker to manipulate the contents of the response if we tried to use
2591 // the link doctor here.
2592 return GURL::EmptyGURL();
2593 }
2594
2595 // Grab the base URL from the browser process.
2596 if (!alternate_error_page_url_.is_valid())
2597 return GURL::EmptyGURL();
2598
2599 // Strip query params from the failed URL.
2600 GURL::Replacements remove_params;
2601 remove_params.ClearUsername();
2602 remove_params.ClearPassword();
2603 remove_params.ClearQuery();
2604 remove_params.ClearRef();
[email protected]7ccddb8c2009-08-04 17:36:552605 const GURL url_to_send = failed_url.ReplaceComponents(remove_params);
initial.commit09911bf2008-07-26 23:55:292606
2607 // Construct the query params to send to link doctor.
2608 std::string params(alternate_error_page_url_.query());
2609 params.append("&url=");
2610 params.append(EscapeQueryParamValue(url_to_send.spec()));
2611 params.append("&sourceid=chrome");
2612 params.append("&error=");
2613 switch (error_type) {
2614 case DNS_ERROR:
2615 params.append("dnserror");
2616 break;
2617
2618 case HTTP_404:
2619 params.append("http404");
2620 break;
2621
[email protected]5df266ac2008-10-15 19:50:132622 case CONNECTION_ERROR:
[email protected]e1f934b2009-01-26 20:41:332623 params.append("connectionfailure");
[email protected]5df266ac2008-10-15 19:50:132624 break;
2625
initial.commit09911bf2008-07-26 23:55:292626 default:
2627 NOTREACHED() << "unknown ErrorPageType";
2628 }
2629
2630 // OK, build the final url to return.
2631 GURL::Replacements link_doctor_params;
2632 link_doctor_params.SetQueryStr(params);
2633 GURL url = alternate_error_page_url_.ReplaceComponents(link_doctor_params);
2634 return url;
2635}
2636
[email protected]7ea066a2009-04-06 20:21:592637void RenderView::OnFind(int request_id,
2638 const string16& search_text,
2639 const WebKit::WebFindOptions& options) {
[email protected]26aa0482009-09-30 16:55:272640 WebFrame* main_frame = webview()->mainFrame();
[email protected]b4bb2502009-10-01 22:35:272641 WebFrame* frame_after_main = main_frame->traverseNext(true);
[email protected]26aa0482009-09-30 16:55:272642 WebFrame* focused_frame = webview()->focusedFrame();
initial.commit09911bf2008-07-26 23:55:292643 WebFrame* search_frame = focused_frame; // start searching focused frame.
2644
2645 bool multi_frame = (frame_after_main != main_frame);
2646
2647 // If we have multiple frames, we don't want to wrap the search within the
2648 // frame, so we check here if we only have main_frame in the chain.
2649 bool wrap_within_frame = !multi_frame;
2650
[email protected]b3f2b912009-04-09 16:18:522651 WebRect selection_rect;
initial.commit09911bf2008-07-26 23:55:292652 bool result = false;
2653
2654 do {
[email protected]dd7daa82009-08-10 05:46:452655 result = search_frame->find(
[email protected]7ea066a2009-04-06 20:21:592656 request_id, search_text, options, wrap_within_frame, &selection_rect);
initial.commit09911bf2008-07-26 23:55:292657
2658 if (!result) {
2659 // don't leave text selected as you move to the next frame.
[email protected]a100d76bb2009-08-14 17:50:222660 search_frame->executeCommand(WebString::fromUTF8("Unselect"));
initial.commit09911bf2008-07-26 23:55:292661
2662 // Find the next frame, but skip the invisible ones.
2663 do {
2664 // What is the next frame to search? (we might be going backwards). Note
2665 // that we specify wrap=true so that search_frame never becomes NULL.
[email protected]7ea066a2009-04-06 20:21:592666 search_frame = options.forward ?
[email protected]b4bb2502009-10-01 22:35:272667 search_frame->traverseNext(true) :
2668 search_frame->traversePrevious(true);
[email protected]dd7daa82009-08-10 05:46:452669 } while (!search_frame->hasVisibleContent() &&
2670 search_frame != focused_frame);
initial.commit09911bf2008-07-26 23:55:292671
[email protected]884db412008-11-24 23:46:502672 // Make sure selection doesn't affect the search operation in new frame.
[email protected]a100d76bb2009-08-14 17:50:222673 search_frame->executeCommand(WebString::fromUTF8("Unselect"));
initial.commit09911bf2008-07-26 23:55:292674
2675 // If we have multiple frames and we have wrapped back around to the
2676 // focused frame, we need to search it once more allowing wrap within
2677 // the frame, otherwise it will report 'no match' if the focused frame has
2678 // reported matches, but no frames after the focused_frame contain a
2679 // match for the search word(s).
2680 if (multi_frame && search_frame == focused_frame) {
[email protected]dd7daa82009-08-10 05:46:452681 result = search_frame->find(
[email protected]7ea066a2009-04-06 20:21:592682 request_id, search_text, options, true, // Force wrapping.
2683 &selection_rect);
initial.commit09911bf2008-07-26 23:55:292684 }
2685 }
2686
[email protected]26aa0482009-09-30 16:55:272687 webview()->setFocusedFrame(search_frame);
initial.commit09911bf2008-07-26 23:55:292688 } while (!result && search_frame != focused_frame);
2689
[email protected]7ea066a2009-04-06 20:21:592690 if (options.findNext) {
[email protected]4f3dc372009-02-24 00:10:292691 // Force the main_frame to report the actual count.
[email protected]dd7daa82009-08-10 05:46:452692 main_frame->increaseMatchCount(0, request_id);
[email protected]4f3dc372009-02-24 00:10:292693 } else {
2694 // If nothing is found, set result to "0 of 0", otherwise, set it to
2695 // "-1 of 1" to indicate that we found at least one item, but we don't know
2696 // yet what is active.
2697 int ordinal = result ? -1 : 0; // -1 here means, we might know more later.
2698 int match_count = result ? 1 : 0; // 1 here means possibly more coming.
initial.commit09911bf2008-07-26 23:55:292699
[email protected]4f3dc372009-02-24 00:10:292700 // If we find no matches then this will be our last status update.
2701 // Otherwise the scoping effort will send more results.
2702 bool final_status_update = !result;
initial.commit09911bf2008-07-26 23:55:292703
[email protected]4f3dc372009-02-24 00:10:292704 // Send the search result over to the browser process.
[email protected]4f999132009-03-31 18:08:402705 Send(new ViewHostMsg_Find_Reply(routing_id_,
[email protected]7ea066a2009-04-06 20:21:592706 request_id,
[email protected]4f3dc372009-02-24 00:10:292707 match_count,
2708 selection_rect,
2709 ordinal,
2710 final_status_update));
initial.commit09911bf2008-07-26 23:55:292711
initial.commit09911bf2008-07-26 23:55:292712 // Scoping effort begins, starting with the mainframe.
2713 search_frame = main_frame;
2714
[email protected]dd7daa82009-08-10 05:46:452715 main_frame->resetMatchCount();
initial.commit09911bf2008-07-26 23:55:292716
2717 do {
2718 // Cancel all old scoping requests before starting a new one.
[email protected]dd7daa82009-08-10 05:46:452719 search_frame->cancelPendingScopingEffort();
initial.commit09911bf2008-07-26 23:55:292720
2721 // We don't start another scoping effort unless at least one match has
2722 // been found.
2723 if (result) {
2724 // Start new scoping request. If the scoping function determines that it
2725 // needs to scope, it will defer until later.
[email protected]dd7daa82009-08-10 05:46:452726 search_frame->scopeStringMatches(request_id,
[email protected]7ea066a2009-04-06 20:21:592727 search_text,
2728 options,
initial.commit09911bf2008-07-26 23:55:292729 true); // reset the tickmarks
2730 }
2731
2732 // Iterate to the next frame. The frame will not necessarily scope, for
2733 // example if it is not visible.
[email protected]b4bb2502009-10-01 22:35:272734 search_frame = search_frame->traverseNext(true);
initial.commit09911bf2008-07-26 23:55:292735 } while (search_frame != main_frame);
2736 }
2737}
2738
[email protected]5c4266922009-07-10 16:41:272739void RenderView::OnDeterminePageText() {
2740 if (!is_loading_) {
2741 if (!webview())
2742 return;
[email protected]26aa0482009-09-30 16:55:272743 WebFrame* main_frame = webview()->mainFrame();
[email protected]5c4266922009-07-10 16:41:272744 std::wstring contents;
2745 CaptureText(main_frame, &contents);
2746 Send(new ViewMsg_DeterminePageText_Reply(routing_id_, contents));
2747 determine_page_text_after_loading_stops_ = false;
2748 return;
2749 }
2750
2751 // We set |determine_page_text_after_loading_stops_| true here so that,
2752 // after page has been loaded completely, the text in the page is captured.
2753 determine_page_text_after_loading_stops_ = true;
2754}
2755
[email protected]ed4bf2d2009-05-05 00:10:062756bool RenderView::WasOpenedByUserGesture() const {
initial.commit09911bf2008-07-26 23:55:292757 return opened_by_user_gesture_;
2758}
2759
initial.commit09911bf2008-07-26 23:55:292760void RenderView::DnsPrefetch(const std::vector<std::string>& host_names) {
2761 Send(new ViewHostMsg_DnsPrefetch(host_names));
2762}
2763
[email protected]630e26b2008-10-14 22:55:172764void RenderView::OnZoom(int function) {
2765 static const bool kZoomIsTextOnly = false;
2766 switch (function) {
2767 case PageZoom::SMALLER:
[email protected]26aa0482009-09-30 16:55:272768 webview()->zoomOut(kZoomIsTextOnly);
initial.commit09911bf2008-07-26 23:55:292769 break;
[email protected]630e26b2008-10-14 22:55:172770 case PageZoom::STANDARD:
[email protected]26aa0482009-09-30 16:55:272771 webview()->zoomDefault();
initial.commit09911bf2008-07-26 23:55:292772 break;
[email protected]630e26b2008-10-14 22:55:172773 case PageZoom::LARGER:
[email protected]26aa0482009-09-30 16:55:272774 webview()->zoomIn(kZoomIsTextOnly);
initial.commit09911bf2008-07-26 23:55:292775 break;
2776 default:
2777 NOTREACHED();
2778 }
2779}
2780
[email protected]41fc0322009-09-04 22:23:402781void RenderView::OnSetPageEncoding(const std::string& encoding_name) {
[email protected]26aa0482009-09-30 16:55:272782 webview()->setPageEncoding(WebString::fromUTF8(encoding_name));
initial.commit09911bf2008-07-26 23:55:292783}
2784
[email protected]a697f4c2009-09-14 22:30:182785void RenderView::OnResetPageEncodingToDefault() {
[email protected]26aa0482009-09-30 16:55:272786 WebString no_encoding;
2787 webview()->setPageEncoding(no_encoding);
[email protected]a697f4c2009-09-14 22:30:182788}
2789
[email protected]611cad42009-03-16 18:51:342790WebDevToolsAgentDelegate* RenderView::GetWebDevToolsAgentDelegate() {
[email protected]b75b7d072009-04-06 13:47:002791 return devtools_agent_.get();
[email protected]611cad42009-03-16 18:51:342792}
2793
[email protected]dd7daa82009-08-10 05:46:452794WebFrame* RenderView::GetChildFrame(const std::wstring& xpath) const {
2795 if (xpath.empty())
[email protected]26aa0482009-09-30 16:55:272796 return webview()->mainFrame();
[email protected]dd7daa82009-08-10 05:46:452797
2798 // xpath string can represent a frame deep down the tree (across multiple
2799 // frame DOMs).
2800 // Example, /html/body/table/tbody/tr/td/iframe\n/frameset/frame[0]
2801 // should break into 2 xpaths
2802 // /html/body/table/tbody/tr/td/iframe & /frameset/frame[0]
2803
[email protected]26aa0482009-09-30 16:55:272804 WebFrame* frame = webview()->mainFrame();
[email protected]dd7daa82009-08-10 05:46:452805
2806 std::wstring xpath_remaining = xpath;
2807 while (!xpath_remaining.empty()) {
2808 std::wstring::size_type delim_pos = xpath_remaining.find_first_of(L'\n');
2809 std::wstring xpath_child;
2810 if (delim_pos != std::wstring::npos) {
2811 xpath_child = xpath_remaining.substr(0, delim_pos);
2812 xpath_remaining.erase(0, delim_pos + 1);
2813 } else {
2814 xpath_remaining.swap(xpath_child);
2815 }
2816 frame = frame->findChildByExpression(WideToUTF16Hack(xpath_child));
initial.commit09911bf2008-07-26 23:55:292817 }
2818
[email protected]dd7daa82009-08-10 05:46:452819 return frame;
initial.commit09911bf2008-07-26 23:55:292820}
2821
[email protected]f29acf52008-11-03 20:08:332822void RenderView::EvaluateScript(const std::wstring& frame_xpath,
2823 const std::wstring& script) {
initial.commit09911bf2008-07-26 23:55:292824 WebFrame* web_frame = GetChildFrame(frame_xpath);
2825 if (!web_frame)
2826 return;
2827
[email protected]dd7daa82009-08-10 05:46:452828 web_frame->executeScript(WebScriptSource(WideToUTF16Hack(script)));
initial.commit09911bf2008-07-26 23:55:292829}
2830
[email protected]1810e132009-03-24 23:35:482831void RenderView::InsertCSS(const std::wstring& frame_xpath,
[email protected]ffaef0c2009-09-15 17:08:082832 const std::string& css,
2833 const std::string& id) {
[email protected]1810e132009-03-24 23:35:482834 WebFrame* web_frame = GetChildFrame(frame_xpath);
2835 if (!web_frame)
2836 return;
2837
[email protected]ffaef0c2009-09-15 17:08:082838 web_frame->insertStyleText(WebString::fromUTF8(css), WebString::fromUTF8(id));
[email protected]1810e132009-03-24 23:35:482839}
2840
initial.commit09911bf2008-07-26 23:55:292841void RenderView::OnScriptEvalRequest(const std::wstring& frame_xpath,
2842 const std::wstring& jscript) {
[email protected]f29acf52008-11-03 20:08:332843 EvaluateScript(frame_xpath, jscript);
initial.commit09911bf2008-07-26 23:55:292844}
2845
[email protected]1810e132009-03-24 23:35:482846void RenderView::OnCSSInsertRequest(const std::wstring& frame_xpath,
[email protected]ffaef0c2009-09-15 17:08:082847 const std::string& css,
2848 const std::string& id) {
2849 InsertCSS(frame_xpath, css, id);
[email protected]ae461542009-06-19 19:03:412850
2851 // Notify RenderViewHost that css has been inserted into the frame.
2852 Send(new ViewHostMsg_OnCSSInserted(routing_id_));
[email protected]1810e132009-03-24 23:35:482853}
2854
[email protected]7ea066a2009-04-06 20:21:592855void RenderView::OnAddMessageToConsole(
2856 const string16& frame_xpath,
2857 const string16& message,
2858 const WebConsoleMessage::Level& level) {
2859 WebFrame* web_frame = GetChildFrame(UTF16ToWideHack(frame_xpath));
[email protected]0dea3ea2009-03-31 23:30:592860 if (web_frame)
[email protected]dd7daa82009-08-10 05:46:452861 web_frame->addMessageToConsole(WebConsoleMessage(level, message));
initial.commit09911bf2008-07-26 23:55:292862}
2863
[email protected]81e63782009-02-27 19:35:092864void RenderView::OnAllowBindings(int enabled_bindings_flags) {
2865 enabled_bindings_ |= enabled_bindings_flags;
initial.commit09911bf2008-07-26 23:55:292866}
2867
2868void RenderView::OnSetDOMUIProperty(const std::string& name,
2869 const std::string& value) {
[email protected]81e63782009-02-27 19:35:092870 DCHECK(BindingsPolicy::is_dom_ui_enabled(enabled_bindings_));
initial.commit09911bf2008-07-26 23:55:292871 dom_ui_bindings_.SetProperty(name, value);
2872}
2873
2874void RenderView::OnReservePageIDRange(int size_of_range) {
2875 next_page_id_ += size_of_range + 1;
2876}
2877
[email protected]e80c73b2009-04-07 23:24:582878void RenderView::OnDragSourceEndedOrMoved(const gfx::Point& client_point,
2879 const gfx::Point& screen_point,
[email protected]1d9f4132009-09-08 17:29:252880 bool ended,
2881 WebDragOperation op) {
[email protected]5f9ae6c2009-07-08 02:38:032882 if (ended) {
[email protected]26aa0482009-09-30 16:55:272883 webview()->dragSourceEndedAt(client_point, screen_point, op);
[email protected]5f9ae6c2009-07-08 02:38:032884 } else {
[email protected]26aa0482009-09-30 16:55:272885 webview()->dragSourceMovedTo(client_point, screen_point);
[email protected]5f9ae6c2009-07-08 02:38:032886 }
initial.commit09911bf2008-07-26 23:55:292887}
2888
2889void RenderView::OnDragSourceSystemDragEnded() {
[email protected]26aa0482009-09-30 16:55:272890 webview()->dragSourceSystemDragEnded();
initial.commit09911bf2008-07-26 23:55:292891}
2892
2893void RenderView::OnUploadFileRequest(const ViewMsg_UploadFile_Params& p) {
2894 webkit_glue::FileUploadData* f = new webkit_glue::FileUploadData;
2895 f->file_path = p.file_path;
2896 f->form_name = p.form;
2897 f->file_name = p.file;
2898 f->submit_name = p.submit;
2899
2900 // Build the other form values map.
2901 if (!p.other_values.empty()) {
2902 std::vector<std::wstring> e;
2903 std::vector<std::wstring> kvp;
2904 std::vector<std::wstring>::iterator i;
2905
2906 SplitString(p.other_values, L'\n', &e);
2907 for (i = e.begin(); i != e.end(); ++i) {
2908 SplitString(*i, L'=', &kvp);
2909 if (kvp.size() == 2)
2910 f->other_form_values[kvp[0]] = kvp[1];
2911 kvp.clear();
2912 }
2913 }
2914
2915 pending_upload_data_.reset(f);
2916 ProcessPendingUpload();
2917}
2918
2919void RenderView::ProcessPendingUpload() {
2920 webkit_glue::FileUploadData* f = pending_upload_data_.get();
2921 if (f && webview() && webkit_glue::FillFormToUploadFile(webview(), *f))
2922 ResetPendingUpload();
2923}
2924
2925void RenderView::ResetPendingUpload() {
2926 pending_upload_data_.reset();
2927}
2928
2929void RenderView::OnFormFill(const FormData& form) {
2930 webkit_glue::FillForm(this->webview(), form);
2931}
2932
2933void RenderView::OnFillPasswordForm(
[email protected]daa8c58e2009-06-15 17:21:102934 const webkit_glue::PasswordFormDomManager::FillData& form_data) {
initial.commit09911bf2008-07-26 23:55:292935 webkit_glue::FillPasswordForm(this->webview(), form_data);
2936}
2937
2938void RenderView::OnDragTargetDragEnter(const WebDropData& drop_data,
[email protected]e80c73b2009-04-07 23:24:582939 const gfx::Point& client_point,
[email protected]1d9f4132009-09-08 17:29:252940 const gfx::Point& screen_point,
2941 WebDragOperationsMask ops) {
[email protected]26aa0482009-09-30 16:55:272942 WebDragOperation operation = webview()->dragTargetDragEnter(
[email protected]e80c73b2009-04-07 23:24:582943 drop_data.ToDragData(),
2944 drop_data.identity,
2945 client_point,
[email protected]1d9f4132009-09-08 17:29:252946 screen_point,
2947 ops);
initial.commit09911bf2008-07-26 23:55:292948
[email protected]1d9f4132009-09-08 17:29:252949 Send(new ViewHostMsg_UpdateDragCursor(routing_id_, operation));
initial.commit09911bf2008-07-26 23:55:292950}
2951
[email protected]e80c73b2009-04-07 23:24:582952void RenderView::OnDragTargetDragOver(const gfx::Point& client_point,
[email protected]1d9f4132009-09-08 17:29:252953 const gfx::Point& screen_point,
2954 WebDragOperationsMask ops) {
[email protected]26aa0482009-09-30 16:55:272955 WebDragOperation operation = webview()->dragTargetDragOver(
[email protected]1d9f4132009-09-08 17:29:252956 client_point,
2957 screen_point,
2958 ops);
initial.commit09911bf2008-07-26 23:55:292959
[email protected]1d9f4132009-09-08 17:29:252960 Send(new ViewHostMsg_UpdateDragCursor(routing_id_, operation));
initial.commit09911bf2008-07-26 23:55:292961}
2962
2963void RenderView::OnDragTargetDragLeave() {
[email protected]26aa0482009-09-30 16:55:272964 webview()->dragTargetDragLeave();
initial.commit09911bf2008-07-26 23:55:292965}
2966
[email protected]e80c73b2009-04-07 23:24:582967void RenderView::OnDragTargetDrop(const gfx::Point& client_point,
2968 const gfx::Point& screen_point) {
[email protected]26aa0482009-09-30 16:55:272969 webview()->dragTargetDrop(client_point, screen_point);
initial.commit09911bf2008-07-26 23:55:292970}
2971
2972void RenderView::OnUpdateWebPreferences(const WebPreferences& prefs) {
[email protected]2fab253a2009-08-17 23:00:592973 webkit_preferences_ = prefs;
2974 webkit_preferences_.Apply(webview());
initial.commit09911bf2008-07-26 23:55:292975}
2976
2977void RenderView::OnSetAltErrorPageURL(const GURL& url) {
2978 alternate_error_page_url_ = url;
2979}
2980
initial.commit09911bf2008-07-26 23:55:292981void RenderView::OnInstallMissingPlugin() {
2982 // This could happen when the first default plugin is deleted.
[email protected]f103ab72009-09-02 17:10:592983 if (first_default_plugin_)
2984 first_default_plugin_->InstallMissingPlugin();
initial.commit09911bf2008-07-26 23:55:292985}
2986
[email protected]b62d1a8c2009-01-13 23:54:572987void RenderView::OnFileChooserResponse(
[email protected]561abe62009-04-06 18:08:342988 const std::vector<FilePath>& file_names) {
[email protected]8029f5672009-03-20 22:33:362989 // This could happen if we navigated to a different page before the user
2990 // closed the chooser.
2991 if (!file_chooser_.get())
2992 return;
2993
[email protected]b62d1a8c2009-01-13 23:54:572994 file_chooser_->OnFileChoose(file_names);
initial.commit09911bf2008-07-26 23:55:292995 file_chooser_.reset();
2996}
2997
2998void RenderView::OnEnableViewSourceMode() {
2999 if (!webview())
3000 return;
[email protected]26aa0482009-09-30 16:55:273001 WebFrame* main_frame = webview()->mainFrame();
initial.commit09911bf2008-07-26 23:55:293002 if (!main_frame)
3003 return;
3004
[email protected]dd7daa82009-08-10 05:46:453005 main_frame->enableViewSourceMode(true);
initial.commit09911bf2008-07-26 23:55:293006}
3007
[email protected]0666aef2009-05-13 19:48:083008void RenderView::OnEnableIntrinsicWidthChangedMode() {
3009 send_preferred_width_changes_ = true;
3010}
3011
[email protected]80d96fa2009-06-10 22:34:513012void RenderView::OnSetRendererPrefs(const RendererPreferences& renderer_prefs) {
3013 renderer_preferences_ = renderer_prefs;
[email protected]6e282c92009-07-24 01:19:373014 UpdateFontRenderingFromRendererPrefs();
[email protected]7a74e102009-09-03 00:16:563015#if defined(OS_LINUX)
[email protected]1c83eb42009-09-11 21:08:413016 WebColorName name = WebKit::WebColorWebkitFocusRingColor;
3017 WebKit::setNamedColors(&name, &renderer_prefs.focus_ring_color, 1);
[email protected]7a74e102009-09-03 00:16:563018#endif
[email protected]80d96fa2009-06-10 22:34:513019}
3020
[email protected]581b87eb2009-07-23 23:06:563021void RenderView::OnMediaPlayerActionAt(int x,
3022 int y,
3023 const MediaPlayerAction& action) {
3024 if (!webview())
3025 return;
3026
3027 webview()->MediaPlayerActionAt(x, y, action);
3028}
3029
[email protected]7b291f92009-08-14 05:43:533030void RenderView::OnNotifyRendererViewType(ViewType::Type type) {
[email protected]078b34612009-09-19 19:31:513031 // When this is first set, the bindings aren't fully loaded. We only need
3032 // to call through this API after the page has already been loaded. It's
3033 // also called in didCreateDocumentElement to bootstrap.
3034 if (view_type_ != ViewType::INVALID) {
3035 if (type == ViewType::EXTENSION_MOLE ||
3036 type == ViewType::EXTENSION_TOOLSTRIP) {
3037 ExtensionProcessBindings::SetViewType(webview(), type);
3038 }
3039 }
[email protected]7b291f92009-08-14 05:43:533040 view_type_ = type;
3041}
3042
3043void RenderView::OnUpdateBrowserWindowId(int window_id) {
3044 browser_window_id_ = window_id;
3045}
3046
initial.commit09911bf2008-07-26 23:55:293047void RenderView::OnUpdateBackForwardListCount(int back_list_count,
3048 int forward_list_count) {
3049 history_back_list_count_ = back_list_count;
3050 history_forward_list_count_ = forward_list_count;
3051}
3052
[email protected]266eb6f2008-09-30 23:56:503053void RenderView::OnGetAccessibilityInfo(
[email protected]6a983b42009-03-20 20:12:253054 const webkit_glue::WebAccessibility::InParams& in_params,
3055 webkit_glue::WebAccessibility::OutParams* out_params) {
[email protected]6c8afae52009-01-22 02:24:573056#if defined(OS_WIN)
[email protected]6a983b42009-03-20 20:12:253057 if (!web_accessibility_manager_.get()) {
3058 web_accessibility_manager_.reset(
3059 webkit_glue::WebAccessibilityManager::Create());
3060 }
[email protected]266eb6f2008-09-30 23:56:503061
[email protected]6a983b42009-03-20 20:12:253062 if (!web_accessibility_manager_->GetAccObjInfo(webview(), in_params,
3063 out_params)) {
[email protected]266eb6f2008-09-30 23:56:503064 return;
3065 }
[email protected]6c8afae52009-01-22 02:24:573066#else // defined(OS_WIN)
3067 // TODO(port): accessibility not yet implemented
3068 NOTIMPLEMENTED();
3069#endif
[email protected]266eb6f2008-09-30 23:56:503070}
3071
[email protected]6a983b42009-03-20 20:12:253072void RenderView::OnClearAccessibilityInfo(int acc_obj_id, bool clear_all) {
[email protected]6c8afae52009-01-22 02:24:573073#if defined(OS_WIN)
[email protected]6a983b42009-03-20 20:12:253074 if (!web_accessibility_manager_.get()) {
[email protected]266eb6f2008-09-30 23:56:503075 // If accessibility is not activated, ignore clearing message.
3076 return;
3077 }
[email protected]e846d0d2009-05-20 00:53:063078
[email protected]6a983b42009-03-20 20:12:253079 if (!web_accessibility_manager_->ClearAccObjMap(acc_obj_id, clear_all))
[email protected]266eb6f2008-09-30 23:56:503080 return;
[email protected]e846d0d2009-05-20 00:53:063081
[email protected]6c8afae52009-01-22 02:24:573082#else // defined(OS_WIN)
3083 // TODO(port): accessibility not yet implemented
3084 NOTIMPLEMENTED();
3085#endif
[email protected]266eb6f2008-09-30 23:56:503086}
3087
initial.commit09911bf2008-07-26 23:55:293088void RenderView::OnGetAllSavableResourceLinksForCurrentPage(
3089 const GURL& page_url) {
3090 // Prepare list to storage all savable resource links.
3091 std::vector<GURL> resources_list;
3092 std::vector<GURL> referrers_list;
3093 std::vector<GURL> frames_list;
3094 webkit_glue::SavableResourcesResult result(&resources_list,
3095 &referrers_list,
3096 &frames_list);
3097
3098 if (!webkit_glue::GetAllSavableResourceLinksForCurrentPage(webview(),
3099 page_url,
3100 &result)) {
3101 // If something is wrong when collecting all savable resource links,
3102 // send empty list to embedder(browser) to tell it failed.
3103 referrers_list.clear();
3104 resources_list.clear();
3105 frames_list.clear();
3106 }
3107
3108 // Send result of all savable resource links to embedder.
3109 Send(new ViewHostMsg_SendCurrentPageAllSavableResourceLinks(routing_id_,
3110 resources_list,
3111 referrers_list,
3112 frames_list));
3113}
3114
3115void RenderView::OnGetSerializedHtmlDataForCurrentPageWithLocalLinks(
[email protected]f6b48532009-02-12 01:56:323116 const std::vector<GURL>& links,
[email protected]fde6714d12009-02-18 22:39:313117 const std::vector<FilePath>& local_paths,
3118 const FilePath& local_directory_name) {
[email protected]26aa0482009-09-30 16:55:273119 webkit_glue::DomSerializer dom_serializer(webview()->mainFrame(),
initial.commit09911bf2008-07-26 23:55:293120 true,
3121 this,
3122 links,
3123 local_paths,
3124 local_directory_name);
3125 dom_serializer.SerializeDom();
3126}
3127
3128void RenderView::DidSerializeDataForFrame(const GURL& frame_url,
3129 const std::string& data, PageSavingSerializationStatus status) {
3130 Send(new ViewHostMsg_SendSerializedHtmlData(routing_id_,
3131 frame_url, data, static_cast<int32>(status)));
3132}
3133
[email protected]04b4a6c2008-08-02 00:44:473134void RenderView::OnMsgShouldClose() {
[email protected]26aa0482009-09-30 16:55:273135 bool should_close = webview()->dispatchBeforeUnloadEvent();
[email protected]04b4a6c2008-08-02 00:44:473136 Send(new ViewHostMsg_ShouldClose_ACK(routing_id_, should_close));
initial.commit09911bf2008-07-26 23:55:293137}
3138
[email protected]eb6b87a2009-07-24 15:57:393139void RenderView::OnClosePage(const ViewMsg_ClosePage_Params& params) {
initial.commit09911bf2008-07-26 23:55:293140 // TODO(creis): We'd rather use webview()->Close() here, but that currently
3141 // sets the WebView's delegate_ to NULL, preventing any JavaScript dialogs
3142 // in the onunload handler from appearing. For now, we're bypassing that and
3143 // calling the FrameLoader's CloseURL method directly. This should be
3144 // revisited to avoid having two ways to close a page. Having a single way
3145 // to close that can run onunload is also useful for fixing
3146 // http://b/issue?id=753080.
[email protected]26aa0482009-09-30 16:55:273147 WebFrame* main_frame = webview()->mainFrame();
[email protected]7a9b51f2009-06-29 21:28:293148 if (main_frame) {
[email protected]dd7daa82009-08-10 05:46:453149 const GURL& url = main_frame->url();
[email protected]3d9689372009-09-10 04:29:173150 // TODO(davemoore) this code should be removed once willClose() gets
[email protected]7a9b51f2009-06-29 21:28:293151 // called when a page is destroyed. DumpLoadHistograms() is safe to call
3152 // multiple times for the same frame, but it will simplify things.
[email protected]dd7daa82009-08-10 05:46:453153 if (url.SchemeIs(chrome::kHttpScheme) ||
3154 url.SchemeIs(chrome::kHttpsScheme))
[email protected]7a9b51f2009-06-29 21:28:293155 DumpLoadHistograms();
[email protected]7a9b51f2009-06-29 21:28:293156 }
[email protected]26aa0482009-09-30 16:55:273157 webview()->dispatchUnloadEvent();
initial.commit09911bf2008-07-26 23:55:293158
[email protected]eb6b87a2009-07-24 15:57:393159 // Just echo back the params in the ACK.
3160 Send(new ViewHostMsg_ClosePage_ACK(routing_id_, params));
initial.commit09911bf2008-07-26 23:55:293161}
3162
3163void RenderView::OnThemeChanged() {
[email protected]6c8afae52009-01-22 02:24:573164#if defined(OS_WIN)
initial.commit09911bf2008-07-26 23:55:293165 gfx::NativeTheme::instance()->CloseHandles();
3166 gfx::Rect view_rect(0, 0, size_.width(), size_.height());
[email protected]4873c7d2009-07-16 06:36:283167 didInvalidateRect(view_rect);
[email protected]6c8afae52009-01-22 02:24:573168#else // defined(OS_WIN)
3169 // TODO(port): we don't support theming on non-Windows platforms yet
3170 NOTIMPLEMENTED();
3171#endif
initial.commit09911bf2008-07-26 23:55:293172}
3173
[email protected]28790922009-03-09 19:48:373174void RenderView::OnMessageFromExternalHost(const std::string& message,
3175 const std::string& origin,
3176 const std::string& target) {
[email protected]3ac14a052008-08-15 21:22:153177 if (message.empty())
3178 return;
3179
[email protected]28790922009-03-09 19:48:373180 external_host_bindings_.ForwardMessageFromExternalHost(message, origin,
3181 target);
[email protected]3ac14a052008-08-15 21:22:153182}
3183
[email protected]0aa55312008-10-17 21:53:083184void RenderView::OnDisassociateFromPopupCount() {
3185 if (decrement_shared_popup_at_destruction_)
3186 shared_popup_counter_->data--;
3187 shared_popup_counter_ = new SharedRenderViewCounter(0);
3188 decrement_shared_popup_at_destruction_ = false;
3189}
3190
[email protected]15d79e12009-08-02 19:23:453191bool RenderView::MaybeLoadAlternateErrorPage(WebFrame* frame,
3192 const WebURLError& error,
3193 bool replace) {
3194 // We only show alternate error pages in the main frame. They are
3195 // intended to assist the user when navigating, so there is not much
3196 // value in showing them for failed subframes. Ideally, we would be
3197 // able to use the TYPED transition type for this, but that flag is
3198 // not preserved across page reloads.
[email protected]dd7daa82009-08-10 05:46:453199 if (frame->parent())
[email protected]15d79e12009-08-02 19:23:453200 return false;
3201
3202 // Use the alternate error page service if this is a DNS failure or
[email protected]c53976d52009-08-07 18:58:373203 // connection failure.
[email protected]15d79e12009-08-02 19:23:453204 int ec = error.reason;
3205 if (ec != net::ERR_NAME_NOT_RESOLVED &&
3206 ec != net::ERR_CONNECTION_FAILED &&
3207 ec != net::ERR_CONNECTION_REFUSED &&
3208 ec != net::ERR_ADDRESS_UNREACHABLE &&
[email protected]c53976d52009-08-07 18:58:373209 ec != net::ERR_CONNECTION_TIMED_OUT)
[email protected]15d79e12009-08-02 19:23:453210 return false;
3211
3212 const GURL& error_page_url = GetAlternateErrorPageURL(error.unreachableURL,
[email protected]7ccddb8c2009-08-04 17:36:553213 ec == net::ERR_NAME_NOT_RESOLVED ? DNS_ERROR : CONNECTION_ERROR);
[email protected]15d79e12009-08-02 19:23:453214 if (!error_page_url.is_valid())
3215 return false;
3216
3217 // Load an empty page first so there is an immediate response to the error,
3218 // and then kick off a request for the alternate error page.
[email protected]dd7daa82009-08-10 05:46:453219 frame->loadHTMLString(std::string(),
[email protected]15d79e12009-08-02 19:23:453220 GURL(kUnreachableWebDataURL),
3221 error.unreachableURL,
3222 replace);
3223
3224 // Now, create a fetcher for the error page and associate it with the data
3225 // source we just created via the LoadHTMLString call. That way if another
3226 // navigation occurs, the fetcher will get destroyed.
3227 NavigationState* navigation_state =
[email protected]dd7daa82009-08-10 05:46:453228 NavigationState::FromDataSource(frame->provisionalDataSource());
[email protected]15d79e12009-08-02 19:23:453229 navigation_state->set_alt_error_page_fetcher(
3230 new AltErrorPageResourceFetcher(
3231 error_page_url, frame, error,
3232 NewCallback(this, &RenderView::AltErrorPageFinished)));
3233 return true;
3234}
3235
initial.commit09911bf2008-07-26 23:55:293236std::string RenderView::GetAltHTMLForTemplate(
3237 const DictionaryValue& error_strings, int template_resource_id) const {
[email protected]8a16266e2009-09-10 21:08:393238 const base::StringPiece template_html(
initial.commit09911bf2008-07-26 23:55:293239 ResourceBundle::GetSharedInstance().GetRawDataResource(
3240 template_resource_id));
3241
3242 if (template_html.empty()) {
3243 NOTREACHED() << "unable to load template. ID: " << template_resource_id;
3244 return "";
3245 }
[email protected]7cd22a52009-07-14 00:40:253246
initial.commit09911bf2008-07-26 23:55:293247 // "t" is the id of the templates root node.
[email protected]7cd22a52009-07-14 00:40:253248 return jstemplate_builder::GetTemplatesHtml(
initial.commit09911bf2008-07-26 23:55:293249 template_html, &error_strings, "t");
3250}
[email protected]0e79b9e2009-02-13 04:20:483251
[email protected]15d79e12009-08-02 19:23:453252void RenderView::AltErrorPageFinished(WebFrame* frame,
3253 const WebURLError& original_error,
3254 const std::string& html) {
3255 // Here, we replace the blank page we loaded previously.
[email protected]7ccddb8c2009-08-04 17:36:553256
3257 // If we failed to download the alternate error page, fall back to the
3258 // original error page if present. Otherwise, LoadNavigationErrorPage
3259 // will simply display a default error page.
3260 const std::string* html_to_load = &html;
3261 if (html.empty()) {
3262 NavigationState* navigation_state =
[email protected]dd7daa82009-08-10 05:46:453263 NavigationState::FromDataSource(frame->dataSource());
[email protected]7ccddb8c2009-08-04 17:36:553264 html_to_load = &navigation_state->postponed_data();
3265 }
3266 LoadNavigationErrorPage(
3267 frame, WebURLRequest(), original_error, *html_to_load, true);
[email protected]15d79e12009-08-02 19:23:453268}
3269
[email protected]30f75e62009-02-25 22:01:003270void RenderView::OnMoveOrResizeStarted() {
3271 if (webview())
3272 webview()->HideAutofillPopup();
3273}
3274
[email protected]30f75e62009-02-25 22:01:003275void RenderView::OnResize(const gfx::Size& new_size,
3276 const gfx::Rect& resizer_rect) {
3277 if (webview())
3278 webview()->HideAutofillPopup();
3279 RenderWidget::OnResize(new_size, resizer_rect);
3280}
[email protected]0aa477bd2009-03-23 22:21:433281
[email protected]05d478752009-04-08 23:38:163282void RenderView::OnClearFocusedNode() {
3283 if (webview())
[email protected]26aa0482009-09-30 16:55:273284 webview()->clearFocusedNode();
[email protected]05d478752009-04-08 23:38:163285}
3286
[email protected]699ab0d2009-04-23 23:19:143287void RenderView::OnSetBackground(const SkBitmap& background) {
3288 if (webview())
[email protected]b4bb2502009-10-01 22:35:273289 webview()->setIsTransparent(!background.empty());
[email protected]699ab0d2009-04-23 23:19:143290
3291 SetBackground(background);
3292}
3293
[email protected]8c66c5a2009-07-22 17:26:343294void RenderView::OnSetActive(bool active) {
3295 if (webview())
[email protected]b4bb2502009-10-01 22:35:273296 webview()->setIsActive(active);
[email protected]8c66c5a2009-07-22 17:26:343297}
3298
[email protected]309d7a282009-03-24 09:18:273299void RenderView::SendExtensionRequest(const std::string& name,
3300 const std::string& args,
[email protected]c6619182009-05-12 14:59:323301 int request_id,
[email protected]2f25d7b92009-06-10 00:06:473302 bool has_callback) {
[email protected]c6619182009-05-12 14:59:323303 Send(new ViewHostMsg_ExtensionRequest(routing_id_, name, args, request_id,
[email protected]2f25d7b92009-06-10 00:06:473304 has_callback));
[email protected]309d7a282009-03-24 09:18:273305}
3306
[email protected]c6619182009-05-12 14:59:323307void RenderView::OnExtensionResponse(int request_id,
3308 bool success,
3309 const std::string& response,
3310 const std::string& error) {
[email protected]0f6053962009-07-09 19:26:353311 ExtensionProcessBindings::HandleResponse(
3312 request_id, success, response, error);
[email protected]309d7a282009-03-24 09:18:273313}
[email protected]c20210e62009-04-03 21:39:263314
[email protected]078b34612009-09-19 19:31:513315void RenderView::InjectToolstripCSS() {
3316 if (view_type_ != ViewType::EXTENSION_TOOLSTRIP)
3317 return;
3318
3319 static const base::StringPiece toolstrip_css(
3320 ResourceBundle::GetSharedInstance().GetRawDataResource(
3321 IDR_EXTENSION_TOOLSTRIP_CSS));
3322 std::string css = toolstrip_css.as_string();
3323 InsertCSS(L"", css, "ToolstripDefaultCSS");
3324}
3325
[email protected]7120f132009-07-20 21:05:373326void RenderView::OnExtensionMessageInvoke(const std::string& function_name,
3327 const ListValue& args) {
3328 RendererExtensionBindings::Invoke(function_name, args, this);
3329}
3330
[email protected]e7e4f3c2009-04-21 15:24:083331// Dump all load time histograms.
[email protected]c20210e62009-04-03 21:39:263332//
[email protected]7a9b51f2009-06-29 21:28:293333// There are 13 histograms measuring various times.
[email protected]c20210e62009-04-03 21:39:263334// The time points we keep are
3335// request: time document was requested by user
3336// start: time load of document started
[email protected]a2f6bc112009-06-27 16:27:253337// commit: time load of document started
[email protected]7a9b51f2009-06-29 21:28:293338// finish_document: main document loaded, before onload()
[email protected]c20210e62009-04-03 21:39:263339// finish: after onload() and all resources are loaded
[email protected]7a9b51f2009-06-29 21:28:293340// first_paint: first paint performed
3341// first_paint_after_load: first paint performed after load is finished
3342// begin: request if it was user requested, start otherwise
3343//
[email protected]c20210e62009-04-03 21:39:263344// The times that we histogram are
[email protected]a2f6bc112009-06-27 16:27:253345// request->start,
[email protected]7a9b51f2009-06-29 21:28:293346// start->commit,
3347// commit->finish_document,
3348// finish_document->finish,
3349// begin->commit,
3350// begin->finishDoc,
3351// begin->finish,
3352// begin->first_paint,
3353// begin->first_paint_after_load
3354// commit->finishDoc,
3355// commit->first_paint,
3356// commit->first_paint_after_load,
3357// finish->first_paint_after_load,
[email protected]c20210e62009-04-03 21:39:263358//
[email protected]e7e4f3c2009-04-21 15:24:083359// It's possible for the request time not to be set, if a client
3360// redirect had been done (the user never requested the page)
3361// Also, it's possible to load a page without ever laying it out
[email protected]7a9b51f2009-06-29 21:28:293362// so first_paint and first_paint_after_load can be 0.
[email protected]c20210e62009-04-03 21:39:263363void RenderView::DumpLoadHistograms() const {
[email protected]26aa0482009-09-30 16:55:273364 WebFrame* main_frame = webview()->mainFrame();
[email protected]ed3fb032009-06-16 19:50:563365 NavigationState* navigation_state =
[email protected]dd7daa82009-08-10 05:46:453366 NavigationState::FromDataSource(main_frame->dataSource());
[email protected]7a9b51f2009-06-29 21:28:293367 Time finish = navigation_state->finish_load_time();
[email protected]ed3fb032009-06-16 19:50:563368
[email protected]7a9b51f2009-06-29 21:28:293369 // If we've already dumped or we haven't finished loading, do nothing.
3370 if (navigation_state->load_histograms_recorded() || finish.is_null())
3371 return;
[email protected]ed3fb032009-06-16 19:50:563372
[email protected]7a9b51f2009-06-29 21:28:293373 Time request = navigation_state->request_time();
3374 Time start = navigation_state->start_load_time();
3375 Time commit = navigation_state->commit_load_time();
3376 Time finish_doc = navigation_state->finish_document_load_time();
3377 Time first_paint = navigation_state->first_paint_time();
3378 Time first_paint_after_load =
3379 navigation_state->first_paint_after_load_time();
[email protected]c20210e62009-04-03 21:39:263380
[email protected]7a9b51f2009-06-29 21:28:293381 Time begin;
3382 // Client side redirects will have no request time.
3383 if (request.is_null()) {
3384 begin = start;
3385 } else {
3386 begin = request;
3387 UMA_HISTOGRAM_MEDIUM_TIMES("Renderer4.RequestToStart", start - request);
[email protected]e7e4f3c2009-04-21 15:24:083388 }
[email protected]7a9b51f2009-06-29 21:28:293389 UMA_HISTOGRAM_MEDIUM_TIMES("Renderer4.StartToCommit", commit - start);
3390 UMA_HISTOGRAM_MEDIUM_TIMES(
3391 "Renderer4.CommitToFinishDoc", finish_doc - commit);
3392 UMA_HISTOGRAM_MEDIUM_TIMES(
3393 "Renderer4.FinishDocToFinish", finish - finish_doc);
3394
3395 UMA_HISTOGRAM_MEDIUM_TIMES("Renderer4.BeginToCommit", commit - begin);
3396 UMA_HISTOGRAM_MEDIUM_TIMES("Renderer4.BeginToFinishDoc", finish_doc - begin);
[email protected]e695fbd62009-06-30 16:31:543397
3398 static const TimeDelta kBeginToFinishMin(TimeDelta::FromMilliseconds(10));
3399 static const TimeDelta kBeginToFinishMax(TimeDelta::FromMinutes(10));
3400 static const size_t kBeginToFinishBucketCount(100);
3401
3402 UMA_HISTOGRAM_CUSTOM_TIMES("Renderer4.BeginToFinish",
3403 finish - begin, kBeginToFinishMin,
3404 kBeginToFinishMax, kBeginToFinishBucketCount);
[email protected]0a32257a2009-07-09 18:10:413405 UMA_HISTOGRAM_CUSTOM_TIMES("Renderer4.StartToFinish",
3406 finish - start, kBeginToFinishMin,
3407 kBeginToFinishMax, kBeginToFinishBucketCount);
3408 if (!request.is_null())
3409 UMA_HISTOGRAM_CUSTOM_TIMES("Renderer4.RequestToFinish",
3410 finish - request, kBeginToFinishMin,
3411 kBeginToFinishMax, kBeginToFinishBucketCount);
[email protected]e695fbd62009-06-30 16:31:543412
[email protected]36285b52009-06-30 19:10:003413 static bool use_dns_histogram(FieldTrialList::Find("DnsImpact") &&
3414 !FieldTrialList::Find("DnsImpact")->group_name().empty());
[email protected]0a32257a2009-07-09 18:10:413415 if (use_dns_histogram) {
[email protected]36285b52009-06-30 19:10:003416 UMA_HISTOGRAM_CUSTOM_TIMES(
3417 FieldTrial::MakeName("Renderer4.BeginToFinish", "DnsImpact").data(),
3418 finish - begin, kBeginToFinishMin,
3419 kBeginToFinishMax, kBeginToFinishBucketCount);
[email protected]0a32257a2009-07-09 18:10:413420 UMA_HISTOGRAM_CUSTOM_TIMES(
3421 FieldTrial::MakeName("Renderer4.StartToFinish", "DnsImpact").data(),
3422 finish - start, kBeginToFinishMin,
3423 kBeginToFinishMax, kBeginToFinishBucketCount);
3424 if (!request.is_null())
3425 UMA_HISTOGRAM_CUSTOM_TIMES(
3426 FieldTrial::MakeName("Renderer4.RequestToFinish", "DnsImpact").data(),
3427 finish - request, kBeginToFinishMin,
3428 kBeginToFinishMax, kBeginToFinishBucketCount);
3429 }
[email protected]e695fbd62009-06-30 16:31:543430
[email protected]36285b52009-06-30 19:10:003431 static bool use_sdch_histogram(FieldTrialList::Find("GlobalSdch") &&
3432 !FieldTrialList::Find("GlobalSdch")->group_name().empty());
[email protected]0a32257a2009-07-09 18:10:413433 if (use_sdch_histogram) {
[email protected]36285b52009-06-30 19:10:003434 UMA_HISTOGRAM_CUSTOM_TIMES(
3435 FieldTrial::MakeName("Renderer4.BeginToFinish", "GlobalSdch").data(),
3436 finish - begin, kBeginToFinishMin,
3437 kBeginToFinishMax, kBeginToFinishBucketCount);
[email protected]0a32257a2009-07-09 18:10:413438 UMA_HISTOGRAM_CUSTOM_TIMES(
3439 FieldTrial::MakeName("Renderer4.StartToFinish", "GlobalSdch").data(),
3440 finish - start, kBeginToFinishMin,
3441 kBeginToFinishMax, kBeginToFinishBucketCount);
3442 if (!request.is_null())
3443 UMA_HISTOGRAM_CUSTOM_TIMES(
3444 FieldTrial::MakeName("Renderer4.RequestToFinish",
3445 "GlobalSdch").data(),
3446 finish - request, kBeginToFinishMin,
3447 kBeginToFinishMax, kBeginToFinishBucketCount);
3448 }
[email protected]7a9b51f2009-06-29 21:28:293449
[email protected]5fff93f2009-08-02 04:27:343450 static bool use_socket_late_binding_histogram =
3451 FieldTrialList::Find("SocketLateBinding") &&
3452 !FieldTrialList::Find("SocketLateBinding")->group_name().empty();
3453 if (use_socket_late_binding_histogram) {
3454 UMA_HISTOGRAM_CUSTOM_TIMES(
3455 FieldTrial::MakeName("Renderer4.BeginToFinish",
3456 "SocketLateBinding").data(),
3457 finish - begin, kBeginToFinishMin,
3458 kBeginToFinishMax, kBeginToFinishBucketCount);
3459 UMA_HISTOGRAM_CUSTOM_TIMES(
3460 FieldTrial::MakeName("Renderer4.StartToFinish",
3461 "SocketLateBinding").data(),
3462 finish - start, kBeginToFinishMin,
3463 kBeginToFinishMax, kBeginToFinishBucketCount);
3464 if (!request.is_null())
3465 UMA_HISTOGRAM_CUSTOM_TIMES(
3466 FieldTrial::MakeName("Renderer4.RequestToFinish",
3467 "SocketLateBinding").data(),
3468 finish - request, kBeginToFinishMin,
3469 kBeginToFinishMax, kBeginToFinishBucketCount);
3470 }
3471
[email protected]7e05f6c42009-07-11 01:50:483472 static bool use_cache_histogram1(FieldTrialList::Find("CacheSize") &&
3473 !FieldTrialList::Find("CacheSize")->group_name().empty());
3474 if (use_cache_histogram1)
3475 UMA_HISTOGRAM_CUSTOM_TIMES(
3476 FieldTrial::MakeName("Renderer4.StartToFinish", "CacheSize").data(),
3477 finish - start, kBeginToFinishMin,
3478 kBeginToFinishMax, kBeginToFinishBucketCount);
3479
3480 static bool use_cache_histogram2(FieldTrialList::Find("NewEviction") &&
3481 !FieldTrialList::Find("NewEviction")->group_name().empty());
3482 if (use_cache_histogram2)
3483 UMA_HISTOGRAM_CUSTOM_TIMES(
3484 FieldTrial::MakeName("Renderer4.StartToFinish", "NewEviction").data(),
3485 finish - start, kBeginToFinishMin,
3486 kBeginToFinishMax, kBeginToFinishBucketCount);
3487
[email protected]ab0729e2009-09-30 04:42:463488 static bool use_async_tcp(FieldTrialList::Find("AsyncSlowStart") &&
3489 !FieldTrialList::Find("AsyncSlowStart")->group_name().empty());
3490 if (use_async_tcp) {
3491 UMA_HISTOGRAM_CUSTOM_TIMES(
3492 FieldTrial::MakeName("Renderer4.StartToFinish",
3493 "AsyncSlowStart").data(),
3494 finish - start, kBeginToFinishMin,
3495 kBeginToFinishMax, kBeginToFinishBucketCount);
3496 }
3497
[email protected]7a9b51f2009-06-29 21:28:293498 UMA_HISTOGRAM_MEDIUM_TIMES("Renderer4.CommitToFinish", finish - commit);
3499
3500 if (!first_paint.is_null()) {
3501 UMA_HISTOGRAM_MEDIUM_TIMES(
3502 "Renderer4.BeginToFirstPaint", first_paint - begin);
3503 UMA_HISTOGRAM_MEDIUM_TIMES(
3504 "Renderer4.CommitToFirstPaint", first_paint - commit);
[email protected]c20210e62009-04-03 21:39:263505 }
[email protected]7a9b51f2009-06-29 21:28:293506
3507 if (!first_paint_after_load.is_null()) {
3508 UMA_HISTOGRAM_MEDIUM_TIMES(
3509 "Renderer4.BeginToFirstPaintAfterLoad", first_paint_after_load - begin);
3510 UMA_HISTOGRAM_MEDIUM_TIMES(
3511 "Renderer4.CommitToFirstPaintAfterLoad",
3512 first_paint_after_load - commit);
3513 UMA_HISTOGRAM_MEDIUM_TIMES(
3514 "Renderer4.FinishToFirstPaintAfterLoad",
3515 first_paint_after_load - finish);
3516 }
3517
3518 navigation_state->set_load_histograms_recorded(true);
[email protected]c20210e62009-04-03 21:39:263519}
[email protected]e846d0d2009-05-20 00:53:063520
3521void RenderView::FocusAccessibilityObject(
3522 WebCore::AccessibilityObject* acc_obj) {
3523#if defined(OS_WIN)
3524 if (!web_accessibility_manager_.get()) {
3525 web_accessibility_manager_.reset(
3526 webkit_glue::WebAccessibilityManager::Create());
3527 }
3528
3529 // Retrieve the accessibility object id of the AccessibilityObject.
3530 int acc_obj_id = web_accessibility_manager_->FocusAccObj(acc_obj);
3531
3532 // If id is valid, alert the browser side that an accessibility focus change
3533 // occurred.
3534 if (acc_obj_id >= 0)
3535 Send(new ViewHostMsg_AccessibilityFocusChange(routing_id_, acc_obj_id));
3536
3537#else // defined(OS_WIN)
3538 // TODO(port): accessibility not yet implemented
3539 NOTIMPLEMENTED();
3540#endif
3541}
[email protected]daa8c58e2009-06-15 17:21:103542
3543void RenderView::SendPasswordForms(WebFrame* frame) {
[email protected]dd7daa82009-08-10 05:46:453544 WebVector<WebForm> forms;
3545 frame->forms(forms);
[email protected]daa8c58e2009-06-15 17:21:103546
3547 std::vector<PasswordForm> password_forms;
3548 for (size_t i = 0; i < forms.size(); ++i) {
3549 const WebForm& form = forms[i];
3550
3551 // Respect autocomplete=off.
3552 if (form.isAutoCompleteEnabled()) {
3553 scoped_ptr<PasswordForm> password_form(
3554 PasswordFormDomManager::CreatePasswordForm(form));
3555 if (password_form.get())
3556 password_forms.push_back(*password_form);
3557 }
3558 }
3559
3560 if (!password_forms.empty())
3561 Send(new ViewHostMsg_PasswordFormsSeen(routing_id_, password_forms));
3562}
[email protected]0fda7272009-06-26 15:49:333563
3564void RenderView::Print(WebFrame* frame, bool script_initiated) {
3565 DCHECK(frame);
3566 if (print_helper_.get() == NULL) {
3567 print_helper_.reset(new PrintWebViewHelper(this));
3568 }
3569 print_helper_->Print(frame, script_initiated);
3570}
[email protected]446705872009-09-10 07:22:483571
3572void RenderView::OnSetEditCommandsForNextKeyEvent(
3573 const EditCommands& edit_commands) {
3574 edit_commands_ = edit_commands;
3575}
3576
[email protected]912256b32009-09-18 09:47:353577void RenderView::OnExecuteCode(int request_id, const std::string& extension_id,
3578 bool is_js_code,
3579 const std::string& code_string) {
3580 if (is_loading_) {
3581 scoped_refptr<CodeExecutionInfo> info = new CodeExecutionInfo(
3582 request_id, extension_id, is_js_code, code_string);
3583 pending_code_execution_queue_.push(info);
3584 return;
3585 }
[email protected]26aa0482009-09-30 16:55:273586 WebFrame* main_frame = webview() ? webview()->mainFrame() : NULL;
[email protected]912256b32009-09-18 09:47:353587 if (!main_frame) {
3588 Send(new ViewMsg_ExecuteCodeFinished(routing_id_, request_id, false));
3589 return;
3590 }
3591
3592 if (is_js_code) {
3593 std::vector<WebScriptSource> sources;
3594 sources.push_back(
3595 WebScriptSource(WebString::fromUTF8(code_string)));
3596 UserScriptSlave::InsertInitExtensionCode(&sources, extension_id);
3597 main_frame->executeScriptInNewWorld(&sources.front(), sources.size(),
3598 EXTENSION_GROUP_CONTENT_SCRIPTS);
3599 } else {
3600 main_frame->insertStyleText(WebString::fromUTF8(code_string), WebString());
3601 }
3602
3603 Send(new ViewMsg_ExecuteCodeFinished(routing_id_, request_id, true));
3604}
3605
[email protected]446705872009-09-10 07:22:483606void RenderView::DidHandleKeyEvent() {
3607 edit_commands_.clear();
3608}
3609
[email protected]83dde542009-09-11 20:59:553610void RenderView::EnsureDocumentTag() {
3611 // TODO(darin): There's actually no reason for this to be here. We should
3612 // have the browser side manage the document tag.
3613#if defined(OS_MACOSX)
3614 if (!has_document_tag_) {
3615 // Make the call to get the tag.
3616 Send(new ViewHostMsg_GetDocumentTag(routing_id_, &document_tag_));
3617 has_document_tag_ = true;
3618 }
3619#endif
3620}
[email protected]12636df2009-09-28 22:32:213621
3622bool RenderView::SendAndRunNestedMessageLoop(IPC::SyncMessage* message) {
[email protected]8beff0762009-09-29 02:18:303623 PluginChannelHost::Broadcast(
3624 new PluginMsg_SignalModalDialogEvent(host_window_));
[email protected]12636df2009-09-28 22:32:213625
3626 message->EnableMessagePumping(); // Runs a nested message loop.
3627 bool rv = Send(message);
3628
[email protected]8beff0762009-09-29 02:18:303629 PluginChannelHost::Broadcast(
3630 new PluginMsg_ResetModalDialogEvent(host_window_));
[email protected]12636df2009-09-28 22:32:213631
3632 return rv;
3633}