blob: cd422f28d072b9e77e93cb14343bf1a5784f14be [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"
initial.commit09911bf2008-07-26 23:55:2919#include "base/gfx/png_encoder.h"
[email protected]18bcc3c2009-01-27 21:39:1520#include "base/gfx/native_widget_types.h"
[email protected]8380c092009-06-25 17:45:5121#include "base/process_util.h"
[email protected]7b291f92009-08-14 05:43:5322#include "base/singleton.h"
initial.commit09911bf2008-07-26 23:55:2923#include "base/string_piece.h"
24#include "base/string_util.h"
[email protected]6c8afae52009-01-22 02:24:5725#include "build/build_config.h"
[email protected]81e63782009-02-27 19:35:0926#include "chrome/common/bindings_policy.h"
[email protected]ef916272009-07-08 21:40:5527#include "chrome/common/child_process_logging.h"
initial.commit09911bf2008-07-26 23:55:2928#include "chrome/common/chrome_switches.h"
[email protected]f0af6a72009-05-30 05:25:1729#include "chrome/common/chrome_constants.h"
initial.commit09911bf2008-07-26 23:55:2930#include "chrome/common/jstemplate_builder.h"
[email protected]630e26b2008-10-14 22:55:1731#include "chrome/common/page_zoom.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]f816c012009-06-26 21:48:3240#include "chrome/renderer/extensions/event_bindings.h"
[email protected]0f6053962009-07-09 19:26:3541#include "chrome/renderer/extensions/extension_process_bindings.h"
[email protected]7120f132009-07-20 21:05:3742#include "chrome/renderer/extensions/renderer_extension_bindings.h"
initial.commit09911bf2008-07-26 23:55:2943#include "chrome/renderer/localized_error.h"
[email protected]6f56d482009-02-20 05:02:5644#include "chrome/renderer/media/audio_renderer_impl.h"
[email protected]ed3fb032009-06-16 19:50:5645#include "chrome/renderer/navigation_state.h"
[email protected]d81c1e52009-06-03 22:09:5046#include "chrome/renderer/print_web_view_helper.h"
[email protected]39008c02009-02-11 23:59:2547#include "chrome/renderer/render_process.h"
[email protected]0938d3c2009-01-09 20:37:3548#include "chrome/renderer/user_script_slave.h"
initial.commit09911bf2008-07-26 23:55:2949#include "chrome/renderer/visitedlink_slave.h"
[email protected]ba4b17f2009-02-11 21:32:2950#include "chrome/renderer/webplugin_delegate_proxy.h"
[email protected]eb47a132009-03-04 00:39:5651#include "chrome/renderer/webworker_proxy.h"
[email protected]34ac8f32009-02-22 23:03:2752#include "grit/generated_resources.h"
53#include "grit/renderer_resources.h"
[email protected]f11ca0732009-04-11 00:09:3454#include "net/base/data_url.h"
initial.commit09911bf2008-07-26 23:55:2955#include "net/base/escape.h"
56#include "net/base/net_errors.h"
[email protected]c399a8a2008-11-22 19:38:0057#include "skia/ext/bitmap_platform_device.h"
[email protected]83c9e6552008-12-03 16:22:1058#include "skia/ext/image_operations.h"
[email protected]726985e22009-06-18 21:09:2859#include "webkit/api/public/WebDataSource.h"
[email protected]afdcf5c2009-05-10 20:30:4160#include "webkit/api/public/WebDragData.h"
[email protected]daa8c58e2009-06-15 17:21:1061#include "webkit/api/public/WebForm.h"
[email protected]dd7daa82009-08-10 05:46:4562#include "webkit/api/public/WebFrame.h"
[email protected]ca948a22009-06-25 19:36:1763#include "webkit/api/public/WebHistoryItem.h"
[email protected]581b87eb2009-07-23 23:06:5664#include "webkit/api/public/WebNode.h"
[email protected]afdcf5c2009-05-10 20:30:4165#include "webkit/api/public/WebPoint.h"
66#include "webkit/api/public/WebRect.h"
67#include "webkit/api/public/WebScriptSource.h"
68#include "webkit/api/public/WebSize.h"
[email protected]726985e22009-06-18 21:09:2869#include "webkit/api/public/WebURL.h"
70#include "webkit/api/public/WebURLError.h"
71#include "webkit/api/public/WebURLRequest.h"
72#include "webkit/api/public/WebURLResponse.h"
73#include "webkit/api/public/WebVector.h"
[email protected]f430b5712009-08-21 21:46:3174#include "webkit/appcache/appcache_interfaces.h"
[email protected]ba4b17f2009-02-11 21:32:2975#include "webkit/default_plugin/default_plugin_shared.h"
[email protected]ca948a22009-06-25 19:36:1776#include "webkit/glue/glue_serialize.h"
initial.commit09911bf2008-07-26 23:55:2977#include "webkit/glue/dom_operations.h"
78#include "webkit/glue/dom_serializer.h"
[email protected]f11ca0732009-04-11 00:09:3479#include "webkit/glue/image_decoder.h"
[email protected]8e296bbd2009-07-22 21:37:1780#include "webkit/glue/media/buffered_data_source.h"
[email protected]8380c092009-06-25 17:45:5181#include "webkit/glue/media/simple_data_source.h"
initial.commit09911bf2008-07-26 23:55:2982#include "webkit/glue/password_form.h"
[email protected]ba4b17f2009-02-11 21:32:2983#include "webkit/glue/plugins/plugin_list.h"
[email protected]8a3b7962009-09-04 05:53:2384#include "webkit/glue/plugins/webplugin_delegate_impl.h"
initial.commit09911bf2008-07-26 23:55:2985#include "webkit/glue/searchable_form_data.h"
[email protected]6a983b42009-03-20 20:12:2586#include "webkit/glue/webaccessibilitymanager_impl.h"
[email protected]611cad42009-03-16 18:51:3487#include "webkit/glue/webdevtoolsagent_delegate.h"
initial.commit09911bf2008-07-26 23:55:2988#include "webkit/glue/webdropdata.h"
initial.commit09911bf2008-07-26 23:55:2989#include "webkit/glue/webkit_glue.h"
[email protected]add51772009-06-11 18:25:1790#include "webkit/glue/webmediaplayer_impl.h"
[email protected]f103ab72009-09-02 17:10:5991#include "webkit/glue/webplugin_impl.h"
initial.commit09911bf2008-07-26 23:55:2992#include "webkit/glue/webview.h"
initial.commit09911bf2008-07-26 23:55:2993
[email protected]6c8afae52009-01-22 02:24:5794#if defined(OS_WIN)
95// TODO(port): these files are currently Windows only because they concern:
[email protected]6c8afae52009-01-22 02:24:5796// * theming
[email protected]6c8afae52009-01-22 02:24:5797#include "base/gfx/native_theme.h"
[email protected]6c8afae52009-01-22 02:24:5798#endif
99
[email protected]c20210e62009-04-03 21:39:26100using base::Time;
[email protected]e1acf6f2008-10-27 20:43:33101using base::TimeDelta;
[email protected]15d79e12009-08-02 19:23:45102using webkit_glue::AltErrorPageResourceFetcher;
[email protected]daa8c58e2009-06-15 17:21:10103using webkit_glue::AutofillForm;
[email protected]ed3fb032009-06-16 19:50:56104using webkit_glue::PasswordForm;
[email protected]daa8c58e2009-06-15 17:21:10105using webkit_glue::PasswordFormDomManager;
106using webkit_glue::SearchableFormData;
[email protected]0dea3ea2009-03-31 23:30:59107using WebKit::WebConsoleMessage;
[email protected]e6f546c32009-07-01 17:12:55108using WebKit::WebData;
[email protected]726985e22009-06-18 21:09:28109using WebKit::WebDataSource;
[email protected]e80c73b2009-04-07 23:24:58110using WebKit::WebDragData;
[email protected]1d9f4132009-09-08 17:29:25111using WebKit::WebDragOperation;
112using WebKit::WebDragOperationsMask;
[email protected]79dbc662009-09-04 05:42:51113using WebKit::WebEditingAction;
[email protected]daa8c58e2009-06-15 17:21:10114using WebKit::WebForm;
[email protected]dd7daa82009-08-10 05:46:45115using WebKit::WebFrame;
[email protected]ca948a22009-06-25 19:36:17116using WebKit::WebHistoryItem;
[email protected]4873c7d2009-07-16 06:36:28117using WebKit::WebNavigationPolicy;
[email protected]726985e22009-06-18 21:09:28118using WebKit::WebNavigationType;
[email protected]79dbc662009-09-04 05:42:51119using WebKit::WebNode;
[email protected]88efb7ec2009-07-14 16:32:59120using WebKit::WebPopupMenuInfo;
[email protected]79dbc662009-09-04 05:42:51121using WebKit::WebRange;
[email protected]b3f2b912009-04-09 16:18:52122using WebKit::WebRect;
[email protected]4f999132009-03-31 18:08:40123using WebKit::WebScriptSource;
[email protected]2fab253a2009-08-17 23:00:59124using WebKit::WebSettings;
[email protected]8649fb32009-06-26 17:51:02125using WebKit::WebSize;
[email protected]726985e22009-06-18 21:09:28126using WebKit::WebString;
[email protected]79dbc662009-09-04 05:42:51127using WebKit::WebTextAffinity;
[email protected]de570ef2009-07-29 18:27:52128using WebKit::WebTextDirection;
[email protected]726985e22009-06-18 21:09:28129using WebKit::WebURL;
130using WebKit::WebURLError;
131using WebKit::WebURLRequest;
132using WebKit::WebURLResponse;
[email protected]4873c7d2009-07-16 06:36:28133using WebKit::WebVector;
134using WebKit::WebWidget;
[email protected]27ba8532009-04-24 20:22:43135using WebKit::WebWorker;
136using WebKit::WebWorkerClient;
[email protected]e1acf6f2008-10-27 20:43:33137
initial.commit09911bf2008-07-26 23:55:29138//-----------------------------------------------------------------------------
139
140// define to write the time necessary for thumbnail/DOM text retrieval,
141// respectively, into the system debug log
142// #define TIME_BITMAP_RETRIEVAL
143// #define TIME_TEXT_RETRIEVAL
144
145// maximum number of characters in the document to index, any text beyond this
146// point will be clipped
[email protected]6c8afae52009-01-22 02:24:57147static const size_t kMaxIndexChars = 65535;
initial.commit09911bf2008-07-26 23:55:29148
149// Size of the thumbnails that we'll generate
[email protected]8b4f4892009-09-04 21:52:37150static const int kThumbnailWidth = 212;
151static const int kThumbnailHeight = 132;
initial.commit09911bf2008-07-26 23:55:29152
153// Delay in milliseconds that we'll wait before capturing the page contents
154// and thumbnail.
155static const int kDelayForCaptureMs = 500;
156
157// Typically, we capture the page data once the page is loaded.
158// Sometimes, the page never finishes to load, preventing the page capture
159// To workaround this problem, we always perform a capture after the following
160// delay.
161static const int kDelayForForcedCaptureMs = 6000;
162
[email protected]81a34412009-01-05 19:17:24163// The default value for RenderView.delay_seconds_for_form_state_sync_, see
164// that variable for more.
165const int kDefaultDelaySecondsForFormStateSync = 5;
initial.commit09911bf2008-07-26 23:55:29166
167// The next available page ID to use. This ensures that the page IDs are
168// globally unique in the renderer.
169static int32 next_page_id_ = 1;
170
[email protected]0aa55312008-10-17 21:53:08171// The maximum number of popups that can be spawned from one page.
172static const int kMaximumNumberOfUnacknowledgedPopups = 25;
173
initial.commit09911bf2008-07-26 23:55:29174static const char* const kUnreachableWebDataURL =
[email protected]60e448982009-05-06 04:21:16175 "chrome://chromewebdata/";
initial.commit09911bf2008-07-26 23:55:29176
[email protected]50b691c2008-10-31 19:08:35177static const char* const kBackForwardNavigationScheme = "history";
178
[email protected]726985e22009-06-18 21:09:28179static void GetRedirectChain(WebDataSource* ds, std::vector<GURL>* result) {
180 WebVector<WebURL> urls;
181 ds->redirectChain(urls);
182 result->reserve(urls.size());
183 for (size_t i = 0; i < urls.size(); ++i)
184 result->push_back(urls[i]);
185}
186
initial.commit09911bf2008-07-26 23:55:29187///////////////////////////////////////////////////////////////////////////////
188
[email protected]2fab253a2009-08-17 23:00:59189RenderView::RenderView(RenderThreadBase* render_thread,
190 const WebPreferences& webkit_preferences)
[email protected]81a34412009-01-05 19:17:24191 : RenderWidget(render_thread, true),
[email protected]81e63782009-02-27 19:35:09192 enabled_bindings_(0),
[email protected]e75cb49e2009-01-05 23:13:21193 target_url_status_(TARGET_NONE),
[email protected]81a34412009-01-05 19:17:24194 is_loading_(false),
[email protected]e75cb49e2009-01-05 23:13:21195 navigation_gesture_(NavigationGestureUnknown),
[email protected]81a34412009-01-05 19:17:24196 page_id_(-1),
197 last_page_id_sent_to_browser_(-1),
198 last_indexed_page_id_(-1),
[email protected]81a34412009-01-05 19:17:24199 opened_by_user_gesture_(true),
[email protected]bb063b72009-03-27 23:18:50200 ALLOW_THIS_IN_INITIALIZER_LIST(method_factory_(this)),
[email protected]e4ac5df2009-03-17 15:33:11201 devtools_agent_(NULL),
202 devtools_client_(NULL),
[email protected]81a34412009-01-05 19:17:24203 history_back_list_count_(0),
204 history_forward_list_count_(0),
[email protected]81a34412009-01-05 19:17:24205 has_unload_listener_(false),
206 decrement_shared_popup_at_destruction_(false),
[email protected]81a34412009-01-05 19:17:24207 form_field_autofill_request_id_(0),
208 popup_notification_visible_(false),
[email protected]0666aef2009-05-13 19:48:08209 delay_seconds_for_form_state_sync_(kDefaultDelaySecondsForFormStateSync),
210 preferred_width_(0),
[email protected]5c4266922009-07-10 16:41:27211 send_preferred_width_changes_(false),
[email protected]5f450e52009-07-28 13:28:11212 determine_page_text_after_loading_stops_(false),
[email protected]7b291f92009-08-14 05:43:53213 view_type_(ViewType::INVALID),
214 browser_window_id_(-1),
[email protected]01822322009-08-18 22:43:56215 last_top_level_navigation_page_id_(-1),
[email protected]2fab253a2009-08-17 23:00:59216 webkit_preferences_(webkit_preferences) {
[email protected]7b291f92009-08-14 05:43:53217 Singleton<RenderViewSet>()->render_view_set_.insert(this);
initial.commit09911bf2008-07-26 23:55:29218}
219
220RenderView::~RenderView() {
[email protected]7b291f92009-08-14 05:43:53221 Singleton<RenderViewSet>()->render_view_set_.erase(this);
[email protected]0aa55312008-10-17 21:53:08222 if (decrement_shared_popup_at_destruction_)
223 shared_popup_counter_->data--;
224
[email protected]5fb88962009-04-16 19:03:25225 render_thread_->RemoveFilter(audio_message_filter_);
initial.commit09911bf2008-07-26 23:55:29226}
227
228/*static*/
[email protected]0aa55312008-10-17 21:53:08229RenderView* RenderView::Create(
[email protected]81a34412009-01-05 19:17:24230 RenderThreadBase* render_thread,
[email protected]18bcc3c2009-01-27 21:39:15231 gfx::NativeViewId parent_hwnd,
[email protected]1c4947f2009-01-15 22:25:11232 base::WaitableEvent* modal_dialog_event,
[email protected]0aa55312008-10-17 21:53:08233 int32 opener_id,
[email protected]80d96fa2009-06-10 22:34:51234 const RendererPreferences& renderer_prefs,
[email protected]0aa55312008-10-17 21:53:08235 const WebPreferences& webkit_prefs,
236 SharedRenderViewCounter* counter,
237 int32 routing_id) {
initial.commit09911bf2008-07-26 23:55:29238 DCHECK(routing_id != MSG_ROUTING_NONE);
[email protected]2fab253a2009-08-17 23:00:59239 scoped_refptr<RenderView> view = new RenderView(render_thread, webkit_prefs);
initial.commit09911bf2008-07-26 23:55:29240 view->Init(parent_hwnd,
241 modal_dialog_event,
242 opener_id,
[email protected]80d96fa2009-06-10 22:34:51243 renderer_prefs,
[email protected]0aa55312008-10-17 21:53:08244 counter,
initial.commit09911bf2008-07-26 23:55:29245 routing_id); // adds reference
246 return view;
247}
248
249/*static*/
250void RenderView::SetNextPageID(int32 next_page_id) {
251 // This method should only be called during process startup, and the given
252 // page id had better not exceed our current next page id!
[email protected]4646f292009-05-20 03:49:05253 DCHECK_EQ(next_page_id_, 1);
initial.commit09911bf2008-07-26 23:55:29254 DCHECK(next_page_id >= next_page_id_);
255 next_page_id_ = next_page_id;
256}
257
[email protected]fb466342009-07-15 00:43:08258void RenderView::PluginCrashed(base::ProcessId pid,
259 const FilePath& plugin_path) {
260 Send(new ViewHostMsg_CrashedPlugin(routing_id_, pid, plugin_path));
initial.commit09911bf2008-07-26 23:55:29261}
262
initial.commit09911bf2008-07-26 23:55:29263void RenderView::JSOutOfMemory() {
264 Send(new ViewHostMsg_JSOutOfMemory(routing_id_));
265}
266
[email protected]18bcc3c2009-01-27 21:39:15267void RenderView::Init(gfx::NativeViewId parent_hwnd,
[email protected]1c4947f2009-01-15 22:25:11268 base::WaitableEvent* modal_dialog_event,
initial.commit09911bf2008-07-26 23:55:29269 int32 opener_id,
[email protected]80d96fa2009-06-10 22:34:51270 const RendererPreferences& renderer_prefs,
[email protected]0aa55312008-10-17 21:53:08271 SharedRenderViewCounter* counter,
initial.commit09911bf2008-07-26 23:55:29272 int32 routing_id) {
273 DCHECK(!webview());
274
275 if (opener_id != MSG_ROUTING_NONE)
276 opener_id_ = opener_id;
277
[email protected]0aa55312008-10-17 21:53:08278 if (counter) {
279 shared_popup_counter_ = counter;
280 shared_popup_counter_->data++;
281 decrement_shared_popup_at_destruction_ = true;
282 } else {
283 shared_popup_counter_ = new SharedRenderViewCounter(0);
284 decrement_shared_popup_at_destruction_ = false;
285 }
286
[email protected]58bfc6b2009-06-24 09:45:02287 devtools_agent_.reset(new DevToolsAgent(routing_id, this));
[email protected]9b9d7282009-04-08 14:13:04288
[email protected]79dbc662009-09-04 05:42:51289 webwidget_ = WebView::Create(this, this);
[email protected]2fab253a2009-08-17 23:00:59290 webkit_preferences_.Apply(webview());
[email protected]79dbc662009-09-04 05:42:51291 webview()->InitializeMainFrame();
initial.commit09911bf2008-07-26 23:55:29292
[email protected]d3ba77272009-09-03 00:06:09293 OnSetRendererPrefs(renderer_prefs);
294
initial.commit09911bf2008-07-26 23:55:29295 // Don't let WebCore keep a B/F list - we have our own.
296 // We let it keep 1 entry because FrameLoader::goToItem expects an item in the
297 // backForwardList, which is used only in ASSERTs.
298 webview()->SetBackForwardListSize(1);
299
300 routing_id_ = routing_id;
[email protected]81a34412009-01-05 19:17:24301 render_thread_->AddRoute(routing_id_, this);
initial.commit09911bf2008-07-26 23:55:29302 // Take a reference on behalf of the RenderThread. This will be balanced
303 // when we receive ViewMsg_Close.
304 AddRef();
305
306 // If this is a popup, we must wait for the CreatingNew_ACK message before
307 // completing initialization. Otherwise, we can finish it now.
308 if (opener_id == MSG_ROUTING_NONE) {
309 did_show_ = true;
310 CompleteInit(parent_hwnd);
311 }
312
313 host_window_ = parent_hwnd;
[email protected]1c4947f2009-01-15 22:25:11314 modal_dialog_event_.reset(modal_dialog_event);
initial.commit09911bf2008-07-26 23:55:29315
[email protected]58bfc6b2009-06-24 09:45:02316 const CommandLine& command_line = *CommandLine::ForCurrentProcess();
[email protected]81e63782009-02-27 19:35:09317 if (command_line.HasSwitch(switches::kDomAutomationController))
318 enabled_bindings_ |= BindingsPolicy::DOM_AUTOMATION;
initial.commit09911bf2008-07-26 23:55:29319
[email protected]5fb88962009-04-16 19:03:25320 audio_message_filter_ = new AudioMessageFilter(routing_id_);
321 render_thread_->AddFilter(audio_message_filter_);
initial.commit09911bf2008-07-26 23:55:29322}
323
324void RenderView::OnMessageReceived(const IPC::Message& message) {
[email protected]f8b6b6f2009-03-10 16:48:26325 WebFrame* main_frame = webview() ? webview()->GetMainFrame() : NULL;
[email protected]ef916272009-07-08 21:40:55326 child_process_logging::ScopedActiveURLSetter url_setter(
[email protected]dd7daa82009-08-10 05:46:45327 main_frame ? main_frame->url() : WebURL());
[email protected]f8b6b6f2009-03-10 16:48:26328
[email protected]b2abac72009-02-26 12:39:28329 // If this is developer tools renderer intercept tools messages first.
[email protected]e4ac5df2009-03-17 15:33:11330 if (devtools_client_.get() && devtools_client_->OnMessageReceived(message))
[email protected]b2abac72009-02-26 12:39:28331 return;
[email protected]b4b967e2009-04-22 11:33:05332 if (devtools_agent_.get() && devtools_agent_->OnMessageReceived(message))
333 return;
[email protected]b2abac72009-02-26 12:39:28334
initial.commit09911bf2008-07-26 23:55:29335 IPC_BEGIN_MESSAGE_MAP(RenderView, message)
initial.commit09911bf2008-07-26 23:55:29336 IPC_MESSAGE_HANDLER(ViewMsg_CaptureThumbnail, SendThumbnail)
initial.commit09911bf2008-07-26 23:55:29337 IPC_MESSAGE_HANDLER(ViewMsg_PrintPages, OnPrintPages)
[email protected]82270452009-06-19 15:58:01338 IPC_MESSAGE_HANDLER(ViewMsg_PrintingDone, OnPrintingDone)
initial.commit09911bf2008-07-26 23:55:29339 IPC_MESSAGE_HANDLER(ViewMsg_Navigate, OnNavigate)
340 IPC_MESSAGE_HANDLER(ViewMsg_Stop, OnStop)
341 IPC_MESSAGE_HANDLER(ViewMsg_LoadAlternateHTMLText, OnLoadAlternateHTMLText)
342 IPC_MESSAGE_HANDLER(ViewMsg_StopFinding, OnStopFinding)
343 IPC_MESSAGE_HANDLER(ViewMsg_Undo, OnUndo)
344 IPC_MESSAGE_HANDLER(ViewMsg_Redo, OnRedo)
345 IPC_MESSAGE_HANDLER(ViewMsg_Cut, OnCut)
346 IPC_MESSAGE_HANDLER(ViewMsg_Copy, OnCopy)
347 IPC_MESSAGE_HANDLER(ViewMsg_Paste, OnPaste)
348 IPC_MESSAGE_HANDLER(ViewMsg_Replace, OnReplace)
[email protected]bbbd545c2008-12-15 20:18:04349 IPC_MESSAGE_HANDLER(ViewMsg_ToggleSpellCheck, OnToggleSpellCheck)
initial.commit09911bf2008-07-26 23:55:29350 IPC_MESSAGE_HANDLER(ViewMsg_Delete, OnDelete)
351 IPC_MESSAGE_HANDLER(ViewMsg_SelectAll, OnSelectAll)
352 IPC_MESSAGE_HANDLER(ViewMsg_CopyImageAt, OnCopyImageAt)
[email protected]4b59ae602009-06-23 20:58:15353 IPC_MESSAGE_HANDLER(ViewMsg_ExecuteEditCommand, OnExecuteEditCommand)
initial.commit09911bf2008-07-26 23:55:29354 IPC_MESSAGE_HANDLER(ViewMsg_Find, OnFind)
[email protected]5c4266922009-07-10 16:41:27355 IPC_MESSAGE_HANDLER(ViewMsg_DeterminePageText, OnDeterminePageText)
[email protected]630e26b2008-10-14 22:55:17356 IPC_MESSAGE_HANDLER(ViewMsg_Zoom, OnZoom)
[email protected]ea8c7452009-04-02 20:47:06357 IPC_MESSAGE_HANDLER(ViewMsg_InsertText, OnInsertText)
initial.commit09911bf2008-07-26 23:55:29358 IPC_MESSAGE_HANDLER(ViewMsg_SetPageEncoding, OnSetPageEncoding)
[email protected]b2abac72009-02-26 12:39:28359 IPC_MESSAGE_HANDLER(ViewMsg_SetupDevToolsClient, OnSetupDevToolsClient)
[email protected]bf5c2ff392009-07-08 16:24:33360 IPC_MESSAGE_HANDLER(ViewMsg_DownloadFavIcon, OnDownloadFavIcon)
initial.commit09911bf2008-07-26 23:55:29361 IPC_MESSAGE_HANDLER(ViewMsg_ScriptEvalRequest, OnScriptEvalRequest)
[email protected]1810e132009-03-24 23:35:48362 IPC_MESSAGE_HANDLER(ViewMsg_CSSInsertRequest, OnCSSInsertRequest)
initial.commit09911bf2008-07-26 23:55:29363 IPC_MESSAGE_HANDLER(ViewMsg_AddMessageToConsole, OnAddMessageToConsole)
initial.commit09911bf2008-07-26 23:55:29364 IPC_MESSAGE_HANDLER(ViewMsg_ReservePageIDRange, OnReservePageIDRange)
365 IPC_MESSAGE_HANDLER(ViewMsg_UploadFile, OnUploadFileRequest)
366 IPC_MESSAGE_HANDLER(ViewMsg_FormFill, OnFormFill)
367 IPC_MESSAGE_HANDLER(ViewMsg_FillPasswordForm, OnFillPasswordForm)
368 IPC_MESSAGE_HANDLER(ViewMsg_DragTargetDragEnter, OnDragTargetDragEnter)
369 IPC_MESSAGE_HANDLER(ViewMsg_DragTargetDragOver, OnDragTargetDragOver)
370 IPC_MESSAGE_HANDLER(ViewMsg_DragTargetDragLeave, OnDragTargetDragLeave)
371 IPC_MESSAGE_HANDLER(ViewMsg_DragTargetDrop, OnDragTargetDrop)
[email protected]18cb2572008-08-21 20:34:45372 IPC_MESSAGE_HANDLER(ViewMsg_AllowBindings, OnAllowBindings)
initial.commit09911bf2008-07-26 23:55:29373 IPC_MESSAGE_HANDLER(ViewMsg_SetDOMUIProperty, OnSetDOMUIProperty)
[email protected]266eb6f2008-09-30 23:56:50374 IPC_MESSAGE_HANDLER(ViewMsg_DragSourceEndedOrMoved,
375 OnDragSourceEndedOrMoved)
initial.commit09911bf2008-07-26 23:55:29376 IPC_MESSAGE_HANDLER(ViewMsg_DragSourceSystemDragEnded,
377 OnDragSourceSystemDragEnded)
378 IPC_MESSAGE_HANDLER(ViewMsg_SetInitialFocus, OnSetInitialFocus)
379 IPC_MESSAGE_HANDLER(ViewMsg_FindReplyACK, OnFindReplyAck)
380 IPC_MESSAGE_HANDLER(ViewMsg_UpdateTargetURL_ACK, OnUpdateTargetURLAck)
381 IPC_MESSAGE_HANDLER(ViewMsg_UpdateWebPreferences, OnUpdateWebPreferences)
382 IPC_MESSAGE_HANDLER(ViewMsg_SetAltErrorPageURL, OnSetAltErrorPageURL)
383 IPC_MESSAGE_HANDLER(ViewMsg_InstallMissingPlugin, OnInstallMissingPlugin)
384 IPC_MESSAGE_HANDLER(ViewMsg_RunFileChooserResponse, OnFileChooserResponse)
385 IPC_MESSAGE_HANDLER(ViewMsg_EnableViewSourceMode, OnEnableViewSourceMode)
386 IPC_MESSAGE_HANDLER(ViewMsg_UpdateBackForwardListCount,
387 OnUpdateBackForwardListCount)
388 IPC_MESSAGE_HANDLER(ViewMsg_GetAllSavableResourceLinksForCurrentPage,
389 OnGetAllSavableResourceLinksForCurrentPage)
[email protected]f09c7182009-03-10 12:54:04390 IPC_MESSAGE_HANDLER(
391 ViewMsg_GetSerializedHtmlDataForCurrentPageWithLocalLinks,
392 OnGetSerializedHtmlDataForCurrentPageWithLocalLinks)
initial.commit09911bf2008-07-26 23:55:29393 IPC_MESSAGE_HANDLER(ViewMsg_GetApplicationInfo, OnGetApplicationInfo)
[email protected]266eb6f2008-09-30 23:56:50394 IPC_MESSAGE_HANDLER(ViewMsg_GetAccessibilityInfo, OnGetAccessibilityInfo)
395 IPC_MESSAGE_HANDLER(ViewMsg_ClearAccessibilityInfo,
396 OnClearAccessibilityInfo)
initial.commit09911bf2008-07-26 23:55:29397 IPC_MESSAGE_HANDLER(ViewMsg_ShouldClose, OnMsgShouldClose)
398 IPC_MESSAGE_HANDLER(ViewMsg_ClosePage, OnClosePage)
399 IPC_MESSAGE_HANDLER(ViewMsg_ThemeChanged, OnThemeChanged)
[email protected]18cb2572008-08-21 20:34:45400 IPC_MESSAGE_HANDLER(ViewMsg_HandleMessageFromExternalHost,
401 OnMessageFromExternalHost)
[email protected]0aa55312008-10-17 21:53:08402 IPC_MESSAGE_HANDLER(ViewMsg_DisassociateFromPopupCount,
403 OnDisassociateFromPopupCount)
[email protected]0ebf3872008-11-07 21:35:03404 IPC_MESSAGE_HANDLER(ViewMsg_AutofillSuggestions,
405 OnReceivedAutofillSuggestions)
[email protected]2c4410d2009-05-06 23:46:22406 IPC_MESSAGE_HANDLER(ViewMsg_PopupNotificationVisibilityChanged,
407 OnPopupNotificationVisibilityChanged)
[email protected]30f75e62009-02-25 22:01:00408 IPC_MESSAGE_HANDLER(ViewMsg_MoveOrResizeStarted, OnMoveOrResizeStarted)
[email protected]309d7a282009-03-24 09:18:27409 IPC_MESSAGE_HANDLER(ViewMsg_ExtensionResponse, OnExtensionResponse)
[email protected]7120f132009-07-20 21:05:37410 IPC_MESSAGE_HANDLER(ViewMsg_ExtensionMessageInvoke,
411 OnExtensionMessageInvoke)
[email protected]05d478752009-04-08 23:38:16412 IPC_MESSAGE_HANDLER(ViewMsg_ClearFocusedNode, OnClearFocusedNode)
[email protected]699ab0d2009-04-23 23:19:14413 IPC_MESSAGE_HANDLER(ViewMsg_SetBackground, OnSetBackground)
[email protected]0666aef2009-05-13 19:48:08414 IPC_MESSAGE_HANDLER(ViewMsg_EnableIntrinsicWidthChangedMode,
415 OnEnableIntrinsicWidthChangedMode)
[email protected]80d96fa2009-06-10 22:34:51416 IPC_MESSAGE_HANDLER(ViewMsg_SetRendererPrefs, OnSetRendererPrefs)
[email protected]7b291f92009-08-14 05:43:53417 IPC_MESSAGE_HANDLER(ViewMsg_UpdateBrowserWindowId,
418 OnUpdateBrowserWindowId)
419 IPC_MESSAGE_HANDLER(ViewMsg_NotifyRenderViewType,
420 OnNotifyRendererViewType)
[email protected]581b87eb2009-07-23 23:06:56421 IPC_MESSAGE_HANDLER(ViewMsg_MediaPlayerActionAt, OnMediaPlayerActionAt)
[email protected]8c66c5a2009-07-22 17:26:34422 IPC_MESSAGE_HANDLER(ViewMsg_SetActive, OnSetActive)
[email protected]634a6f92008-12-01 21:39:31423
initial.commit09911bf2008-07-26 23:55:29424 // Have the super handle all other messages.
425 IPC_MESSAGE_UNHANDLED(RenderWidget::OnMessageReceived(message))
426 IPC_END_MESSAGE_MAP()
427}
428
initial.commit09911bf2008-07-26 23:55:29429void RenderView::SendThumbnail() {
430 WebFrame* main_frame = webview()->GetMainFrame();
431 if (!main_frame)
432 return;
433
434 // get the URL for this page
[email protected]dd7daa82009-08-10 05:46:45435 GURL url(main_frame->url());
initial.commit09911bf2008-07-26 23:55:29436 if (url.is_empty())
437 return;
438
439 if (size_.IsEmpty())
440 return; // Don't create an empty thumbnail!
441
442 ThumbnailScore score;
443 SkBitmap thumbnail;
[email protected]8649fb32009-06-26 17:51:02444 if (!CaptureThumbnail(webview(), kThumbnailWidth, kThumbnailHeight,
[email protected]b6e4bec2008-11-12 01:17:15445 &thumbnail, &score))
446 return;
447
initial.commit09911bf2008-07-26 23:55:29448 // send the thumbnail message to the browser process
[email protected]674741932009-02-04 23:44:46449 Send(new ViewHostMsg_Thumbnail(routing_id_, url, score, thumbnail));
initial.commit09911bf2008-07-26 23:55:29450}
451
[email protected]068637222009-01-29 16:58:07452void RenderView::OnPrintPages() {
initial.commit09911bf2008-07-26 23:55:29453 DCHECK(webview());
[email protected]aa82249f2009-07-16 17:23:58454 if (webview()) {
455 // If the user has selected text in the currently focused frame we print
456 // only that frame (this makes print selection work for multiple frames).
[email protected]dd7daa82009-08-10 05:46:45457 if (webview()->GetFocusedFrame()->hasSelection())
[email protected]aa82249f2009-07-16 17:23:58458 Print(webview()->GetFocusedFrame(), false);
459 else
460 Print(webview()->GetMainFrame(), false);
461 }
initial.commit09911bf2008-07-26 23:55:29462}
463
[email protected]82270452009-06-19 15:58:01464void RenderView::OnPrintingDone(int document_cookie, bool success) {
465 // Ignoring document cookie here since only one print job can be outstanding
466 // per renderer and document_cookie is 0 when printing is successful.
467 DCHECK(print_helper_.get());
468 if (print_helper_.get() != NULL) {
469 print_helper_->DidFinishPrinting(success);
470 }
471}
472
initial.commit09911bf2008-07-26 23:55:29473void RenderView::CapturePageInfo(int load_id, bool preliminary_capture) {
474 if (load_id != page_id_)
475 return; // this capture call is no longer relevant due to navigation
476 if (load_id == last_indexed_page_id_)
477 return; // we already indexed this page
478
479 if (!webview())
480 return;
481
482 WebFrame* main_frame = webview()->GetMainFrame();
483 if (!main_frame)
484 return;
485
486 // Don't index/capture pages that are in view source mode.
[email protected]dd7daa82009-08-10 05:46:45487 if (main_frame->isViewSourceModeEnabled())
initial.commit09911bf2008-07-26 23:55:29488 return;
489
490 // Don't index/capture pages that failed to load. This only checks the top
491 // level frame so the thumbnail may contain a frame that failed to load.
[email protected]dd7daa82009-08-10 05:46:45492 WebDataSource* ds = main_frame->dataSource();
[email protected]726985e22009-06-18 21:09:28493 if (ds && ds->hasUnreachableURL())
initial.commit09911bf2008-07-26 23:55:29494 return;
495
496 if (!preliminary_capture)
497 last_indexed_page_id_ = load_id;
498
499 // get the URL for this page
[email protected]dd7daa82009-08-10 05:46:45500 GURL url(main_frame->url());
initial.commit09911bf2008-07-26 23:55:29501 if (url.is_empty())
502 return;
503
504 // full text
505 std::wstring contents;
506 CaptureText(main_frame, &contents);
507 if (contents.size()) {
508 // Send the text to the browser for indexing.
509 Send(new ViewHostMsg_PageContents(url, load_id, contents));
510 }
511
[email protected]5c4266922009-07-10 16:41:27512 // Send over text content of this page to the browser.
513 if (determine_page_text_after_loading_stops_) {
514 determine_page_text_after_loading_stops_ = false;
515 Send(new ViewMsg_DeterminePageText_Reply(routing_id_, contents));
516 }
517
initial.commit09911bf2008-07-26 23:55:29518 // thumbnail
519 SendThumbnail();
520}
521
522void RenderView::CaptureText(WebFrame* frame, std::wstring* contents) {
523 contents->clear();
524 if (!frame)
525 return;
526
[email protected]0faf0bd92008-09-09 20:53:27527 // Don't index any https pages. People generally don't want their bank
528 // accounts, etc. indexed on their computer, especially since some of these
529 // things are not marked cachable.
530 // TODO(brettw) we may want to consider more elaborate heuristics such as
531 // the cachability of the page. We may also want to consider subframes (this
532 // test will still index subframes if the subframe is SSL).
[email protected]dd7daa82009-08-10 05:46:45533 if (GURL(frame->url()).SchemeIsSecure())
[email protected]0faf0bd92008-09-09 20:53:27534 return;
535
initial.commit09911bf2008-07-26 23:55:29536#ifdef TIME_TEXT_RETRIEVAL
537 double begin = time_util::GetHighResolutionTimeNow();
538#endif
539
540 // get the contents of the frame
[email protected]dd7daa82009-08-10 05:46:45541 *contents = UTF16ToWideHack(frame->contentAsText(kMaxIndexChars));
initial.commit09911bf2008-07-26 23:55:29542
543#ifdef TIME_TEXT_RETRIEVAL
544 double end = time_util::GetHighResolutionTimeNow();
545 char buf[128];
546 sprintf_s(buf, "%d chars retrieved for indexing in %gms\n",
547 contents.size(), (end - begin)*1000);
548 OutputDebugStringA(buf);
549#endif
550
551 // When the contents are clipped to the maximum, we don't want to have a
552 // partial word indexed at the end that might have been clipped. Therefore,
553 // terminate the string at the last space to ensure no words are clipped.
554 if (contents->size() == kMaxIndexChars) {
555 size_t last_space_index = contents->find_last_of(kWhitespaceWide);
556 if (last_space_index == std::wstring::npos)
557 return; // don't index if we got a huge block of text with no spaces
558 contents->resize(last_space_index);
559 }
560}
561
[email protected]8649fb32009-06-26 17:51:02562bool RenderView::CaptureThumbnail(WebView* view,
initial.commit09911bf2008-07-26 23:55:29563 int w,
564 int h,
565 SkBitmap* thumbnail,
566 ThumbnailScore* score) {
567#ifdef TIME_BITMAP_RETRIEVAL
568 double begin = time_util::GetHighResolutionTimeNow();
569#endif
570
[email protected]4873c7d2009-07-16 06:36:28571 view->layout();
572 const WebSize& size = view->size();
[email protected]b6e4bec2008-11-12 01:17:15573
[email protected]8649fb32009-06-26 17:51:02574 skia::PlatformCanvas canvas;
575 if (!canvas.initialize(size.width, size.height, true))
576 return false;
[email protected]8c89e7792009-08-19 21:18:34577 view->paint(webkit_glue::ToWebCanvas(&canvas),
578 WebRect(0, 0, size.width, size.height));
[email protected]8649fb32009-06-26 17:51:02579
580 skia::BitmapPlatformDevice& device =
581 static_cast<skia::BitmapPlatformDevice&>(canvas.getTopPlatformDevice());
582
583 const SkBitmap& src_bmp = device.accessBitmap(false);
initial.commit09911bf2008-07-26 23:55:29584
585 SkRect dest_rect;
586 dest_rect.set(0, 0, SkIntToScalar(w), SkIntToScalar(h));
587 float dest_aspect = dest_rect.width() / dest_rect.height();
588
589 // Get the src rect so that we can preserve the aspect ratio while filling
590 // the destination.
591 SkIRect src_rect;
592 if (src_bmp.width() < dest_rect.width() ||
593 src_bmp.height() < dest_rect.height()) {
594 // Source image is smaller: we clip the part of source image within the
595 // dest rect, and then stretch it to fill the dest rect. We don't respect
596 // the aspect ratio in this case.
597 src_rect.set(0, 0, static_cast<S16CPU>(dest_rect.width()),
598 static_cast<S16CPU>(dest_rect.height()));
599 score->good_clipping = false;
600 } else {
601 float src_aspect = static_cast<float>(src_bmp.width()) / src_bmp.height();
602 if (src_aspect > dest_aspect) {
603 // Wider than tall, clip horizontally: we center the smaller thumbnail in
604 // the wider screen.
605 S16CPU new_width = static_cast<S16CPU>(src_bmp.height() * dest_aspect);
606 S16CPU x_offset = (src_bmp.width() - new_width) / 2;
607 src_rect.set(x_offset, 0, new_width + x_offset, src_bmp.height());
608 score->good_clipping = false;
609 } else {
610 src_rect.set(0, 0, src_bmp.width(),
611 static_cast<S16CPU>(src_bmp.width() / dest_aspect));
612 score->good_clipping = true;
613 }
614 }
615
[email protected]dd7daa82009-08-10 05:46:45616 score->at_top = (view->GetMainFrame()->scrollOffset().height == 0);
initial.commit09911bf2008-07-26 23:55:29617
618 SkBitmap subset;
[email protected]8649fb32009-06-26 17:51:02619 device.accessBitmap(false).extractSubset(&subset, src_rect);
initial.commit09911bf2008-07-26 23:55:29620
621 // Resample the subset that we want to get it the right size.
[email protected]465b34b72008-12-12 20:19:14622 *thumbnail = skia::ImageOperations::Resize(
623 subset, skia::ImageOperations::RESIZE_LANCZOS3, w, h);
initial.commit09911bf2008-07-26 23:55:29624
625 score->boring_score = CalculateBoringScore(thumbnail);
626
627#ifdef TIME_BITMAP_RETRIEVAL
628 double end = time_util::GetHighResolutionTimeNow();
629 char buf[128];
630 sprintf_s(buf, "thumbnail in %gms\n", (end - begin) * 1000);
631 OutputDebugStringA(buf);
632#endif
[email protected]b6e4bec2008-11-12 01:17:15633 return true;
initial.commit09911bf2008-07-26 23:55:29634}
635
636double RenderView::CalculateBoringScore(SkBitmap* bitmap) {
637 int histogram[256] = {0};
638 color_utils::BuildLumaHistogram(bitmap, histogram);
639
640 int color_count = *std::max_element(histogram, histogram + 256);
641 int pixel_count = bitmap->width() * bitmap->height();
642 return static_cast<double>(color_count) / pixel_count;
643}
644
645void RenderView::OnNavigate(const ViewMsg_Navigate_Params& params) {
646 if (!webview())
647 return;
648
[email protected]8c785c62009-07-13 14:20:15649 if (devtools_agent_.get())
650 devtools_agent_->OnNavigate();
651
[email protected]ef916272009-07-08 21:40:55652 child_process_logging::ScopedActiveURLSetter url_setter(params.url);
[email protected]f8b6b6f2009-03-10 16:48:26653
initial.commit09911bf2008-07-26 23:55:29654 AboutHandler::MaybeHandle(params.url);
655
656 bool is_reload = params.reload;
657
658 WebFrame* main_frame = webview()->GetMainFrame();
[email protected]dd7daa82009-08-10 05:46:45659 if (is_reload && main_frame->currentHistoryItem().isNull()) {
initial.commit09911bf2008-07-26 23:55:29660 // We cannot reload if we do not have any history state. This happens, for
661 // example, when recovering from a crash. Our workaround here is a bit of
662 // a hack since it means that reload after a crashed tab does not cause an
663 // end-to-end cache validation.
664 is_reload = false;
665 }
666
[email protected]77f17a82009-05-21 04:42:54667 // A navigation resulting from loading a javascript URL should not be treated
668 // as a browser initiated event. Instead, we want it to look as if the page
669 // initiated any load resulting from JS execution.
670 if (!params.url.SchemeIs(chrome::kJavaScriptScheme)) {
[email protected]daa8c58e2009-06-15 17:21:10671 pending_navigation_state_.reset(NavigationState::CreateBrowserInitiated(
[email protected]77f17a82009-05-21 04:42:54672 params.page_id, params.transition, params.request_time));
673 }
initial.commit09911bf2008-07-26 23:55:29674
[email protected]04d3c6e2009-05-22 17:00:13675 // If we are reloading, then WebKit will use the history state of the current
676 // page, so we should just ignore any given history state. Otherwise, if we
677 // have history state, then we need to navigate to it, which corresponds to a
678 // back/forward navigation event.
[email protected]e6f546c32009-07-01 17:12:55679 if (is_reload) {
[email protected]dd7daa82009-08-10 05:46:45680 main_frame->reload();
[email protected]e6f546c32009-07-01 17:12:55681 } else if (!params.state.empty()) {
[email protected]04d3c6e2009-05-22 17:00:13682 // We must know the page ID of the page we are navigating back to.
[email protected]f929f2f22009-06-12 16:56:58683 DCHECK_NE(params.page_id, -1);
[email protected]dd7daa82009-08-10 05:46:45684 main_frame->loadHistoryItem(
[email protected]ca948a22009-06-25 19:36:17685 webkit_glue::HistoryItemFromString(params.state));
[email protected]04d3c6e2009-05-22 17:00:13686 } else {
687 // Navigate to the given URL.
[email protected]726985e22009-06-18 21:09:28688 WebURLRequest request(params.url);
initial.commit09911bf2008-07-26 23:55:29689
[email protected]e6f546c32009-07-01 17:12:55690 // A session history navigation should have been accompanied by state.
691 DCHECK_EQ(params.page_id, -1);
[email protected]04d3c6e2009-05-22 17:00:13692
[email protected]dd7daa82009-08-10 05:46:45693 if (main_frame->isViewSourceModeEnabled())
[email protected]e6f546c32009-07-01 17:12:55694 request.setCachePolicy(WebURLRequest::ReturnCacheDataElseLoad);
[email protected]04d3c6e2009-05-22 17:00:13695
[email protected]726985e22009-06-18 21:09:28696 if (params.referrer.is_valid()) {
697 request.setHTTPHeaderField(WebString::fromUTF8("Referer"),
698 WebString::fromUTF8(params.referrer.spec()));
699 }
[email protected]04d3c6e2009-05-22 17:00:13700
[email protected]dd7daa82009-08-10 05:46:45701 main_frame->loadRequest(request);
[email protected]c0588052008-10-27 23:01:50702 }
703
[email protected]77f17a82009-05-21 04:42:54704 // In case LoadRequest failed before DidCreateDataSource was called.
705 pending_navigation_state_.reset();
initial.commit09911bf2008-07-26 23:55:29706}
707
708// Stop loading the current page
709void RenderView::OnStop() {
710 if (webview())
711 webview()->StopLoading();
712}
713
[email protected]e6f546c32009-07-01 17:12:55714void RenderView::OnLoadAlternateHTMLText(const std::string& html,
initial.commit09911bf2008-07-26 23:55:29715 bool new_navigation,
716 const GURL& display_url,
717 const std::string& security_info) {
718 if (!webview())
719 return;
720
[email protected]e6f546c32009-07-01 17:12:55721 pending_navigation_state_.reset(NavigationState::CreateBrowserInitiated(
722 new_navigation ? -1 : page_id_, PageTransition::LINK, Time::Now()));
723 pending_navigation_state_->set_security_info(security_info);
initial.commit09911bf2008-07-26 23:55:29724
[email protected]dd7daa82009-08-10 05:46:45725 webview()->GetMainFrame()->loadHTMLString(html,
[email protected]e6f546c32009-07-01 17:12:55726 GURL(kUnreachableWebDataURL),
727 display_url,
728 !new_navigation);
729
730 pending_navigation_state_.reset();
initial.commit09911bf2008-07-26 23:55:29731}
732
733void RenderView::OnCopyImageAt(int x, int y) {
734 webview()->CopyImageAt(x, y);
735}
736
[email protected]68b1e922009-06-23 16:00:25737void RenderView::OnExecuteEditCommand(const std::string& name,
738 const std::string& value) {
739 if (!webview() || !webview()->GetFocusedFrame())
740 return;
741
[email protected]dd7daa82009-08-10 05:46:45742 webview()->GetFocusedFrame()->executeCommand(
743 WebString::fromUTF8(name), WebString::fromUTF8(value));
[email protected]68b1e922009-06-23 16:00:25744}
745
[email protected]b2abac72009-02-26 12:39:28746void RenderView::OnSetupDevToolsClient() {
[email protected]e4ac5df2009-03-17 15:33:11747 DCHECK(!devtools_client_.get());
748 devtools_client_.reset(new DevToolsClient(this));
[email protected]b2abac72009-02-26 12:39:28749}
750
initial.commit09911bf2008-07-26 23:55:29751void RenderView::OnStopFinding(bool clear_selection) {
752 WebView* view = webview();
753 if (!view)
754 return;
755
756 if (clear_selection)
[email protected]a100d76bb2009-08-14 17:50:22757 view->GetFocusedFrame()->executeCommand(WebString::fromUTF8("Unselect"));
initial.commit09911bf2008-07-26 23:55:29758
759 WebFrame* frame = view->GetMainFrame();
760 while (frame) {
[email protected]dd7daa82009-08-10 05:46:45761 frame->stopFinding(clear_selection);
initial.commit09911bf2008-07-26 23:55:29762 frame = view->GetNextFrameAfter(frame, false);
763 }
764}
765
766void RenderView::OnFindReplyAck() {
767 // Check if there is any queued up request waiting to be sent.
768 if (queued_find_reply_message_.get()) {
769 // Send the search result over to the browser process.
770 Send(queued_find_reply_message_.get());
771 queued_find_reply_message_.release();
772 }
773}
774
775void RenderView::OnUpdateTargetURLAck() {
776 // Check if there is a targeturl waiting to be sent.
777 if (target_url_status_ == TARGET_PENDING) {
778 Send(new ViewHostMsg_UpdateTargetURL(routing_id_, page_id_,
779 pending_target_url_));
780 }
781
782 target_url_status_ = TARGET_NONE;
783}
784
785void RenderView::OnUndo() {
786 if (!webview())
787 return;
788
[email protected]dd7daa82009-08-10 05:46:45789 webview()->GetFocusedFrame()->executeCommand(WebString::fromUTF8("Undo"));
790 UserMetricsRecordAction(L"Undo");
initial.commit09911bf2008-07-26 23:55:29791}
792
793void RenderView::OnRedo() {
794 if (!webview())
795 return;
796
[email protected]dd7daa82009-08-10 05:46:45797 webview()->GetFocusedFrame()->executeCommand(WebString::fromUTF8("Redo"));
798 UserMetricsRecordAction(L"Redo");
initial.commit09911bf2008-07-26 23:55:29799}
800
801void RenderView::OnCut() {
802 if (!webview())
803 return;
804
[email protected]dd7daa82009-08-10 05:46:45805 webview()->GetFocusedFrame()->executeCommand(WebString::fromUTF8("Cut"));
806 UserMetricsRecordAction(L"Cut");
initial.commit09911bf2008-07-26 23:55:29807}
808
809void RenderView::OnCopy() {
810 if (!webview())
811 return;
812
[email protected]dd7daa82009-08-10 05:46:45813 webview()->GetFocusedFrame()->executeCommand(WebString::fromUTF8("Copy"));
814 UserMetricsRecordAction(L"Copy");
initial.commit09911bf2008-07-26 23:55:29815}
816
817void RenderView::OnPaste() {
818 if (!webview())
819 return;
820
[email protected]dd7daa82009-08-10 05:46:45821 webview()->GetFocusedFrame()->executeCommand(WebString::fromUTF8("Paste"));
822 UserMetricsRecordAction(L"Paste");
initial.commit09911bf2008-07-26 23:55:29823}
824
825void RenderView::OnReplace(const std::wstring& text) {
826 if (!webview())
827 return;
828
[email protected]dd7daa82009-08-10 05:46:45829 webview()->GetFocusedFrame()->replaceSelection(WideToUTF16Hack(text));
initial.commit09911bf2008-07-26 23:55:29830}
831
[email protected]bbbd545c2008-12-15 20:18:04832void RenderView::OnToggleSpellCheck() {
833 if (!webview())
834 return;
835
[email protected]dd7daa82009-08-10 05:46:45836 WebFrame* frame = webview()->GetFocusedFrame();
837 frame->enableContinuousSpellChecking(
838 !frame->isContinuousSpellCheckingEnabled());
[email protected]bbbd545c2008-12-15 20:18:04839}
840
initial.commit09911bf2008-07-26 23:55:29841void RenderView::OnDelete() {
842 if (!webview())
843 return;
844
[email protected]dd7daa82009-08-10 05:46:45845 webview()->GetFocusedFrame()->executeCommand(WebString::fromUTF8("Delete"));
846 UserMetricsRecordAction(L"DeleteSelection");
initial.commit09911bf2008-07-26 23:55:29847}
848
849void RenderView::OnSelectAll() {
850 if (!webview())
851 return;
852
[email protected]a100d76bb2009-08-14 17:50:22853 webview()->GetFocusedFrame()->executeCommand(
854 WebString::fromUTF8("SelectAll"));
855 UserMetricsRecordAction(L"SelectAll");
initial.commit09911bf2008-07-26 23:55:29856}
857
858void RenderView::OnSetInitialFocus(bool reverse) {
859 if (!webview())
860 return;
861 webview()->SetInitialFocus(reverse);
862}
863
864///////////////////////////////////////////////////////////////////////////////
865
866// Tell the embedding application that the URL of the active page has changed
867void RenderView::UpdateURL(WebFrame* frame) {
[email protected]dd7daa82009-08-10 05:46:45868 WebDataSource* ds = frame->dataSource();
initial.commit09911bf2008-07-26 23:55:29869 DCHECK(ds);
870
[email protected]726985e22009-06-18 21:09:28871 const WebURLRequest& request = ds->request();
872 const WebURLRequest& original_request = ds->originalRequest();
873 const WebURLResponse& response = ds->response();
initial.commit09911bf2008-07-26 23:55:29874
[email protected]daa8c58e2009-06-15 17:21:10875 NavigationState* navigation_state = NavigationState::FromDataSource(ds);
876 DCHECK(navigation_state);
initial.commit09911bf2008-07-26 23:55:29877
878 ViewHostMsg_FrameNavigate_Params params;
[email protected]726985e22009-06-18 21:09:28879 params.http_status_code = response.httpStatusCode();
initial.commit09911bf2008-07-26 23:55:29880 params.is_post = false;
881 params.page_id = page_id_;
[email protected]726985e22009-06-18 21:09:28882 params.is_content_filtered = response.isContentFiltered();
[email protected]e6f546c32009-07-01 17:12:55883 if (!navigation_state->security_info().empty()) {
initial.commit09911bf2008-07-26 23:55:29884 // SSL state specified in the request takes precedence over the one in the
885 // response.
886 // So far this is only intended for error pages that are not expected to be
887 // over ssl, so we should not get any clash.
[email protected]726985e22009-06-18 21:09:28888 DCHECK(response.securityInfo().isEmpty());
[email protected]e6f546c32009-07-01 17:12:55889 params.security_info = navigation_state->security_info();
initial.commit09911bf2008-07-26 23:55:29890 } else {
[email protected]726985e22009-06-18 21:09:28891 params.security_info = response.securityInfo();
initial.commit09911bf2008-07-26 23:55:29892 }
893
894 // Set the URL to be displayed in the browser UI to the user.
[email protected]726985e22009-06-18 21:09:28895 if (ds->hasUnreachableURL()) {
896 params.url = ds->unreachableURL();
initial.commit09911bf2008-07-26 23:55:29897 } else {
[email protected]726985e22009-06-18 21:09:28898 params.url = request.url();
initial.commit09911bf2008-07-26 23:55:29899 }
900
[email protected]726985e22009-06-18 21:09:28901 GetRedirectChain(ds, &params.redirects);
902 params.should_update_history = !ds->hasUnreachableURL();
initial.commit09911bf2008-07-26 23:55:29903
904 const SearchableFormData* searchable_form_data =
[email protected]daa8c58e2009-06-15 17:21:10905 navigation_state->searchable_form_data();
initial.commit09911bf2008-07-26 23:55:29906 if (searchable_form_data) {
907 params.searchable_form_url = searchable_form_data->url();
908 params.searchable_form_element_name = searchable_form_data->element_name();
909 params.searchable_form_encoding = searchable_form_data->encoding();
910 }
911
912 const PasswordForm* password_form_data =
[email protected]daa8c58e2009-06-15 17:21:10913 navigation_state->password_form_data();
initial.commit09911bf2008-07-26 23:55:29914 if (password_form_data)
915 params.password_form = *password_form_data;
916
917 params.gesture = navigation_gesture_;
918 navigation_gesture_ = NavigationGestureUnknown;
919
[email protected]dd7daa82009-08-10 05:46:45920 if (!frame->parent()) {
initial.commit09911bf2008-07-26 23:55:29921 // Top-level navigation.
922
923 // Update contents MIME type for main frame.
[email protected]9c5645b2009-08-11 03:37:55924 params.contents_mime_type = ds->response().mimeType().utf8();
initial.commit09911bf2008-07-26 23:55:29925
[email protected]daa8c58e2009-06-15 17:21:10926 params.transition = navigation_state->transition_type();
initial.commit09911bf2008-07-26 23:55:29927 if (!PageTransition::IsMainFrame(params.transition)) {
928 // If the main frame does a load, it should not be reported as a subframe
929 // navigation. This can occur in the following case:
930 // 1. You're on a site with frames.
931 // 2. You do a subframe navigation. This is stored with transition type
932 // MANUAL_SUBFRAME.
933 // 3. You navigate to some non-frame site, say, google.com.
934 // 4. You navigate back to the page from step 2. Since it was initially
935 // MANUAL_SUBFRAME, it will be that same transition type here.
936 // We don't want that, because any navigation that changes the toplevel
937 // frame should be tracked as a toplevel navigation (this allows us to
938 // update the URL bar, etc).
939 params.transition = PageTransition::LINK;
940 }
941
initial.commit09911bf2008-07-26 23:55:29942 // If we have a valid consumed client redirect source,
943 // the page contained a client redirect (meta refresh, document.loc...),
944 // so we set the referrer and transition to match.
945 if (completed_client_redirect_src_.is_valid()) {
[email protected]77e09a92008-08-01 18:11:04946 DCHECK(completed_client_redirect_src_ == params.redirects[0]);
initial.commit09911bf2008-07-26 23:55:29947 params.referrer = completed_client_redirect_src_;
948 params.transition = static_cast<PageTransition::Type>(
949 params.transition | PageTransition::CLIENT_REDIRECT);
950 } else {
951 // Bug 654101: the referrer will be empty on https->http transitions. It
952 // would be nice if we could get the real referrer from somewhere.
[email protected]726985e22009-06-18 21:09:28953 params.referrer = GURL(
954 original_request.httpHeaderField(WebString::fromUTF8("Referer")));
initial.commit09911bf2008-07-26 23:55:29955 }
956
[email protected]726985e22009-06-18 21:09:28957 string16 method = request.httpMethod();
958 if (EqualsASCII(method, "POST"))
initial.commit09911bf2008-07-26 23:55:29959 params.is_post = true;
960
961 Send(new ViewHostMsg_FrameNavigate(routing_id_, params));
962 } else {
963 // Subframe navigation: the type depends on whether this navigation
964 // generated a new session history entry. When they do generate a session
965 // history entry, it means the user initiated the navigation and we should
966 // mark it as such. This test checks if this is the first time UpdateURL
967 // has been called since WillNavigateToURL was called to initiate the load.
968 if (page_id_ > last_page_id_sent_to_browser_)
969 params.transition = PageTransition::MANUAL_SUBFRAME;
970 else
971 params.transition = PageTransition::AUTO_SUBFRAME;
972
initial.commit09911bf2008-07-26 23:55:29973 Send(new ViewHostMsg_FrameNavigate(routing_id_, params));
974 }
975
976 last_page_id_sent_to_browser_ =
977 std::max(last_page_id_sent_to_browser_, page_id_);
978
979 // If we end up reusing this WebRequest (for example, due to a #ref click),
[email protected]daa8c58e2009-06-15 17:21:10980 // we don't want the transition type to persist. Just clear it.
981 navigation_state->set_transition_type(PageTransition::LINK);
[email protected]266eb6f2008-09-30 23:56:50982
[email protected]6c8afae52009-01-22 02:24:57983#if defined(OS_WIN)
[email protected]6a983b42009-03-20 20:12:25984 if (web_accessibility_manager_.get()) {
[email protected]be645db2009-02-06 20:36:33985 // Clear accessibility info cache.
[email protected]6a983b42009-03-20 20:12:25986 web_accessibility_manager_->ClearAccObjMap(-1, true);
[email protected]266eb6f2008-09-30 23:56:50987 }
[email protected]6c8afae52009-01-22 02:24:57988#else
[email protected]7d926f92009-03-03 14:26:54989 // TODO(port): accessibility not yet implemented. See http://crbug.com/8288.
[email protected]6c8afae52009-01-22 02:24:57990#endif
initial.commit09911bf2008-07-26 23:55:29991}
992
993// Tell the embedding application that the title of the active page has changed
994void RenderView::UpdateTitle(WebFrame* frame, const std::wstring& title) {
995 // Ignore all but top level navigations...
[email protected]f0af6a72009-05-30 05:25:17996 if (webview()->GetMainFrame() == frame) {
997 Send(new ViewHostMsg_UpdateTitle(
998 routing_id_,
999 page_id_,
1000 title.length() > chrome::kMaxTitleChars ?
1001 title.substr(0, chrome::kMaxTitleChars) : title));
1002 }
initial.commit09911bf2008-07-26 23:55:291003}
1004
1005void RenderView::UpdateEncoding(WebFrame* frame,
[email protected]41fc0322009-09-04 22:23:401006 const std::string& encoding_name) {
initial.commit09911bf2008-07-26 23:55:291007 // Only update main frame's encoding_name.
1008 if (webview()->GetMainFrame() == frame &&
1009 last_encoding_name_ != encoding_name) {
[email protected]e38f40152008-09-12 23:08:301010 // Save the encoding name for later comparing.
initial.commit09911bf2008-07-26 23:55:291011 last_encoding_name_ = encoding_name;
1012
[email protected]e38f40152008-09-12 23:08:301013 Send(new ViewHostMsg_UpdateEncoding(routing_id_, last_encoding_name_));
initial.commit09911bf2008-07-26 23:55:291014 }
1015}
1016
[email protected]f4d34b52008-11-24 23:05:011017// Sends the previous session history state to the browser so it will be saved
1018// before we navigate to a new page. This must be called *before* the page ID
1019// has been updated so we know what it was.
initial.commit09911bf2008-07-26 23:55:291020void RenderView::UpdateSessionHistory(WebFrame* frame) {
1021 // If we have a valid page ID at this point, then it corresponds to the page
1022 // we are navigating away from. Otherwise, this is the first navigation, so
1023 // there is no past session history to record.
1024 if (page_id_ == -1)
1025 return;
1026
[email protected]ca948a22009-06-25 19:36:171027 const WebHistoryItem& item =
[email protected]dd7daa82009-08-10 05:46:451028 webview()->GetMainFrame()->previousHistoryItem();
[email protected]ca948a22009-06-25 19:36:171029 if (item.isNull())
initial.commit09911bf2008-07-26 23:55:291030 return;
[email protected]ca948a22009-06-25 19:36:171031
1032 Send(new ViewHostMsg_UpdateState(
1033 routing_id_, page_id_, webkit_glue::HistoryItemToString(item)));
initial.commit09911bf2008-07-26 23:55:291034}
1035
[email protected]79dbc662009-09-04 05:42:511036// WebViewDelegate ------------------------------------------------------------
initial.commit09911bf2008-07-26 23:55:291037
[email protected]80d96fa2009-06-10 22:34:511038bool RenderView::CanAcceptLoadDrops() const {
1039 return renderer_preferences_.can_accept_load_drops;
1040}
1041
initial.commit09911bf2008-07-26 23:55:291042void RenderView::DidStartLoading(WebView* webview) {
1043 if (is_loading_) {
1044 DLOG(WARNING) << "DidStartLoading called while loading";
1045 return;
1046 }
1047
1048 is_loading_ = true;
1049 // Clear the pointer so that we can assign it only when there is an unknown
1050 // plugin on a page.
[email protected]f103ab72009-09-02 17:10:591051 first_default_plugin_.reset();
initial.commit09911bf2008-07-26 23:55:291052
[email protected]329581b2009-04-28 06:52:351053 Send(new ViewHostMsg_DidStartLoading(routing_id_));
initial.commit09911bf2008-07-26 23:55:291054}
1055
1056void RenderView::DidStopLoading(WebView* webview) {
1057 if (!is_loading_) {
1058 DLOG(WARNING) << "DidStopLoading called while not loading";
1059 return;
1060 }
1061
1062 is_loading_ = false;
1063
1064 // NOTE: For now we're doing the safest thing, and sending out notification
1065 // when done loading. This currently isn't an issue as the favicon is only
1066 // displayed when done loading. Ideally we would send notification when
1067 // finished parsing the head, but webkit doesn't support that yet.
1068 // The feed discovery code would also benefit from access to the head.
[email protected]dd7daa82009-08-10 05:46:451069 GURL favicon_url(webview->GetMainFrame()->favIconURL());
initial.commit09911bf2008-07-26 23:55:291070 if (!favicon_url.is_empty())
1071 Send(new ViewHostMsg_UpdateFavIconURL(routing_id_, page_id_, favicon_url));
1072
[email protected]dd7daa82009-08-10 05:46:451073 AddGURLSearchProvider(webview->GetMainFrame()->openSearchDescriptionURL(),
initial.commit09911bf2008-07-26 23:55:291074 true); // autodetected
1075
[email protected]329581b2009-04-28 06:52:351076 Send(new ViewHostMsg_DidStopLoading(routing_id_));
initial.commit09911bf2008-07-26 23:55:291077
1078 MessageLoop::current()->PostDelayedTask(FROM_HERE,
1079 method_factory_.NewRunnableMethod(&RenderView::CapturePageInfo, page_id_,
1080 false),
1081 kDelayForCaptureMs);
1082
1083 // The page is loaded. Try to process the file we need to upload if any.
1084 ProcessPendingUpload();
1085
1086 // Since the page is done loading, we are sure we don't need to try
1087 // again.
1088 ResetPendingUpload();
1089}
1090
[email protected]77f17a82009-05-21 04:42:541091void RenderView::DidCreateDataSource(WebFrame* frame, WebDataSource* ds) {
[email protected]daa8c58e2009-06-15 17:21:101092 // The rest of RenderView assumes that a WebDataSource will always have a
1093 // non-null NavigationState.
1094 if (pending_navigation_state_.get()) {
[email protected]726985e22009-06-18 21:09:281095 ds->setExtraData(pending_navigation_state_.release());
[email protected]daa8c58e2009-06-15 17:21:101096 } else {
[email protected]726985e22009-06-18 21:09:281097 ds->setExtraData(NavigationState::CreateContentInitiated());
[email protected]daa8c58e2009-06-15 17:21:101098 }
[email protected]77f17a82009-05-21 04:42:541099}
1100
[email protected]a2f6bc112009-06-27 16:27:251101void RenderView::DidPaint() {
1102 WebFrame* main_frame = webview()->GetMainFrame();
1103
[email protected]dd7daa82009-08-10 05:46:451104 if (main_frame->provisionalDataSource()) {
[email protected]a2f6bc112009-06-27 16:27:251105 // If we have a provisional frame we are between the start
1106 // and commit stages of loading...ignore this paint.
1107 return;
1108 }
1109
[email protected]dd7daa82009-08-10 05:46:451110 WebDataSource* ds = main_frame->dataSource();
[email protected]a2f6bc112009-06-27 16:27:251111 NavigationState* navigation_state = NavigationState::FromDataSource(ds);
[email protected]78a3a6f2009-07-02 16:15:011112 DCHECK(navigation_state);
1113
1114 Time now = Time::Now();
1115 if (navigation_state->first_paint_time().is_null()) {
1116 navigation_state->set_first_paint_time(now);
1117 }
1118 if (navigation_state->first_paint_after_load_time().is_null() &&
1119 !navigation_state->finish_load_time().is_null()) {
1120 navigation_state->set_first_paint_after_load_time(now);
[email protected]a2f6bc112009-06-27 16:27:251121 }
1122}
1123
initial.commit09911bf2008-07-26 23:55:291124void RenderView::DidStartProvisionalLoadForFrame(
1125 WebView* webview,
1126 WebFrame* frame,
1127 NavigationGesture gesture) {
[email protected]dd7daa82009-08-10 05:46:451128 WebDataSource* ds = frame->provisionalDataSource();
[email protected]ed3fb032009-06-16 19:50:561129 NavigationState* navigation_state = NavigationState::FromDataSource(ds);
1130
1131 navigation_state->set_start_load_time(Time::Now());
1132
1133 // Update the request time if WebKit has better knowledge of it.
1134 if (navigation_state->request_time().is_null()) {
[email protected]726985e22009-06-18 21:09:281135 double event_time = ds->triggeringEventTime();
[email protected]ed3fb032009-06-16 19:50:561136 if (event_time != 0.0)
1137 navigation_state->set_request_time(Time::FromDoubleT(event_time));
1138 }
1139
[email protected]dd7daa82009-08-10 05:46:451140 bool is_top_most = !frame->parent();
[email protected]ed3fb032009-06-16 19:50:561141 if (is_top_most) {
initial.commit09911bf2008-07-26 23:55:291142 navigation_gesture_ = gesture;
[email protected]266eb6f2008-09-30 23:56:501143
[email protected]77e09a92008-08-01 18:11:041144 // Make sure redirect tracking state is clear for the new load.
1145 completed_client_redirect_src_ = GURL();
[email protected]dd7daa82009-08-10 05:46:451146 } else if (frame->parent()->isLoading()) {
[email protected]15d79e12009-08-02 19:23:451147 // Take note of AUTO_SUBFRAME loads here, so that we can know how to
1148 // load an error page. See DidFailProvisionalLoadWithError.
1149 navigation_state->set_transition_type(PageTransition::AUTO_SUBFRAME);
[email protected]77e09a92008-08-01 18:11:041150 }
initial.commit09911bf2008-07-26 23:55:291151
1152 Send(new ViewHostMsg_DidStartProvisionalLoadForFrame(
[email protected]726985e22009-06-18 21:09:281153 routing_id_, is_top_most, ds->request().url()));
initial.commit09911bf2008-07-26 23:55:291154}
1155
1156bool RenderView::DidLoadResourceFromMemoryCache(WebView* webview,
[email protected]726985e22009-06-18 21:09:281157 const WebURLRequest& request,
1158 const WebURLResponse& response,
initial.commit09911bf2008-07-26 23:55:291159 WebFrame* frame) {
1160 // Let the browser know we loaded a resource from the memory cache. This
1161 // message is needed to display the correct SSL indicators.
[email protected]dd7daa82009-08-10 05:46:451162 Send(new ViewHostMsg_DidLoadResourceFromMemoryCache(
1163 routing_id_,
1164 request.url(),
1165 frame->securityOrigin().utf8(),
1166 frame->top()->securityOrigin().utf8(),
[email protected]726985e22009-06-18 21:09:281167 response.securityInfo()));
initial.commit09911bf2008-07-26 23:55:291168
1169 return false;
1170}
1171
1172void RenderView::DidReceiveProvisionalLoadServerRedirect(WebView* webview,
1173 WebFrame* frame) {
1174 if (frame == webview->GetMainFrame()) {
1175 // Received a redirect on the main frame.
1176 WebDataSource* data_source =
[email protected]dd7daa82009-08-10 05:46:451177 webview->GetMainFrame()->provisionalDataSource();
initial.commit09911bf2008-07-26 23:55:291178 if (!data_source) {
1179 // Should only be invoked when we have a data source.
1180 NOTREACHED();
1181 return;
1182 }
[email protected]726985e22009-06-18 21:09:281183 std::vector<GURL> redirects;
1184 GetRedirectChain(data_source, &redirects);
initial.commit09911bf2008-07-26 23:55:291185 if (redirects.size() >= 2) {
1186 Send(new ViewHostMsg_DidRedirectProvisionalLoad(
1187 routing_id_, page_id_, redirects[redirects.size() - 2],
1188 redirects[redirects.size() - 1]));
1189 }
1190 }
1191}
1192
1193void RenderView::DidFailProvisionalLoadWithError(WebView* webview,
[email protected]726985e22009-06-18 21:09:281194 const WebURLError& error,
initial.commit09911bf2008-07-26 23:55:291195 WebFrame* frame) {
1196 // Notify the browser that we failed a provisional load with an error.
1197 //
1198 // Note: It is important this notification occur before DidStopLoading so the
1199 // SSL manager can react to the provisional load failure before being
1200 // notified the load stopped.
1201 //
[email protected]dd7daa82009-08-10 05:46:451202 WebDataSource* ds = frame->provisionalDataSource();
initial.commit09911bf2008-07-26 23:55:291203 DCHECK(ds);
1204
[email protected]726985e22009-06-18 21:09:281205 const WebURLRequest& failed_request = ds->request();
initial.commit09911bf2008-07-26 23:55:291206
1207 bool show_repost_interstitial =
[email protected]726985e22009-06-18 21:09:281208 (error.reason == net::ERR_CACHE_MISS &&
1209 EqualsASCII(failed_request.httpMethod(), "POST"));
initial.commit09911bf2008-07-26 23:55:291210 Send(new ViewHostMsg_DidFailProvisionalLoadWithError(
[email protected]dd7daa82009-08-10 05:46:451211 routing_id_, !frame->parent(), error.reason, error.unreachableURL,
initial.commit09911bf2008-07-26 23:55:291212 show_repost_interstitial));
1213
initial.commit09911bf2008-07-26 23:55:291214 // Don't display an error page if this is simply a cancelled load. Aside
1215 // from being dumb, WebCore doesn't expect it and it will cause a crash.
[email protected]726985e22009-06-18 21:09:281216 if (error.reason == net::ERR_ABORTED)
initial.commit09911bf2008-07-26 23:55:291217 return;
1218
[email protected]546ddd172009-06-25 00:25:011219 // Make sure we never show errors in view source mode.
[email protected]dd7daa82009-08-10 05:46:451220 frame->enableViewSourceMode(false);
[email protected]546ddd172009-06-25 00:25:011221
[email protected]15d79e12009-08-02 19:23:451222 NavigationState* navigation_state = NavigationState::FromDataSource(ds);
1223
initial.commit09911bf2008-07-26 23:55:291224 // If this is a failed back/forward/reload navigation, then we need to do a
1225 // 'replace' load. This is necessary to avoid messing up session history.
1226 // Otherwise, we do a normal load, which simulates a 'go' navigation as far
1227 // as session history is concerned.
[email protected]15d79e12009-08-02 19:23:451228 //
1229 // AUTO_SUBFRAME loads should always be treated as loads that do not advance
1230 // the page id.
1231 //
1232 bool replace =
1233 navigation_state->pending_page_id() != -1 ||
1234 navigation_state->transition_type() == PageTransition::AUTO_SUBFRAME;
initial.commit09911bf2008-07-26 23:55:291235
[email protected]15d79e12009-08-02 19:23:451236 // If we failed on a browser initiated request, then make sure that our error
1237 // page load is regarded as the same browser initiated request.
1238 if (!navigation_state->is_content_initiated()) {
1239 pending_navigation_state_.reset(NavigationState::CreateBrowserInitiated(
1240 navigation_state->pending_page_id(),
1241 navigation_state->transition_type(),
1242 navigation_state->request_time()));
initial.commit09911bf2008-07-26 23:55:291243 }
[email protected]5df266ac2008-10-15 19:50:131244
[email protected]15d79e12009-08-02 19:23:451245 // Provide the user with a more helpful error page?
1246 if (MaybeLoadAlternateErrorPage(frame, error, replace))
1247 return;
1248
[email protected]be645db2009-02-06 20:36:331249 // Fallback to a local error page.
[email protected]726985e22009-06-18 21:09:281250 LoadNavigationErrorPage(frame, failed_request, error, std::string(),
[email protected]5df266ac2008-10-15 19:50:131251 replace);
initial.commit09911bf2008-07-26 23:55:291252}
1253
1254void RenderView::LoadNavigationErrorPage(WebFrame* frame,
[email protected]726985e22009-06-18 21:09:281255 const WebURLRequest& failed_request,
1256 const WebURLError& error,
initial.commit09911bf2008-07-26 23:55:291257 const std::string& html,
1258 bool replace) {
[email protected]726985e22009-06-18 21:09:281259 GURL failed_url = error.unreachableURL;
initial.commit09911bf2008-07-26 23:55:291260
1261 std::string alt_html;
1262 if (html.empty()) {
1263 // Use a local error page.
1264 int resource_id;
1265 DictionaryValue error_strings;
[email protected]726985e22009-06-18 21:09:281266 if (error.reason == net::ERR_CACHE_MISS &&
1267 EqualsASCII(failed_request.httpMethod(), "POST")) {
initial.commit09911bf2008-07-26 23:55:291268 GetFormRepostErrorValues(failed_url, &error_strings);
1269 resource_id = IDR_ERROR_NO_DETAILS_HTML;
1270 } else {
1271 GetLocalizedErrorValues(error, &error_strings);
1272 resource_id = IDR_NET_ERROR_HTML;
1273 }
[email protected]8e50b602009-03-03 22:59:431274 error_strings.SetString(L"textdirection",
1275 (l10n_util::GetTextDirection() == l10n_util::RIGHT_TO_LEFT) ?
1276 L"rtl" : L"ltr");
initial.commit09911bf2008-07-26 23:55:291277
1278 alt_html = GetAltHTMLForTemplate(error_strings, resource_id);
1279 } else {
1280 alt_html = html;
1281 }
1282
[email protected]dd7daa82009-08-10 05:46:451283 frame->loadHTMLString(alt_html,
[email protected]e6f546c32009-07-01 17:12:551284 GURL(kUnreachableWebDataURL),
1285 failed_url,
1286 replace);
initial.commit09911bf2008-07-26 23:55:291287}
1288
[email protected]7ccddb8c2009-08-04 17:36:551289void RenderView::DidReceiveDocumentData(WebFrame* frame, const char* data,
1290 size_t data_len) {
1291 NavigationState* navigation_state =
[email protected]dd7daa82009-08-10 05:46:451292 NavigationState::FromDataSource(frame->dataSource());
[email protected]7ccddb8c2009-08-04 17:36:551293 if (!navigation_state->postpone_loading_data()) {
[email protected]dd7daa82009-08-10 05:46:451294 frame->commitDocumentData(data, data_len);
[email protected]7ccddb8c2009-08-04 17:36:551295 return;
1296 }
1297
1298 // Continue buffering the response data for the original 404 page. If it
1299 // grows too large, then we'll just let it through.
1300 navigation_state->append_postponed_data(data, data_len);
1301 if (navigation_state->postponed_data().size() >= 512) {
1302 navigation_state->set_postpone_loading_data(false);
[email protected]dd7daa82009-08-10 05:46:451303 frame->commitDocumentData(navigation_state->postponed_data().data(),
[email protected]7ccddb8c2009-08-04 17:36:551304 navigation_state->postponed_data().size());
1305 navigation_state->clear_postponed_data();
1306 }
1307}
1308
initial.commit09911bf2008-07-26 23:55:291309void RenderView::DidCommitLoadForFrame(WebView *webview, WebFrame* frame,
1310 bool is_new_navigation) {
[email protected]daa8c58e2009-06-15 17:21:101311 NavigationState* navigation_state =
[email protected]dd7daa82009-08-10 05:46:451312 NavigationState::FromDataSource(frame->dataSource());
initial.commit09911bf2008-07-26 23:55:291313
[email protected]a2f6bc112009-06-27 16:27:251314 navigation_state->set_commit_load_time(Time::Now());
initial.commit09911bf2008-07-26 23:55:291315 if (is_new_navigation) {
1316 // When we perform a new navigation, we need to update the previous session
1317 // history entry with state for the page we are leaving.
1318 UpdateSessionHistory(frame);
1319
1320 // We bump our Page ID to correspond with the new session history entry.
1321 page_id_ = next_page_id_++;
1322
1323 MessageLoop::current()->PostDelayedTask(FROM_HERE,
1324 method_factory_.NewRunnableMethod(&RenderView::CapturePageInfo,
1325 page_id_, true),
1326 kDelayForForcedCaptureMs);
1327 } else {
[email protected]15d79e12009-08-02 19:23:451328 // Inspect the navigation_state on this frame to see if the navigation
1329 // corresponds to a session history navigation... Note: |frame| may or
1330 // may not be the toplevel frame, but for the case of capturing session
1331 // history, the first committed frame suffices. We keep track of whether
1332 // we've seen this commit before so that only capture session history once
1333 // per navigation.
[email protected]f4d34b52008-11-24 23:05:011334 //
1335 // Note that we need to check if the page ID changed. In the case of a
1336 // reload, the page ID doesn't change, and UpdateSessionHistory gets the
1337 // previous URL and the current page ID, which would be wrong.
[email protected]15d79e12009-08-02 19:23:451338 if (navigation_state->pending_page_id() != -1 &&
1339 navigation_state->pending_page_id() != page_id_ &&
1340 !navigation_state->request_committed()) {
initial.commit09911bf2008-07-26 23:55:291341 // This is a successful session history navigation!
1342 UpdateSessionHistory(frame);
[email protected]77f17a82009-05-21 04:42:541343 page_id_ = navigation_state->pending_page_id();
initial.commit09911bf2008-07-26 23:55:291344 }
1345 }
1346
1347 // Remember that we've already processed this request, so we don't update
1348 // the session history again. We do this regardless of whether this is
1349 // a session history navigation, because if we attempted a session history
1350 // navigation without valid HistoryItem state, WebCore will think it is a
1351 // new navigation.
[email protected]daa8c58e2009-06-15 17:21:101352 navigation_state->set_request_committed(true);
initial.commit09911bf2008-07-26 23:55:291353
1354 UpdateURL(frame);
1355
1356 // If this committed load was initiated by a client redirect, we're
1357 // at the last stop now, so clear it.
1358 completed_client_redirect_src_ = GURL();
1359
1360 // Check whether we have new encoding name.
1361 UpdateEncoding(frame, webview->GetMainFrameEncodingName());
1362}
1363
1364void RenderView::DidReceiveTitle(WebView* webview,
1365 const std::wstring& title,
1366 WebFrame* frame) {
1367 UpdateTitle(frame, title);
1368
1369 // Also check whether we have new encoding name.
1370 UpdateEncoding(frame, webview->GetMainFrameEncodingName());
1371}
1372
1373void RenderView::DidFinishLoadForFrame(WebView* webview, WebFrame* frame) {
[email protected]dd7daa82009-08-10 05:46:451374 WebDataSource* ds = frame->dataSource();
[email protected]a2f6bc112009-06-27 16:27:251375 NavigationState* navigation_state = NavigationState::FromDataSource(ds);
[email protected]78a3a6f2009-07-02 16:15:011376 DCHECK(navigation_state);
1377 navigation_state->set_finish_load_time(Time::Now());
initial.commit09911bf2008-07-26 23:55:291378}
1379
1380void RenderView::DidFailLoadWithError(WebView* webview,
[email protected]726985e22009-06-18 21:09:281381 const WebURLError& error,
initial.commit09911bf2008-07-26 23:55:291382 WebFrame* frame) {
[email protected]546ddd172009-06-25 00:25:011383 // Currently this function is empty. When you implement something here and it
1384 // will display any error messages in HTML, please make sure to call
1385 // frame->SetInViewSourceMode(false) not to show them in view source mode.
initial.commit09911bf2008-07-26 23:55:291386}
1387
1388void RenderView::DidFinishDocumentLoadForFrame(WebView* webview,
1389 WebFrame* frame) {
[email protected]dd7daa82009-08-10 05:46:451390 WebDataSource* ds = frame->dataSource();
[email protected]a2f6bc112009-06-27 16:27:251391 NavigationState* navigation_state = NavigationState::FromDataSource(ds);
[email protected]78a3a6f2009-07-02 16:15:011392 DCHECK(navigation_state);
1393 navigation_state->set_finish_document_load_time(Time::Now());
[email protected]a2f6bc112009-06-27 16:27:251394
[email protected]09b8f82f2009-06-16 20:22:111395 Send(new ViewHostMsg_DocumentLoadedInFrame(routing_id_));
1396
[email protected]daa8c58e2009-06-15 17:21:101397 // The document has now been fully loaded. Scan for password forms to be
1398 // sent up to the browser.
1399 SendPasswordForms(frame);
1400
initial.commit09911bf2008-07-26 23:55:291401 // Check whether we have new encoding name.
1402 UpdateEncoding(frame, webview->GetMainFrameEncodingName());
[email protected]1e0f70402008-10-16 23:57:471403
[email protected]8930d472009-02-21 08:05:281404 if (RenderThread::current()) // Will be NULL during unit tests.
1405 RenderThread::current()->user_script_slave()->InjectScripts(
[email protected]0afe8272009-02-14 04:15:161406 frame, UserScript::DOCUMENT_END);
initial.commit09911bf2008-07-26 23:55:291407}
1408
1409void RenderView::DidHandleOnloadEventsForFrame(WebView* webview,
1410 WebFrame* frame) {
1411}
1412
1413void RenderView::DidChangeLocationWithinPageForFrame(WebView* webview,
1414 WebFrame* frame,
1415 bool is_new_navigation) {
[email protected]77f17a82009-05-21 04:42:541416 // If this was a reference fragment navigation that we initiated, then we
1417 // could end up having a non-null pending navigation state. We just need to
1418 // update the ExtraData on the datasource so that others who read the
1419 // ExtraData will get the new NavigationState. Similarly, if we did not
[email protected]daa8c58e2009-06-15 17:21:101420 // initiate this navigation, then we need to take care to reset any pre-
1421 // existing navigation state to a content-initiated navigation state.
1422 // DidCreateDataSource conveniently takes care of this for us.
[email protected]dd7daa82009-08-10 05:46:451423 DidCreateDataSource(frame, frame->dataSource());
[email protected]77f17a82009-05-21 04:42:541424
initial.commit09911bf2008-07-26 23:55:291425 DidCommitLoadForFrame(webview, frame, is_new_navigation);
[email protected]77f17a82009-05-21 04:42:541426
[email protected]9d806f52009-03-12 22:50:541427 const string16& title =
[email protected]dd7daa82009-08-10 05:46:451428 webview->GetMainFrame()->dataSource()->pageTitle();
[email protected]9d806f52009-03-12 22:50:541429 UpdateTitle(frame, UTF16ToWideHack(title));
initial.commit09911bf2008-07-26 23:55:291430}
1431
initial.commit09911bf2008-07-26 23:55:291432void RenderView::DidCompleteClientRedirect(WebView* webview,
1433 WebFrame* frame,
1434 const GURL& source) {
1435 if (webview->GetMainFrame() == frame)
1436 completed_client_redirect_src_ = source;
1437}
1438
[email protected]7a9b51f2009-06-29 21:28:291439void RenderView::WillCloseFrame(WebView* webview, WebFrame* frame) {
[email protected]dd7daa82009-08-10 05:46:451440 if (!frame->parent()) {
1441 const GURL& url = frame->url();
[email protected]7a9b51f2009-06-29 21:28:291442 if (url.SchemeIs("http") || url.SchemeIs("https"))
1443 DumpLoadHistograms();
1444 }
1445}
1446
[email protected]daa8c58e2009-06-15 17:21:101447void RenderView::WillSubmitForm(WebView* webview, WebFrame* frame,
1448 const WebForm& form) {
1449 NavigationState* navigation_state =
[email protected]dd7daa82009-08-10 05:46:451450 NavigationState::FromDataSource(frame->provisionalDataSource());
[email protected]daa8c58e2009-06-15 17:21:101451
1452 if (navigation_state->transition_type() == PageTransition::LINK)
1453 navigation_state->set_transition_type(PageTransition::FORM_SUBMIT);
1454
1455 // Save these to be processed when the ensuing navigation is committed.
1456 navigation_state->set_searchable_form_data(
1457 SearchableFormData::Create(form));
1458 navigation_state->set_password_form_data(
1459 PasswordFormDomManager::CreatePasswordForm(form));
1460
1461 if (form.isAutoCompleteEnabled()) {
1462 scoped_ptr<AutofillForm> autofill_form(AutofillForm::Create(form));
1463 if (autofill_form.get())
1464 Send(new ViewHostMsg_AutofillFormSubmitted(routing_id_, *autofill_form));
1465 }
1466}
1467
[email protected]7ccddb8c2009-08-04 17:36:551468void RenderView::WillSendRequest(WebFrame* frame, uint32 identifier,
[email protected]a1353852009-08-06 05:34:221469 WebURLRequest* request,
1470 const WebURLResponse& redirect_response) {
[email protected]726985e22009-06-18 21:09:281471 request->setRequestorID(routing_id_);
[email protected]5b35a6b2009-03-16 19:58:081472}
1473
[email protected]7ccddb8c2009-08-04 17:36:551474void RenderView::DidReceiveResponse(WebFrame* frame, uint32 identifier,
1475 const WebURLResponse& response) {
1476 // Consider loading an alternate error page for 404 responses.
1477 if (response.httpStatusCode() != 404)
1478 return;
1479
1480 // Only do this for responses that correspond to a provisional data source
1481 // of the top-most frame. If we have a provisional data source, then we
1482 // can't have any sub-resources yet, so we know that this response must
1483 // correspond to a frame load.
[email protected]dd7daa82009-08-10 05:46:451484 if (!frame->provisionalDataSource() || frame->parent())
[email protected]7ccddb8c2009-08-04 17:36:551485 return;
1486
1487 // If we are in view source mode, then just let the user see the source of
1488 // the server's 404 error page.
[email protected]dd7daa82009-08-10 05:46:451489 if (frame->isViewSourceModeEnabled())
[email protected]7ccddb8c2009-08-04 17:36:551490 return;
1491
1492 // Can we even load an alternate error page for this URL?
1493 if (!GetAlternateErrorPageURL(response.url(), HTTP_404).is_valid())
1494 return;
1495
1496 NavigationState* navigation_state =
[email protected]dd7daa82009-08-10 05:46:451497 NavigationState::FromDataSource(frame->provisionalDataSource());
[email protected]7ccddb8c2009-08-04 17:36:551498 navigation_state->set_postpone_loading_data(true);
1499 navigation_state->clear_postponed_data();
1500}
1501
1502void RenderView::DidFinishLoading(WebFrame* frame, uint32 identifier) {
1503 NavigationState* navigation_state =
[email protected]dd7daa82009-08-10 05:46:451504 NavigationState::FromDataSource(frame->dataSource());
[email protected]7ccddb8c2009-08-04 17:36:551505 if (!navigation_state->postpone_loading_data())
1506 return;
1507
1508 // The server returned a 404 and the content was < 512 bytes (which we
1509 // suppressed). Go ahead and fetch the alternate page content.
1510
[email protected]dd7daa82009-08-10 05:46:451511 const GURL& frame_url = frame->url();
[email protected]7ccddb8c2009-08-04 17:36:551512
1513 const GURL& error_page_url = GetAlternateErrorPageURL(frame_url, HTTP_404);
1514 DCHECK(error_page_url.is_valid());
1515
1516 WebURLError original_error;
1517 original_error.unreachableURL = frame_url;
1518
1519 navigation_state->set_alt_error_page_fetcher(
1520 new AltErrorPageResourceFetcher(
1521 error_page_url, frame, original_error,
1522 NewCallback(this, &RenderView::AltErrorPageFinished)));
1523}
1524
1525void RenderView::BindDOMAutomationController(WebFrame* frame) {
initial.commit09911bf2008-07-26 23:55:291526 dom_automation_controller_.set_message_sender(this);
1527 dom_automation_controller_.set_routing_id(routing_id_);
[email protected]7ccddb8c2009-08-04 17:36:551528 dom_automation_controller_.BindToJavascript(frame,
initial.commit09911bf2008-07-26 23:55:291529 L"domAutomationController");
1530}
1531
[email protected]7ccddb8c2009-08-04 17:36:551532void RenderView::WindowObjectCleared(WebFrame* frame) {
[email protected]81e63782009-02-27 19:35:091533 if (BindingsPolicy::is_dom_automation_enabled(enabled_bindings_))
[email protected]7ccddb8c2009-08-04 17:36:551534 BindDOMAutomationController(frame);
[email protected]81e63782009-02-27 19:35:091535 if (BindingsPolicy::is_dom_ui_enabled(enabled_bindings_)) {
initial.commit09911bf2008-07-26 23:55:291536 dom_ui_bindings_.set_message_sender(this);
1537 dom_ui_bindings_.set_routing_id(routing_id_);
[email protected]7ccddb8c2009-08-04 17:36:551538 dom_ui_bindings_.BindToJavascript(frame, L"chrome");
initial.commit09911bf2008-07-26 23:55:291539 }
[email protected]81e63782009-02-27 19:35:091540 if (BindingsPolicy::is_external_host_enabled(enabled_bindings_)) {
[email protected]18cb2572008-08-21 20:34:451541 external_host_bindings_.set_message_sender(this);
1542 external_host_bindings_.set_routing_id(routing_id_);
[email protected]7ccddb8c2009-08-04 17:36:551543 external_host_bindings_.BindToJavascript(frame, L"externalHost");
[email protected]18cb2572008-08-21 20:34:451544 }
initial.commit09911bf2008-07-26 23:55:291545}
1546
[email protected]0afe8272009-02-14 04:15:161547void RenderView::DocumentElementAvailable(WebFrame* frame) {
[email protected]8930d472009-02-21 08:05:281548 if (RenderThread::current()) // Will be NULL during unit tests.
1549 RenderThread::current()->user_script_slave()->InjectScripts(
[email protected]0afe8272009-02-14 04:15:161550 frame, UserScript::DOCUMENT_START);
[email protected]e95ad332009-08-03 19:44:251551
1552 // Notify the browser about non-blank documents loading in the top frame.
[email protected]2960ff9c2009-08-28 22:24:511553 GURL url = frame->url();
[email protected]e95ad332009-08-03 19:44:251554 if (url.is_valid() && url.spec() != "about:blank") {
1555 if (frame == webview()->GetMainFrame())
1556 Send(new ViewHostMsg_DocumentAvailableInMainFrame(routing_id_));
1557 }
[email protected]0afe8272009-02-14 04:15:161558}
1559
[email protected]b6ce15972009-07-14 22:14:011560void RenderView::DidCreateScriptContextForFrame(WebFrame* webframe) {
[email protected]7120f132009-07-20 21:05:371561 EventBindings::HandleContextCreated(webframe, false);
[email protected]f816c012009-06-26 21:48:321562}
1563
[email protected]b6ce15972009-07-14 22:14:011564void RenderView::DidDestroyScriptContextForFrame(WebFrame* webframe) {
[email protected]f816c012009-06-26 21:48:321565 EventBindings::HandleContextDestroyed(webframe);
1566}
1567
[email protected]b6ce15972009-07-14 22:14:011568void RenderView::DidCreateIsolatedScriptContext(WebFrame* webframe) {
[email protected]7120f132009-07-20 21:05:371569 EventBindings::HandleContextCreated(webframe, true);
[email protected]b6ce15972009-07-14 22:14:011570}
1571
[email protected]4873c7d2009-07-16 06:36:281572WebNavigationPolicy RenderView::PolicyForNavigationAction(
initial.commit09911bf2008-07-26 23:55:291573 WebView* webview,
1574 WebFrame* frame,
[email protected]726985e22009-06-18 21:09:281575 const WebURLRequest& request,
initial.commit09911bf2008-07-26 23:55:291576 WebNavigationType type,
[email protected]4873c7d2009-07-16 06:36:281577 WebNavigationPolicy default_policy,
initial.commit09911bf2008-07-26 23:55:291578 bool is_redirect) {
[email protected]5f450e52009-07-28 13:28:111579 // Webkit is asking whether to navigate to a new URL.
1580 // This is fine normally, except if we're showing UI from one security
1581 // context and they're trying to navigate to a different context.
1582 const GURL& url = request.url();
1583
1584 // If the browser is interested, then give it a chance to look at top level
1585 // navigations
1586 if (renderer_preferences_.browser_handles_top_level_requests &&
1587 // Only send once.
1588 last_top_level_navigation_page_id_ != page_id_ &&
1589 // Not interested in reloads.
1590 type != WebKit::WebNavigationTypeReload &&
[email protected]87d3a2952009-08-10 18:07:371591 type != WebKit::WebNavigationTypeFormSubmitted &&
[email protected]5f450e52009-07-28 13:28:111592 // Must be a top level frame.
[email protected]dd7daa82009-08-10 05:46:451593 frame->parent() == NULL) {
[email protected]5f450e52009-07-28 13:28:111594 // Skip if navigation is on the same page (using '#').
[email protected]dd7daa82009-08-10 05:46:451595 GURL frame_origin = GURL(frame->url()).GetOrigin();
[email protected]5f450e52009-07-28 13:28:111596 if (url.GetOrigin() != frame_origin || url.ref().empty()) {
1597 last_top_level_navigation_page_id_ = page_id_;
1598 OpenURL(webview, url, GURL(), default_policy);
1599 return WebKit::WebNavigationPolicyIgnore; // Suppress the load here.
1600 }
1601 }
1602
[email protected]daa8c58e2009-06-15 17:21:101603 // A content initiated navigation may have originated from a link-click,
1604 // script, drag-n-drop operation, etc.
[email protected]77f17a82009-05-21 04:42:541605 bool is_content_initiated =
[email protected]dd7daa82009-08-10 05:46:451606 NavigationState::FromDataSource(frame->provisionalDataSource())->
[email protected]daa8c58e2009-06-15 17:21:101607 is_content_initiated();
[email protected]77f17a82009-05-21 04:42:541608
initial.commit09911bf2008-07-26 23:55:291609 // We only care about navigations that are within the current tab (as opposed
1610 // to, for example, opening a new window).
1611 // But we sometimes navigate to about:blank to clear a tab, and we want to
1612 // still allow that.
[email protected]4873c7d2009-07-16 06:36:281613 if (default_policy == WebKit::WebNavigationPolicyCurrentTab &&
[email protected]dd7daa82009-08-10 05:46:451614 is_content_initiated && frame->parent() == NULL &&
[email protected]4873c7d2009-07-16 06:36:281615 !url.SchemeIs(chrome::kAboutScheme)) {
[email protected]77f17a82009-05-21 04:42:541616 // When we received such unsolicited navigations, we sometimes want to
1617 // punt them up to the browser to handle.
1618 if (BindingsPolicy::is_dom_ui_enabled(enabled_bindings_) ||
[email protected]1e5f53a2009-06-15 23:48:041619 BindingsPolicy::is_extension_enabled(enabled_bindings_) ||
[email protected]dd7daa82009-08-10 05:46:451620 frame->isViewSourceModeEnabled() ||
[email protected]a2176742009-07-03 12:13:481621 url.SchemeIs(chrome::kViewSourceScheme) ||
1622 url.SchemeIs(chrome::kPrintScheme)) {
[email protected]4873c7d2009-07-16 06:36:281623 OpenURL(webview, url, GURL(), default_policy);
1624 return WebKit::WebNavigationPolicyIgnore; // Suppress the load here.
initial.commit09911bf2008-07-26 23:55:291625 }
1626 }
1627
1628 // Detect when a page is "forking" a new tab that can be safely rendered in
1629 // its own process. This is done by sites like Gmail that try to open links
1630 // in new windows without script connections back to the original page. We
1631 // treat such cases as browser navigations (in which we will create a new
1632 // renderer for a cross-site navigation), rather than WebKit navigations.
1633 //
1634 // We use the following heuristic to decide whether to fork a new page in its
1635 // own process:
1636 // The parent page must open a new tab to about:blank, set the new tab's
1637 // window.opener to null, and then redirect the tab to a cross-site URL using
1638 // JavaScript.
1639 bool is_fork =
1640 // Must start from a tab showing about:blank, which is later redirected.
[email protected]dd7daa82009-08-10 05:46:451641 GURL(frame->url()) == GURL("about:blank") &&
initial.commit09911bf2008-07-26 23:55:291642 // Must be the first real navigation of the tab.
1643 GetHistoryBackListCount() < 1 &&
1644 GetHistoryForwardListCount() < 1 &&
1645 // The parent page must have set the child's window.opener to null before
1646 // redirecting to the desired URL.
[email protected]dd7daa82009-08-10 05:46:451647 frame->opener() == NULL &&
initial.commit09911bf2008-07-26 23:55:291648 // Must be a top-level frame.
[email protected]dd7daa82009-08-10 05:46:451649 frame->parent() == NULL &&
[email protected]77f17a82009-05-21 04:42:541650 // Must not have issued the request from this page.
1651 is_content_initiated &&
initial.commit09911bf2008-07-26 23:55:291652 // Must be targeted at the current tab.
[email protected]4873c7d2009-07-16 06:36:281653 default_policy == WebKit::WebNavigationPolicyCurrentTab &&
initial.commit09911bf2008-07-26 23:55:291654 // Must be a JavaScript navigation, which appears as "other".
[email protected]726985e22009-06-18 21:09:281655 type == WebKit::WebNavigationTypeOther;
initial.commit09911bf2008-07-26 23:55:291656 if (is_fork) {
1657 // Open the URL via the browser, not via WebKit.
[email protected]4873c7d2009-07-16 06:36:281658 OpenURL(webview, url, GURL(), default_policy);
1659 return WebKit::WebNavigationPolicyIgnore;
initial.commit09911bf2008-07-26 23:55:291660 }
1661
[email protected]4873c7d2009-07-16 06:36:281662 return default_policy;
initial.commit09911bf2008-07-26 23:55:291663}
1664
[email protected]a455d3812009-03-05 20:18:071665void RenderView::RunJavaScriptAlert(WebFrame* webframe,
initial.commit09911bf2008-07-26 23:55:291666 const std::wstring& message) {
[email protected]478ff2ed2009-04-21 23:49:181667 RunJavaScriptMessage(MessageBoxFlags::kIsJavascriptAlert,
initial.commit09911bf2008-07-26 23:55:291668 message,
1669 std::wstring(),
[email protected]dd7daa82009-08-10 05:46:451670 webframe->url(),
initial.commit09911bf2008-07-26 23:55:291671 NULL);
1672}
1673
[email protected]a455d3812009-03-05 20:18:071674bool RenderView::RunJavaScriptConfirm(WebFrame* webframe,
initial.commit09911bf2008-07-26 23:55:291675 const std::wstring& message) {
[email protected]478ff2ed2009-04-21 23:49:181676 return RunJavaScriptMessage(MessageBoxFlags::kIsJavascriptConfirm,
initial.commit09911bf2008-07-26 23:55:291677 message,
1678 std::wstring(),
[email protected]dd7daa82009-08-10 05:46:451679 webframe->url(),
initial.commit09911bf2008-07-26 23:55:291680 NULL);
1681}
1682
[email protected]a455d3812009-03-05 20:18:071683bool RenderView::RunJavaScriptPrompt(WebFrame* webframe,
initial.commit09911bf2008-07-26 23:55:291684 const std::wstring& message,
1685 const std::wstring& default_value,
1686 std::wstring* result) {
[email protected]478ff2ed2009-04-21 23:49:181687 return RunJavaScriptMessage(MessageBoxFlags::kIsJavascriptPrompt,
initial.commit09911bf2008-07-26 23:55:291688 message,
1689 default_value,
[email protected]dd7daa82009-08-10 05:46:451690 webframe->url(),
initial.commit09911bf2008-07-26 23:55:291691 result);
1692}
1693
1694bool RenderView::RunJavaScriptMessage(int type,
1695 const std::wstring& message,
1696 const std::wstring& default_value,
[email protected]a455d3812009-03-05 20:18:071697 const GURL& frame_url,
initial.commit09911bf2008-07-26 23:55:291698 std::wstring* result) {
1699 bool success = false;
1700 std::wstring result_temp;
1701 if (!result)
1702 result = &result_temp;
1703 IPC::SyncMessage* msg = new ViewHostMsg_RunJavaScriptMessage(
[email protected]a455d3812009-03-05 20:18:071704 routing_id_, message, default_value, frame_url, type, &success, result);
initial.commit09911bf2008-07-26 23:55:291705
[email protected]1c4947f2009-01-15 22:25:111706 msg->set_pump_messages_event(modal_dialog_event_.get());
initial.commit09911bf2008-07-26 23:55:291707 Send(msg);
1708
1709 return success;
1710}
1711
1712void RenderView::AddGURLSearchProvider(const GURL& osd_url, bool autodetected) {
1713 if (!osd_url.is_empty())
1714 Send(new ViewHostMsg_PageHasOSDD(routing_id_, page_id_, osd_url,
1715 autodetected));
1716}
1717
[email protected]a455d3812009-03-05 20:18:071718bool RenderView::RunBeforeUnloadConfirm(WebFrame* webframe,
initial.commit09911bf2008-07-26 23:55:291719 const std::wstring& message) {
1720 bool success = false;
1721 // This is an ignored return value, but is included so we can accept the same
1722 // response as RunJavaScriptMessage.
1723 std::wstring ignored_result;
1724 IPC::SyncMessage* msg = new ViewHostMsg_RunBeforeUnloadConfirm(
[email protected]dd7daa82009-08-10 05:46:451725 routing_id_, webframe->url(), message, &success, &ignored_result);
initial.commit09911bf2008-07-26 23:55:291726
[email protected]1c4947f2009-01-15 22:25:111727 msg->set_pump_messages_event(modal_dialog_event_.get());
initial.commit09911bf2008-07-26 23:55:291728 Send(msg);
1729
1730 return success;
1731}
1732
[email protected]0ebf3872008-11-07 21:35:031733void RenderView::QueryFormFieldAutofill(const std::wstring& field_name,
1734 const std::wstring& text,
1735 int64 node_id) {
1736 static int message_id_counter = 0;
1737 form_field_autofill_request_id_ = message_id_counter++;
1738 Send(new ViewHostMsg_QueryFormFieldAutofill(routing_id_,
1739 field_name, text,
1740 node_id,
1741 form_field_autofill_request_id_));
1742}
1743
[email protected]4d2b6fb2009-03-20 22:28:171744void RenderView::RemoveStoredAutofillEntry(const std::wstring& name,
1745 const std::wstring& value) {
1746 Send(new ViewHostMsg_RemoveAutofillEntry(routing_id_, name, value));
1747}
1748
[email protected]0ebf3872008-11-07 21:35:031749void RenderView::OnReceivedAutofillSuggestions(
1750 int64 node_id,
1751 int request_id,
[email protected]8d0f15c2008-11-11 01:01:091752 const std::vector<std::wstring>& suggestions,
[email protected]0ebf3872008-11-07 21:35:031753 int default_suggestion_index) {
1754 if (!webview() || request_id != form_field_autofill_request_id_)
1755 return;
1756
1757 webview()->AutofillSuggestionsForNode(node_id, suggestions,
1758 default_suggestion_index);
1759}
1760
[email protected]2c4410d2009-05-06 23:46:221761void RenderView::OnPopupNotificationVisibilityChanged(bool visible) {
[email protected]634a6f92008-12-01 21:39:311762 popup_notification_visible_ = visible;
1763}
1764
initial.commit09911bf2008-07-26 23:55:291765uint32 RenderView::GetCPBrowsingContext() {
1766 uint32 context = 0;
1767 Send(new ViewHostMsg_GetCPBrowsingContext(&context));
1768 return context;
1769}
1770
1771// Tell the browser to display a destination link.
1772void RenderView::UpdateTargetURL(WebView* webview, const GURL& url) {
1773 if (url != target_url_) {
1774 if (target_url_status_ == TARGET_INFLIGHT ||
1775 target_url_status_ == TARGET_PENDING) {
1776 // If we have a request in-flight, save the URL to be sent when we
1777 // receive an ACK to the in-flight request. We can happily overwrite
1778 // any existing pending sends.
1779 pending_target_url_ = url;
1780 target_url_status_ = TARGET_PENDING;
1781 } else {
1782 Send(new ViewHostMsg_UpdateTargetURL(routing_id_, page_id_, url));
1783 target_url_ = url;
1784 target_url_status_ = TARGET_INFLIGHT;
1785 }
1786 }
1787}
1788
[email protected]b62d1a8c2009-01-13 23:54:571789void RenderView::RunFileChooser(bool multi_select,
[email protected]b949f1112009-04-12 20:03:081790 const string16& title,
1791 const FilePath& default_filename,
initial.commit09911bf2008-07-26 23:55:291792 WebFileChooserCallback* file_chooser) {
1793 if (file_chooser_.get()) {
1794 // TODO(brettw): bug 1235154: This should be a synchronous message to deal
1795 // with the fact that web pages can programatically trigger this. With the
1796 // asnychronous messages, we can get an additional call when one is pending,
1797 // which this test is for. For now, we just ignore the additional file
1798 // chooser request. WebKit doesn't do anything to expect the callback, so
1799 // we can just ignore calling it.
1800 delete file_chooser;
1801 return;
1802 }
1803 file_chooser_.reset(file_chooser);
[email protected]b62d1a8c2009-01-13 23:54:571804 Send(new ViewHostMsg_RunFileChooser(routing_id_, multi_select, title,
[email protected]b949f1112009-04-12 20:03:081805 default_filename));
initial.commit09911bf2008-07-26 23:55:291806}
1807
1808void RenderView::AddMessageToConsole(WebView* webview,
1809 const std::wstring& message,
1810 unsigned int line_no,
1811 const std::wstring& source_id) {
1812 Send(new ViewHostMsg_AddMessageToConsole(routing_id_, message,
1813 static_cast<int32>(line_no),
1814 source_id));
1815}
1816
1817void RenderView::AddSearchProvider(const std::string& url) {
1818 AddGURLSearchProvider(GURL(url),
1819 false); // not autodetected
1820}
1821
[email protected]c88a70fe2009-05-05 20:00:221822WebView* RenderView::CreateWebView(WebView* webview,
1823 bool user_gesture,
1824 const GURL& creator_url) {
[email protected]0aa55312008-10-17 21:53:081825 // Check to make sure we aren't overloading on popups.
1826 if (shared_popup_counter_->data > kMaximumNumberOfUnacknowledgedPopups)
1827 return NULL;
1828
[email protected]634a6f92008-12-01 21:39:311829 // This window can't be closed from a window.close() call until we receive a
1830 // message from the Browser process explicitly allowing it.
1831 popup_notification_visible_ = true;
1832
initial.commit09911bf2008-07-26 23:55:291833 int32 routing_id = MSG_ROUTING_NONE;
[email protected]6c8afae52009-01-22 02:24:571834
[email protected]18bcc3c2009-01-27 21:39:151835 ModalDialogEvent modal_dialog_event;
[email protected]6c8afae52009-01-22 02:24:571836 render_thread_->Send(
[email protected]15787f8f2008-10-17 15:29:031837 new ViewHostMsg_CreateWindow(routing_id_, user_gesture, &routing_id,
1838 &modal_dialog_event));
initial.commit09911bf2008-07-26 23:55:291839 if (routing_id == MSG_ROUTING_NONE) {
initial.commit09911bf2008-07-26 23:55:291840 return NULL;
1841 }
1842
1843 // The WebView holds a reference to this new RenderView
[email protected]6c8afae52009-01-22 02:24:571844 base::WaitableEvent* waitable_event = new base::WaitableEvent
1845#if defined(OS_WIN)
[email protected]18bcc3c2009-01-27 21:39:151846 (modal_dialog_event.event);
[email protected]6c8afae52009-01-22 02:24:571847#else
1848 (true, false);
1849#endif
[email protected]81a34412009-01-05 19:17:241850 RenderView* view = RenderView::Create(render_thread_,
[email protected]5a3b9142009-08-28 21:03:171851 NULL, waitable_event, routing_id_,
[email protected]2fab253a2009-08-17 23:00:591852 renderer_preferences_,
1853 webkit_preferences_,
[email protected]80d96fa2009-06-10 22:34:511854 shared_popup_counter_, routing_id);
[email protected]ed4bf2d2009-05-05 00:10:061855 view->opened_by_user_gesture_ = user_gesture;
[email protected]c88a70fe2009-05-05 20:00:221856 view->creator_url_ = creator_url;
initial.commit09911bf2008-07-26 23:55:291857
1858 // Copy over the alternate error page URL so we can have alt error pages in
1859 // the new render view (we don't need the browser to send the URL back down).
1860 view->alternate_error_page_url_ = alternate_error_page_url_;
1861
1862 return view->webview();
1863}
1864
[email protected]0ebf3872008-11-07 21:35:031865WebWidget* RenderView::CreatePopupWidget(WebView* webview,
[email protected]cfd727f2009-01-09 20:21:111866 bool activatable) {
[email protected]8085dbc82008-09-26 22:53:441867 RenderWidget* widget = RenderWidget::Create(routing_id_,
[email protected]81a34412009-01-05 19:17:241868 render_thread_,
[email protected]cfd727f2009-01-09 20:21:111869 activatable);
initial.commit09911bf2008-07-26 23:55:291870 return widget->webwidget();
1871}
1872
[email protected]88efb7ec2009-07-14 16:32:591873WebWidget* RenderView::CreatePopupWidgetWithInfo(WebView* webview,
1874 const WebPopupMenuInfo& info) {
1875 RenderWidget* widget = RenderWidget::Create(routing_id_,
1876 render_thread_,
1877 true);
1878 widget->ConfigureAsExternalPopupMenu(info);
1879 return widget->webwidget();
1880}
1881
[email protected]f103ab72009-09-02 17:10:591882WebKit::WebPlugin* RenderView::CreatePlugin(
1883 WebFrame* frame, const WebKit::WebPluginParams& params) {
1884 return new webkit_glue::WebPluginImpl(frame, params, AsWeakPtr());
initial.commit09911bf2008-07-26 23:55:291885}
1886
[email protected]4e6be3f2009-05-07 02:24:441887WebKit::WebMediaPlayer* RenderView::CreateWebMediaPlayer(
1888 WebKit::WebMediaPlayerClient* client) {
[email protected]add51772009-06-11 18:25:171889 scoped_refptr<media::FilterFactoryCollection> factory =
1890 new media::FilterFactoryCollection();
1891 // Add in any custom filter factories first.
1892 const CommandLine* cmd_line = CommandLine::ForCurrentProcess();
1893 if (!cmd_line->HasSwitch(switches::kDisableAudio)) {
1894 // Add the chrome specific audio renderer.
1895 factory->AddFactory(
1896 AudioRendererImpl::CreateFactory(audio_message_filter()));
1897 }
[email protected]8380c092009-06-25 17:45:511898
1899 // TODO(hclam): obtain the following parameters from |client|.
1900 webkit_glue::MediaResourceLoaderBridgeFactory* bridge_factory =
1901 new webkit_glue::MediaResourceLoaderBridgeFactory(
1902 GURL::EmptyGURL(), // referrer
1903 "null", // frame origin
1904 "null", // main_frame_origin
1905 base::GetCurrentProcId(),
[email protected]f430b5712009-08-21 21:46:311906 appcache::kNoHostId,
[email protected]8380c092009-06-25 17:45:511907 routing_id());
1908
[email protected]add51772009-06-11 18:25:171909 if (!cmd_line->HasSwitch(switches::kSimpleDataSource)) {
1910 // Add the chrome specific media data source.
[email protected]70ab61c92009-06-16 19:29:391911 factory->AddFactory(
[email protected]8e296bbd2009-07-22 21:37:171912 webkit_glue::BufferedDataSource::CreateFactory(MessageLoop::current(),
1913 bridge_factory));
[email protected]8380c092009-06-25 17:45:511914 } else {
1915 factory->AddFactory(
1916 webkit_glue::SimpleDataSource::CreateFactory(MessageLoop::current(),
1917 bridge_factory));
[email protected]add51772009-06-11 18:25:171918 }
1919 return new webkit_glue::WebMediaPlayerImpl(client, factory);
[email protected]ec9212f2008-12-18 21:40:361920}
1921
[email protected]f103ab72009-09-02 17:10:591922void RenderView::OnMissingPluginStatus(
1923 WebPluginDelegateProxy* delegate,
1924 int status) {
[email protected]6c8afae52009-01-22 02:24:571925#if defined(OS_WIN)
[email protected]f103ab72009-09-02 17:10:591926 if (!first_default_plugin_) {
initial.commit09911bf2008-07-26 23:55:291927 // Show the InfoBar for the first available plugin.
1928 if (status == default_plugin::MISSING_PLUGIN_AVAILABLE) {
[email protected]f103ab72009-09-02 17:10:591929 first_default_plugin_ = delegate->AsWeakPtr();
initial.commit09911bf2008-07-26 23:55:291930 Send(new ViewHostMsg_MissingPluginStatus(routing_id_, status));
1931 }
1932 } else {
1933 // Closes the InfoBar if user clicks on the plugin (instead of the InfoBar)
1934 // to start the download/install.
1935 if (status == default_plugin::MISSING_PLUGIN_USER_STARTED_DOWNLOAD) {
1936 Send(new ViewHostMsg_MissingPluginStatus(routing_id_, status));
1937 }
1938 }
[email protected]6c8afae52009-01-22 02:24:571939#else
1940 // TODO(port): plugins current not supported
1941 NOTIMPLEMENTED();
1942#endif
initial.commit09911bf2008-07-26 23:55:291943}
1944
[email protected]eb47a132009-03-04 00:39:561945WebWorker* RenderView::CreateWebWorker(WebWorkerClient* client) {
[email protected]ec775ef2009-05-01 21:20:471946 return new WebWorkerProxy(client, RenderThread::current(), routing_id_);
[email protected]eb47a132009-03-04 00:39:561947}
1948
initial.commit09911bf2008-07-26 23:55:291949void RenderView::OpenURL(WebView* webview, const GURL& url,
[email protected]c0588052008-10-27 23:01:501950 const GURL& referrer,
[email protected]4873c7d2009-07-16 06:36:281951 WebNavigationPolicy policy) {
1952 Send(new ViewHostMsg_OpenURL(
1953 routing_id_, url, referrer, NavigationPolicyToDisposition(policy)));
initial.commit09911bf2008-07-26 23:55:291954}
1955
[email protected]1d522202009-04-04 01:56:421956void RenderView::DidContentsSizeChange(WebWidget* webwidget,
1957 int new_width,
1958 int new_height) {
[email protected]0666aef2009-05-13 19:48:081959 // We don't always want to send the change messages over IPC, only if we've
1960 // be put in that mode by getting a |ViewMsg_EnableIntrinsicWidthChangedMode|
1961 // message.
1962 // TODO(rafaelw): Figure out where the best place to set this for extensions
1963 // is. It isn't clean to test for ExtensionView by examining the
1964 // enabled_bindings. This needs to be generalized as it becomes clear what
1965 // extension toolbars need.
1966 if (BindingsPolicy::is_extension_enabled(enabled_bindings_) ||
1967 send_preferred_width_changes_) {
1968 // WebCore likes to tell us things have changed even when they haven't, so
1969 // cache the width and only send the IPC message when we're sure the
1970 // width is different.
[email protected]dd7daa82009-08-10 05:46:451971 int width = webview()->GetMainFrame()->contentsPreferredWidth();
[email protected]0666aef2009-05-13 19:48:081972 if (width != preferred_width_) {
1973 Send(new ViewHostMsg_DidContentsPreferredWidthChange(routing_id_, width));
1974 preferred_width_ = width;
1975 }
[email protected]1d522202009-04-04 01:56:421976 }
1977}
1978
[email protected]79dbc662009-09-04 05:42:511979// WebKit::WebWidgetClient ----------------------------------------------------
1980
initial.commit09911bf2008-07-26 23:55:291981// We are supposed to get a single call to Show for a newly created RenderView
1982// that was created via RenderView::CreateWebView. So, we wait until this
1983// point to dispatch the ShowView message.
1984//
1985// This method provides us with the information about how to display the newly
1986// created RenderView (i.e., as a constrained popup or as a new tab).
1987//
[email protected]4873c7d2009-07-16 06:36:281988void RenderView::show(WebNavigationPolicy policy) {
initial.commit09911bf2008-07-26 23:55:291989 DCHECK(!did_show_) << "received extraneous Show call";
1990 DCHECK(opener_id_ != MSG_ROUTING_NONE);
1991
1992 if (did_show_)
1993 return;
1994 did_show_ = true;
1995
1996 // NOTE: initial_pos_ may still have its default values at this point, but
1997 // that's okay. It'll be ignored if disposition is not NEW_POPUP, or the
1998 // browser process will impose a default position otherwise.
[email protected]4873c7d2009-07-16 06:36:281999 Send(new ViewHostMsg_ShowView(opener_id_, routing_id_,
2000 NavigationPolicyToDisposition(policy), initial_pos_,
2001 opened_by_user_gesture_, creator_url_));
[email protected]2533ce12009-05-09 00:02:242002 SetPendingWindowRect(initial_pos_);
initial.commit09911bf2008-07-26 23:55:292003}
2004
[email protected]4873c7d2009-07-16 06:36:282005void RenderView::closeWidgetSoon() {
[email protected]2c4410d2009-05-06 23:46:222006 if (!popup_notification_visible_)
[email protected]4873c7d2009-07-16 06:36:282007 RenderWidget::closeWidgetSoon();
[email protected]634a6f92008-12-01 21:39:312008}
2009
[email protected]4873c7d2009-07-16 06:36:282010void RenderView::runModal() {
initial.commit09911bf2008-07-26 23:55:292011 DCHECK(did_show_) << "should already have shown the view";
2012
2013 IPC::SyncMessage* msg = new ViewHostMsg_RunModal(routing_id_);
2014
[email protected]1c4947f2009-01-15 22:25:112015 msg->set_pump_messages_event(modal_dialog_event_.get());
initial.commit09911bf2008-07-26 23:55:292016 Send(msg);
2017}
2018
[email protected]79dbc662009-09-04 05:42:512019// WebKit::WebEditingClient ---------------------------------------------------
2020
2021bool RenderView::shouldBeginEditing(const WebRange& range) {
2022 return true;
2023}
2024
2025bool RenderView::shouldEndEditing(const WebRange& range) {
2026 return true;
2027}
2028
2029bool RenderView::shouldInsertNode(const WebNode& node, const WebRange& range,
2030 WebEditingAction action) {
2031 return true;
2032}
2033
2034bool RenderView::shouldInsertText(const WebString& text, const WebRange& range,
2035 WebEditingAction action) {
2036 return true;
2037}
2038
2039bool RenderView::shouldChangeSelectedRange(const WebRange& from_range,
2040 const WebRange& to_range,
2041 WebTextAffinity affinity,
2042 bool still_selecting) {
2043 return true;
2044}
2045
2046bool RenderView::shouldDeleteRange(const WebRange& range) {
2047 return true;
2048}
2049
2050bool RenderView::shouldApplyStyle(const WebString& style,
2051 const WebRange& range) {
2052 return true;
2053}
2054
2055bool RenderView::isSmartInsertDeleteEnabled() {
2056 return true;
2057}
2058
2059bool RenderView::isSelectTrailingWhitespaceEnabled() {
2060#if defined(OS_WIN)
2061 return true;
2062#else
2063 return false;
2064#endif
2065}
2066
2067void RenderView::setInputMethodEnabled(bool enabled) {
2068 // Save the updated IME status and mark the input focus has been updated.
2069 // The IME status is to be sent to a browser process next time when
2070 // the input caret is rendered.
2071 if (!ime_control_busy_) {
2072 ime_control_updated_ = true;
2073 ime_control_new_state_ = enabled;
2074 }
2075}
2076
2077void RenderView::didChangeSelection(bool is_empty_selection) {
2078#if defined(OS_LINUX)
2079 if (!handling_input_event_)
2080 return;
2081 // TODO(estade): investigate incremental updates to the selection so that we
2082 // don't send the entire selection over IPC every time.
2083 if (!is_empty_selection) {
2084 // Sometimes we get repeated didChangeSelection calls from webkit when
2085 // the selection hasn't actually changed. We don't want to report these
2086 // because it will cause us to continually claim the X clipboard.
2087 const std::string& this_selection =
2088 webview()->GetFocusedFrame()->selectionAsText().utf8();
2089 if (this_selection == last_selection_)
2090 return;
2091
2092 Send(new ViewHostMsg_SelectionChanged(routing_id_,
2093 this_selection));
2094 last_selection_ = this_selection;
2095 } else {
2096 last_selection_.clear();
2097 }
2098#endif
2099}
2100
2101void RenderView::didExecuteCommand(const WebString& command_name) {
2102 const std::wstring& name = UTF16ToWideHack(command_name);
2103 if (StartsWith(name, L"Move", true) ||
2104 StartsWith(name, L"Insert", true) ||
2105 StartsWith(name, L"Delete", true))
2106 return;
2107 UserMetricsRecordAction(name);
2108}
2109
2110// webkit_glue::WebPluginPageDelegate -----------------------------------------
2111
[email protected]f103ab72009-09-02 17:10:592112webkit_glue::WebPluginDelegate* RenderView::CreatePluginDelegate(
2113 const GURL& url,
2114 const std::string& mime_type,
[email protected]f103ab72009-09-02 17:10:592115 std::string* actual_mime_type) {
2116 if (!PluginChannelHost::IsListening())
2117 return NULL;
2118
2119 GURL policy_url;
2120 WebFrame* main_frame = webview()->GetMainFrame();
2121 if (main_frame)
2122 policy_url = main_frame->url();
2123
2124 FilePath path;
[email protected]610c0892009-09-08 19:46:182125 render_thread_->Send(new ViewHostMsg_GetPluginPath(
2126 url, policy_url, mime_type, &path, actual_mime_type));
[email protected]f103ab72009-09-02 17:10:592127 if (path.value().empty())
2128 return NULL;
2129
2130 const std::string* mime_type_to_use;
2131 if (!actual_mime_type->empty())
2132 mime_type_to_use = actual_mime_type;
2133 else
2134 mime_type_to_use = &mime_type;
2135
2136 if (RenderProcess::current()->in_process_plugins()) {
2137#if defined(OS_WIN) // In-proc plugins aren't supported on Linux or Mac.
[email protected]8a3b7962009-09-04 05:53:232138 return WebPluginDelegateImpl::Create(
[email protected]f103ab72009-09-02 17:10:592139 path, *mime_type_to_use, gfx::NativeViewFromId(host_window_));
2140#else
2141 NOTIMPLEMENTED();
2142 return NULL;
2143#endif
2144 }
2145
[email protected]610c0892009-09-08 19:46:182146 return new WebPluginDelegateProxy(*mime_type_to_use, AsWeakPtr());
[email protected]f103ab72009-09-02 17:10:592147}
2148
2149void RenderView::CreatedPluginWindow(gfx::PluginWindowHandle window) {
2150#if defined(OS_LINUX)
2151 RenderThread::current()->Send(new ViewHostMsg_CreatePluginContainer(
2152 routing_id(), window));
2153#endif
2154}
2155
2156void RenderView::WillDestroyPluginWindow(gfx::PluginWindowHandle window) {
2157#if defined(OS_LINUX)
2158 RenderThread::current()->Send(new ViewHostMsg_DestroyPluginContainer(
2159 routing_id(), window));
2160#endif
2161 CleanupWindowInPluginMoves(window);
2162}
2163
2164void RenderView::DidMovePlugin(const webkit_glue::WebPluginGeometry& move) {
2165 SchedulePluginMove(move);
2166}
2167
2168void RenderView::DidStartLoadingForPlugin() {
2169 // TODO(darin): Make is_loading_ be a counter!
2170 DidStartLoading(webview());
2171}
2172
2173void RenderView::DidStopLoadingForPlugin() {
2174 // TODO(darin): Make is_loading_ be a counter!
2175 DidStopLoading(webview());
2176}
2177
2178void RenderView::ShowModalHTMLDialogForPlugin(
2179 const GURL& url,
2180 const gfx::Size& size,
2181 const std::string& json_arguments,
2182 std::string* json_retval) {
2183 IPC::SyncMessage* msg = new ViewHostMsg_ShowModalHTMLDialog(
2184 routing_id_, url, size.width(), size.height(), json_arguments,
2185 json_retval);
2186
2187 msg->set_pump_messages_event(modal_dialog_event_.get());
2188 Send(msg);
2189}
2190
initial.commit09911bf2008-07-26 23:55:292191void RenderView::SyncNavigationState() {
2192 if (!webview())
2193 return;
2194
[email protected]dd7daa82009-08-10 05:46:452195 const WebHistoryItem& item = webview()->GetMainFrame()->currentHistoryItem();
[email protected]ca948a22009-06-25 19:36:172196 if (item.isNull())
initial.commit09911bf2008-07-26 23:55:292197 return;
[email protected]ca948a22009-06-25 19:36:172198
2199 Send(new ViewHostMsg_UpdateState(
2200 routing_id_, page_id_, webkit_glue::HistoryItemToString(item)));
initial.commit09911bf2008-07-26 23:55:292201}
2202
2203void RenderView::ShowContextMenu(WebView* webview,
[email protected]581b87eb2009-07-23 23:06:562204 ContextNodeType node_type,
initial.commit09911bf2008-07-26 23:55:292205 int x,
2206 int y,
2207 const GURL& link_url,
[email protected]574a1d62009-07-17 03:23:462208 const GURL& src_url,
initial.commit09911bf2008-07-26 23:55:292209 const GURL& page_url,
2210 const GURL& frame_url,
[email protected]574a1d62009-07-17 03:23:462211 const ContextMenuMediaParams& media_params,
initial.commit09911bf2008-07-26 23:55:292212 const std::wstring& selection_text,
2213 const std::wstring& misspelled_word,
[email protected]6aa376b2008-09-23 18:49:522214 int edit_flags,
[email protected]c9825a42009-05-01 22:51:502215 const std::string& security_info,
2216 const std::string& frame_charset) {
[email protected]e09ba552009-02-05 03:26:292217 ContextMenuParams params;
[email protected]581b87eb2009-07-23 23:06:562218 params.node_type = node_type;
initial.commit09911bf2008-07-26 23:55:292219 params.x = x;
2220 params.y = y;
[email protected]574a1d62009-07-17 03:23:462221 params.src_url = src_url;
initial.commit09911bf2008-07-26 23:55:292222 params.link_url = link_url;
[email protected]e6c79812009-04-22 22:31:422223 params.unfiltered_link_url = link_url;
initial.commit09911bf2008-07-26 23:55:292224 params.page_url = page_url;
2225 params.frame_url = frame_url;
[email protected]574a1d62009-07-17 03:23:462226 params.media_params = media_params;
initial.commit09911bf2008-07-26 23:55:292227 params.selection_text = selection_text;
2228 params.misspelled_word = misspelled_word;
[email protected]be645db2009-02-06 20:36:332229 params.spellcheck_enabled =
[email protected]dd7daa82009-08-10 05:46:452230 webview->GetFocusedFrame()->isContinuousSpellCheckingEnabled();
initial.commit09911bf2008-07-26 23:55:292231 params.edit_flags = edit_flags;
[email protected]6aa376b2008-09-23 18:49:522232 params.security_info = security_info;
[email protected]c9825a42009-05-01 22:51:502233 params.frame_charset = frame_charset;
initial.commit09911bf2008-07-26 23:55:292234 Send(new ViewHostMsg_ContextMenu(routing_id_, params));
2235}
2236
[email protected]e80c73b2009-04-07 23:24:582237void RenderView::StartDragging(WebView* webview,
[email protected]1d9f4132009-09-08 17:29:252238 const WebKit::WebPoint &mouseCoords,
2239 const WebDragData& drag_data,
2240 WebDragOperationsMask allowed_ops) {
2241 Send(new ViewHostMsg_StartDragging(routing_id_,
2242 WebDropData(drag_data),
2243 allowed_ops));
initial.commit09911bf2008-07-26 23:55:292244}
2245
2246void RenderView::TakeFocus(WebView* webview, bool reverse) {
2247 Send(new ViewHostMsg_TakeFocus(routing_id_, reverse));
2248}
2249
2250void RenderView::DidDownloadImage(int id,
2251 const GURL& image_url,
2252 bool errored,
2253 const SkBitmap& image) {
[email protected]bf5c2ff392009-07-08 16:24:332254 Send(new ViewHostMsg_DidDownloadFavIcon(routing_id_, id, image_url, errored,
2255 image));
initial.commit09911bf2008-07-26 23:55:292256}
2257
[email protected]bf5c2ff392009-07-08 16:24:332258void RenderView::OnDownloadFavIcon(int id,
2259 const GURL& image_url,
2260 int image_size) {
[email protected]f11ca0732009-04-11 00:09:342261 bool data_image_failed = false;
2262 if (image_url.SchemeIs("data")) {
2263 SkBitmap data_image = ImageFromDataUrl(image_url);
2264 data_image_failed = data_image.empty();
2265 if (!data_image_failed) {
[email protected]bf5c2ff392009-07-08 16:24:332266 Send(new ViewHostMsg_DidDownloadFavIcon(routing_id_, id, image_url, false,
2267 data_image));
[email protected]f11ca0732009-04-11 00:09:342268 }
2269 }
2270
[email protected]bf5c2ff392009-07-08 16:24:332271 if (data_image_failed ||
2272 !webview()->DownloadImage(id, image_url, image_size)) {
2273 Send(new ViewHostMsg_DidDownloadFavIcon(routing_id_, id, image_url, true,
2274 SkBitmap()));
2275 }
initial.commit09911bf2008-07-26 23:55:292276}
2277
[email protected]f11ca0732009-04-11 00:09:342278SkBitmap RenderView::ImageFromDataUrl(const GURL& url) const {
2279 std::string mime_type, char_set, data;
2280 if (net::DataURL::Parse(url, &mime_type, &char_set, &data) && !data.empty()) {
2281 // Decode the favicon using WebKit's image decoder.
2282 webkit_glue::ImageDecoder decoder(gfx::Size(kFavIconSize, kFavIconSize));
2283 const unsigned char* src_data =
2284 reinterpret_cast<const unsigned char*>(&data[0]);
2285
2286 return decoder.Decode(src_data, data.size());
2287 }
2288 return SkBitmap();
2289}
2290
initial.commit09911bf2008-07-26 23:55:292291void RenderView::OnGetApplicationInfo(int page_id) {
2292 webkit_glue::WebApplicationInfo app_info;
2293 if (page_id == page_id_)
2294 webkit_glue::GetApplicationInfo(webview(), &app_info);
2295
2296 // Prune out any data URLs in the set of icons. The browser process expects
2297 // any icon with a data URL to have originated from a favicon. We don't want
2298 // to decode arbitrary data URLs in the browser process. See
2299 // http://b/issue?id=1162972
2300 for (size_t i = 0; i < app_info.icons.size(); ++i) {
[email protected]6de74452009-02-25 18:04:592301 if (app_info.icons[i].url.SchemeIs(chrome::kDataScheme)) {
initial.commit09911bf2008-07-26 23:55:292302 app_info.icons.erase(app_info.icons.begin() + i);
2303 --i;
2304 }
2305 }
2306
2307 Send(new ViewHostMsg_DidGetApplicationInfo(routing_id_, page_id, app_info));
2308}
2309
[email protected]7ccddb8c2009-08-04 17:36:552310GURL RenderView::GetAlternateErrorPageURL(const GURL& failed_url,
initial.commit09911bf2008-07-26 23:55:292311 ErrorPageType error_type) {
[email protected]7ccddb8c2009-08-04 17:36:552312 if (failed_url.SchemeIsSecure()) {
initial.commit09911bf2008-07-26 23:55:292313 // If the URL that failed was secure, then the embedding web page was not
2314 // expecting a network attacker to be able to manipulate its contents. As
2315 // we fetch alternate error pages over HTTP, we would be allowing a network
2316 // attacker to manipulate the contents of the response if we tried to use
2317 // the link doctor here.
2318 return GURL::EmptyGURL();
2319 }
2320
2321 // Grab the base URL from the browser process.
2322 if (!alternate_error_page_url_.is_valid())
2323 return GURL::EmptyGURL();
2324
2325 // Strip query params from the failed URL.
2326 GURL::Replacements remove_params;
2327 remove_params.ClearUsername();
2328 remove_params.ClearPassword();
2329 remove_params.ClearQuery();
2330 remove_params.ClearRef();
[email protected]7ccddb8c2009-08-04 17:36:552331 const GURL url_to_send = failed_url.ReplaceComponents(remove_params);
initial.commit09911bf2008-07-26 23:55:292332
2333 // Construct the query params to send to link doctor.
2334 std::string params(alternate_error_page_url_.query());
2335 params.append("&url=");
2336 params.append(EscapeQueryParamValue(url_to_send.spec()));
2337 params.append("&sourceid=chrome");
2338 params.append("&error=");
2339 switch (error_type) {
2340 case DNS_ERROR:
2341 params.append("dnserror");
2342 break;
2343
2344 case HTTP_404:
2345 params.append("http404");
2346 break;
2347
[email protected]5df266ac2008-10-15 19:50:132348 case CONNECTION_ERROR:
[email protected]e1f934b2009-01-26 20:41:332349 params.append("connectionfailure");
[email protected]5df266ac2008-10-15 19:50:132350 break;
2351
initial.commit09911bf2008-07-26 23:55:292352 default:
2353 NOTREACHED() << "unknown ErrorPageType";
2354 }
2355
2356 // OK, build the final url to return.
2357 GURL::Replacements link_doctor_params;
2358 link_doctor_params.SetQueryStr(params);
2359 GURL url = alternate_error_page_url_.ReplaceComponents(link_doctor_params);
2360 return url;
2361}
2362
[email protected]7ea066a2009-04-06 20:21:592363void RenderView::OnFind(int request_id,
2364 const string16& search_text,
2365 const WebKit::WebFindOptions& options) {
initial.commit09911bf2008-07-26 23:55:292366 WebFrame* main_frame = webview()->GetMainFrame();
2367 WebFrame* frame_after_main = webview()->GetNextFrameAfter(main_frame, true);
2368 WebFrame* focused_frame = webview()->GetFocusedFrame();
2369 WebFrame* search_frame = focused_frame; // start searching focused frame.
2370
2371 bool multi_frame = (frame_after_main != main_frame);
2372
2373 // If we have multiple frames, we don't want to wrap the search within the
2374 // frame, so we check here if we only have main_frame in the chain.
2375 bool wrap_within_frame = !multi_frame;
2376
[email protected]b3f2b912009-04-09 16:18:522377 WebRect selection_rect;
initial.commit09911bf2008-07-26 23:55:292378 bool result = false;
2379
2380 do {
[email protected]dd7daa82009-08-10 05:46:452381 result = search_frame->find(
[email protected]7ea066a2009-04-06 20:21:592382 request_id, search_text, options, wrap_within_frame, &selection_rect);
initial.commit09911bf2008-07-26 23:55:292383
2384 if (!result) {
2385 // don't leave text selected as you move to the next frame.
[email protected]a100d76bb2009-08-14 17:50:222386 search_frame->executeCommand(WebString::fromUTF8("Unselect"));
initial.commit09911bf2008-07-26 23:55:292387
2388 // Find the next frame, but skip the invisible ones.
2389 do {
2390 // What is the next frame to search? (we might be going backwards). Note
2391 // that we specify wrap=true so that search_frame never becomes NULL.
[email protected]7ea066a2009-04-06 20:21:592392 search_frame = options.forward ?
initial.commit09911bf2008-07-26 23:55:292393 webview()->GetNextFrameAfter(search_frame, true) :
2394 webview()->GetPreviousFrameBefore(search_frame, true);
[email protected]dd7daa82009-08-10 05:46:452395 } while (!search_frame->hasVisibleContent() &&
2396 search_frame != focused_frame);
initial.commit09911bf2008-07-26 23:55:292397
[email protected]884db412008-11-24 23:46:502398 // Make sure selection doesn't affect the search operation in new frame.
[email protected]a100d76bb2009-08-14 17:50:222399 search_frame->executeCommand(WebString::fromUTF8("Unselect"));
initial.commit09911bf2008-07-26 23:55:292400
2401 // If we have multiple frames and we have wrapped back around to the
2402 // focused frame, we need to search it once more allowing wrap within
2403 // the frame, otherwise it will report 'no match' if the focused frame has
2404 // reported matches, but no frames after the focused_frame contain a
2405 // match for the search word(s).
2406 if (multi_frame && search_frame == focused_frame) {
[email protected]dd7daa82009-08-10 05:46:452407 result = search_frame->find(
[email protected]7ea066a2009-04-06 20:21:592408 request_id, search_text, options, true, // Force wrapping.
2409 &selection_rect);
initial.commit09911bf2008-07-26 23:55:292410 }
2411 }
2412
initial.commit09911bf2008-07-26 23:55:292413 webview()->SetFocusedFrame(search_frame);
2414 } while (!result && search_frame != focused_frame);
2415
[email protected]7ea066a2009-04-06 20:21:592416 if (options.findNext) {
[email protected]4f3dc372009-02-24 00:10:292417 // Force the main_frame to report the actual count.
[email protected]dd7daa82009-08-10 05:46:452418 main_frame->increaseMatchCount(0, request_id);
[email protected]4f3dc372009-02-24 00:10:292419 } else {
2420 // If nothing is found, set result to "0 of 0", otherwise, set it to
2421 // "-1 of 1" to indicate that we found at least one item, but we don't know
2422 // yet what is active.
2423 int ordinal = result ? -1 : 0; // -1 here means, we might know more later.
2424 int match_count = result ? 1 : 0; // 1 here means possibly more coming.
initial.commit09911bf2008-07-26 23:55:292425
[email protected]4f3dc372009-02-24 00:10:292426 // If we find no matches then this will be our last status update.
2427 // Otherwise the scoping effort will send more results.
2428 bool final_status_update = !result;
initial.commit09911bf2008-07-26 23:55:292429
[email protected]4f3dc372009-02-24 00:10:292430 // Send the search result over to the browser process.
[email protected]4f999132009-03-31 18:08:402431 Send(new ViewHostMsg_Find_Reply(routing_id_,
[email protected]7ea066a2009-04-06 20:21:592432 request_id,
[email protected]4f3dc372009-02-24 00:10:292433 match_count,
2434 selection_rect,
2435 ordinal,
2436 final_status_update));
initial.commit09911bf2008-07-26 23:55:292437
initial.commit09911bf2008-07-26 23:55:292438 // Scoping effort begins, starting with the mainframe.
2439 search_frame = main_frame;
2440
[email protected]dd7daa82009-08-10 05:46:452441 main_frame->resetMatchCount();
initial.commit09911bf2008-07-26 23:55:292442
2443 do {
2444 // Cancel all old scoping requests before starting a new one.
[email protected]dd7daa82009-08-10 05:46:452445 search_frame->cancelPendingScopingEffort();
initial.commit09911bf2008-07-26 23:55:292446
2447 // We don't start another scoping effort unless at least one match has
2448 // been found.
2449 if (result) {
2450 // Start new scoping request. If the scoping function determines that it
2451 // needs to scope, it will defer until later.
[email protected]dd7daa82009-08-10 05:46:452452 search_frame->scopeStringMatches(request_id,
[email protected]7ea066a2009-04-06 20:21:592453 search_text,
2454 options,
initial.commit09911bf2008-07-26 23:55:292455 true); // reset the tickmarks
2456 }
2457
2458 // Iterate to the next frame. The frame will not necessarily scope, for
2459 // example if it is not visible.
2460 search_frame = webview()->GetNextFrameAfter(search_frame, true);
2461 } while (search_frame != main_frame);
2462 }
2463}
2464
[email protected]5c4266922009-07-10 16:41:272465void RenderView::OnDeterminePageText() {
2466 if (!is_loading_) {
2467 if (!webview())
2468 return;
2469 WebFrame* main_frame = webview()->GetMainFrame();
2470 std::wstring contents;
2471 CaptureText(main_frame, &contents);
2472 Send(new ViewMsg_DeterminePageText_Reply(routing_id_, contents));
2473 determine_page_text_after_loading_stops_ = false;
2474 return;
2475 }
2476
2477 // We set |determine_page_text_after_loading_stops_| true here so that,
2478 // after page has been loaded completely, the text in the page is captured.
2479 determine_page_text_after_loading_stops_ = true;
2480}
2481
initial.commit09911bf2008-07-26 23:55:292482void RenderView::ReportFindInPageMatchCount(int count, int request_id,
2483 bool final_update) {
2484 // If we have a message that has been queued up, then we should just replace
2485 // it. The ACK from the browser will make sure it gets sent when the browser
2486 // wants it.
2487 if (queued_find_reply_message_.get()) {
2488 IPC::Message* msg = new ViewHostMsg_Find_Reply(
2489 routing_id_,
2490 request_id,
2491 count,
[email protected]b3f2b912009-04-09 16:18:522492 gfx::Rect(),
initial.commit09911bf2008-07-26 23:55:292493 -1, // Don't update active match ordinal.
2494 final_update);
2495 queued_find_reply_message_.reset(msg);
2496 } else {
2497 // Send the search result over to the browser process.
2498 Send(new ViewHostMsg_Find_Reply(
2499 routing_id_,
2500 request_id,
2501 count,
[email protected]b3f2b912009-04-09 16:18:522502 gfx::Rect(),
initial.commit09911bf2008-07-26 23:55:292503 -1, // // Don't update active match ordinal.
2504 final_update));
2505 }
2506}
2507
2508void RenderView::ReportFindInPageSelection(int request_id,
2509 int active_match_ordinal,
[email protected]b3f2b912009-04-09 16:18:522510 const WebRect& selection_rect) {
initial.commit09911bf2008-07-26 23:55:292511 // Send the search result over to the browser process.
2512 Send(new ViewHostMsg_Find_Reply(routing_id_,
2513 request_id,
2514 -1,
2515 selection_rect,
2516 active_match_ordinal,
2517 false));
2518}
2519
[email protected]ed4bf2d2009-05-05 00:10:062520bool RenderView::WasOpenedByUserGesture() const {
initial.commit09911bf2008-07-26 23:55:292521 return opened_by_user_gesture_;
2522}
2523
[email protected]7f40fc5b2009-06-12 19:23:082524void RenderView::SpellCheck(const std::wstring& word, int* misspell_location,
2525 int* misspell_length) {
2526 Send(new ViewHostMsg_SpellCheck(routing_id_, word, misspell_location,
2527 misspell_length));
initial.commit09911bf2008-07-26 23:55:292528}
2529
[email protected]26ea6c42009-06-10 22:32:212530std::wstring RenderView::GetAutoCorrectWord(
2531 const std::wstring& misspelled_word) {
2532 std::wstring autocorrect_word;
[email protected]eda2b5a2009-05-12 19:30:212533 const CommandLine& command_line = *CommandLine::ForCurrentProcess();
2534 if (command_line.HasSwitch(switches::kAutoSpellCorrect)) {
2535 Send(new ViewHostMsg_GetAutoCorrectWord(routing_id_, misspelled_word,
2536 &autocorrect_word));
2537 }
[email protected]26ea6c42009-06-10 22:32:212538
2539 return autocorrect_word;
[email protected]eda2b5a2009-05-12 19:30:212540}
2541
initial.commit09911bf2008-07-26 23:55:292542void RenderView::ScriptedPrint(WebFrame* frame) {
[email protected]aa82249f2009-07-16 17:23:582543 DCHECK(webview());
2544 if (webview()) {
2545 // Print the full page - not just the frame the javascript is running from.
2546 Print(webview()->GetMainFrame(), true);
2547 }
initial.commit09911bf2008-07-26 23:55:292548}
2549
initial.commit09911bf2008-07-26 23:55:292550void RenderView::UserMetricsRecordAction(const std::wstring& action) {
2551 Send(new ViewHostMsg_UserMetricsRecordAction(routing_id_, action));
2552}
2553
2554void RenderView::DnsPrefetch(const std::vector<std::string>& host_names) {
2555 Send(new ViewHostMsg_DnsPrefetch(host_names));
2556}
2557
[email protected]630e26b2008-10-14 22:55:172558void RenderView::OnZoom(int function) {
2559 static const bool kZoomIsTextOnly = false;
2560 switch (function) {
2561 case PageZoom::SMALLER:
2562 webview()->ZoomOut(kZoomIsTextOnly);
initial.commit09911bf2008-07-26 23:55:292563 break;
[email protected]630e26b2008-10-14 22:55:172564 case PageZoom::STANDARD:
2565 webview()->ResetZoom();
initial.commit09911bf2008-07-26 23:55:292566 break;
[email protected]630e26b2008-10-14 22:55:172567 case PageZoom::LARGER:
2568 webview()->ZoomIn(kZoomIsTextOnly);
initial.commit09911bf2008-07-26 23:55:292569 break;
2570 default:
2571 NOTREACHED();
2572 }
2573}
2574
[email protected]ea8c7452009-04-02 20:47:062575void RenderView::OnInsertText(const string16& text) {
[email protected]5f9e0b82009-05-08 22:13:392576 WebFrame* frame = webview()->GetFocusedFrame();
2577 if (!frame)
2578 return;
[email protected]dd7daa82009-08-10 05:46:452579 frame->insertText(text);
[email protected]ea8c7452009-04-02 20:47:062580}
2581
[email protected]41fc0322009-09-04 22:23:402582void RenderView::OnSetPageEncoding(const std::string& encoding_name) {
initial.commit09911bf2008-07-26 23:55:292583 webview()->SetPageEncoding(encoding_name);
2584}
2585
[email protected]f6e59a62009-05-13 21:12:032586void RenderView::NavigateBackForwardSoon(int offset) {
[email protected]f46aff62008-10-16 07:58:052587 history_back_list_count_ += offset;
2588 history_forward_list_count_ -= offset;
2589
initial.commit09911bf2008-07-26 23:55:292590 Send(new ViewHostMsg_GoToEntryAtOffset(routing_id_, offset));
2591}
2592
2593int RenderView::GetHistoryBackListCount() {
2594 return history_back_list_count_;
2595}
2596
2597int RenderView::GetHistoryForwardListCount() {
2598 return history_forward_list_count_;
2599}
2600
2601void RenderView::OnNavStateChanged(WebView* webview) {
[email protected]81a34412009-01-05 19:17:242602 if (!nav_state_sync_timer_.IsRunning()) {
2603 nav_state_sync_timer_.Start(
2604 TimeDelta::FromSeconds(delay_seconds_for_form_state_sync_), this,
2605 &RenderView::SyncNavigationState);
2606 }
initial.commit09911bf2008-07-26 23:55:292607}
2608
2609void RenderView::SetTooltipText(WebView* webview,
[email protected]de570ef2009-07-29 18:27:522610 const std::wstring& tooltip_text,
2611 WebTextDirection text_direction_hint) {
2612 Send(new ViewHostMsg_SetTooltipText(routing_id_, tooltip_text,
2613 text_direction_hint));
initial.commit09911bf2008-07-26 23:55:292614}
2615
2616void RenderView::DownloadUrl(const GURL& url, const GURL& referrer) {
2617 Send(new ViewHostMsg_DownloadUrl(routing_id_, url, referrer));
2618}
2619
[email protected]0df30122009-06-03 12:13:082620void RenderView::UpdateInspectorSettings(const std::wstring& raw_settings) {
2621 Send(new ViewHostMsg_UpdateInspectorSettings(routing_id_, raw_settings));
2622}
2623
[email protected]611cad42009-03-16 18:51:342624WebDevToolsAgentDelegate* RenderView::GetWebDevToolsAgentDelegate() {
[email protected]b75b7d072009-04-06 13:47:002625 return devtools_agent_.get();
[email protected]611cad42009-03-16 18:51:342626}
2627
[email protected]ea8c7452009-04-02 20:47:062628void RenderView::PasteFromSelectionClipboard() {
2629 Send(new ViewHostMsg_PasteFromSelectionClipboard(routing_id_));
2630}
2631
[email protected]dd7daa82009-08-10 05:46:452632WebFrame* RenderView::GetChildFrame(const std::wstring& xpath) const {
2633 if (xpath.empty())
2634 return webview()->GetMainFrame();
2635
2636 // xpath string can represent a frame deep down the tree (across multiple
2637 // frame DOMs).
2638 // Example, /html/body/table/tbody/tr/td/iframe\n/frameset/frame[0]
2639 // should break into 2 xpaths
2640 // /html/body/table/tbody/tr/td/iframe & /frameset/frame[0]
2641
2642 WebFrame* frame = webview()->GetMainFrame();
2643
2644 std::wstring xpath_remaining = xpath;
2645 while (!xpath_remaining.empty()) {
2646 std::wstring::size_type delim_pos = xpath_remaining.find_first_of(L'\n');
2647 std::wstring xpath_child;
2648 if (delim_pos != std::wstring::npos) {
2649 xpath_child = xpath_remaining.substr(0, delim_pos);
2650 xpath_remaining.erase(0, delim_pos + 1);
2651 } else {
2652 xpath_remaining.swap(xpath_child);
2653 }
2654 frame = frame->findChildByExpression(WideToUTF16Hack(xpath_child));
initial.commit09911bf2008-07-26 23:55:292655 }
2656
[email protected]dd7daa82009-08-10 05:46:452657 return frame;
initial.commit09911bf2008-07-26 23:55:292658}
2659
[email protected]f29acf52008-11-03 20:08:332660void RenderView::EvaluateScript(const std::wstring& frame_xpath,
2661 const std::wstring& script) {
initial.commit09911bf2008-07-26 23:55:292662 WebFrame* web_frame = GetChildFrame(frame_xpath);
2663 if (!web_frame)
2664 return;
2665
[email protected]dd7daa82009-08-10 05:46:452666 web_frame->executeScript(WebScriptSource(WideToUTF16Hack(script)));
initial.commit09911bf2008-07-26 23:55:292667}
2668
[email protected]1810e132009-03-24 23:35:482669void RenderView::InsertCSS(const std::wstring& frame_xpath,
2670 const std::string& css) {
2671 WebFrame* web_frame = GetChildFrame(frame_xpath);
2672 if (!web_frame)
2673 return;
2674
[email protected]dd7daa82009-08-10 05:46:452675 web_frame->insertStyleText(WebString::fromUTF8(css));
[email protected]1810e132009-03-24 23:35:482676}
2677
initial.commit09911bf2008-07-26 23:55:292678void RenderView::OnScriptEvalRequest(const std::wstring& frame_xpath,
2679 const std::wstring& jscript) {
[email protected]f29acf52008-11-03 20:08:332680 EvaluateScript(frame_xpath, jscript);
initial.commit09911bf2008-07-26 23:55:292681}
2682
[email protected]1810e132009-03-24 23:35:482683void RenderView::OnCSSInsertRequest(const std::wstring& frame_xpath,
2684 const std::string& css) {
2685 InsertCSS(frame_xpath, css);
[email protected]ae461542009-06-19 19:03:412686
2687 // Notify RenderViewHost that css has been inserted into the frame.
2688 Send(new ViewHostMsg_OnCSSInserted(routing_id_));
[email protected]1810e132009-03-24 23:35:482689}
2690
[email protected]7ea066a2009-04-06 20:21:592691void RenderView::OnAddMessageToConsole(
2692 const string16& frame_xpath,
2693 const string16& message,
2694 const WebConsoleMessage::Level& level) {
2695 WebFrame* web_frame = GetChildFrame(UTF16ToWideHack(frame_xpath));
[email protected]0dea3ea2009-03-31 23:30:592696 if (web_frame)
[email protected]dd7daa82009-08-10 05:46:452697 web_frame->addMessageToConsole(WebConsoleMessage(level, message));
initial.commit09911bf2008-07-26 23:55:292698}
2699
[email protected]81e63782009-02-27 19:35:092700void RenderView::OnAllowBindings(int enabled_bindings_flags) {
2701 enabled_bindings_ |= enabled_bindings_flags;
initial.commit09911bf2008-07-26 23:55:292702}
2703
2704void RenderView::OnSetDOMUIProperty(const std::string& name,
2705 const std::string& value) {
[email protected]81e63782009-02-27 19:35:092706 DCHECK(BindingsPolicy::is_dom_ui_enabled(enabled_bindings_));
initial.commit09911bf2008-07-26 23:55:292707 dom_ui_bindings_.SetProperty(name, value);
2708}
2709
2710void RenderView::OnReservePageIDRange(int size_of_range) {
2711 next_page_id_ += size_of_range + 1;
2712}
2713
[email protected]e80c73b2009-04-07 23:24:582714void RenderView::OnDragSourceEndedOrMoved(const gfx::Point& client_point,
2715 const gfx::Point& screen_point,
[email protected]1d9f4132009-09-08 17:29:252716 bool ended,
2717 WebDragOperation op) {
[email protected]5f9ae6c2009-07-08 02:38:032718 if (ended) {
[email protected]1d9f4132009-09-08 17:29:252719 webview()->DragSourceEndedAt(client_point, screen_point, op);
[email protected]5f9ae6c2009-07-08 02:38:032720 } else {
[email protected]e80c73b2009-04-07 23:24:582721 webview()->DragSourceMovedTo(client_point, screen_point);
[email protected]5f9ae6c2009-07-08 02:38:032722 }
initial.commit09911bf2008-07-26 23:55:292723}
2724
2725void RenderView::OnDragSourceSystemDragEnded() {
2726 webview()->DragSourceSystemDragEnded();
2727}
2728
2729void RenderView::OnUploadFileRequest(const ViewMsg_UploadFile_Params& p) {
2730 webkit_glue::FileUploadData* f = new webkit_glue::FileUploadData;
2731 f->file_path = p.file_path;
2732 f->form_name = p.form;
2733 f->file_name = p.file;
2734 f->submit_name = p.submit;
2735
2736 // Build the other form values map.
2737 if (!p.other_values.empty()) {
2738 std::vector<std::wstring> e;
2739 std::vector<std::wstring> kvp;
2740 std::vector<std::wstring>::iterator i;
2741
2742 SplitString(p.other_values, L'\n', &e);
2743 for (i = e.begin(); i != e.end(); ++i) {
2744 SplitString(*i, L'=', &kvp);
2745 if (kvp.size() == 2)
2746 f->other_form_values[kvp[0]] = kvp[1];
2747 kvp.clear();
2748 }
2749 }
2750
2751 pending_upload_data_.reset(f);
2752 ProcessPendingUpload();
2753}
2754
2755void RenderView::ProcessPendingUpload() {
2756 webkit_glue::FileUploadData* f = pending_upload_data_.get();
2757 if (f && webview() && webkit_glue::FillFormToUploadFile(webview(), *f))
2758 ResetPendingUpload();
2759}
2760
2761void RenderView::ResetPendingUpload() {
2762 pending_upload_data_.reset();
2763}
2764
2765void RenderView::OnFormFill(const FormData& form) {
2766 webkit_glue::FillForm(this->webview(), form);
2767}
2768
2769void RenderView::OnFillPasswordForm(
[email protected]daa8c58e2009-06-15 17:21:102770 const webkit_glue::PasswordFormDomManager::FillData& form_data) {
initial.commit09911bf2008-07-26 23:55:292771 webkit_glue::FillPasswordForm(this->webview(), form_data);
2772}
2773
2774void RenderView::OnDragTargetDragEnter(const WebDropData& drop_data,
[email protected]e80c73b2009-04-07 23:24:582775 const gfx::Point& client_point,
[email protected]1d9f4132009-09-08 17:29:252776 const gfx::Point& screen_point,
2777 WebDragOperationsMask ops) {
2778 WebDragOperation operation = webview()->DragTargetDragEnter(
[email protected]e80c73b2009-04-07 23:24:582779 drop_data.ToDragData(),
2780 drop_data.identity,
2781 client_point,
[email protected]1d9f4132009-09-08 17:29:252782 screen_point,
2783 ops);
initial.commit09911bf2008-07-26 23:55:292784
[email protected]1d9f4132009-09-08 17:29:252785 Send(new ViewHostMsg_UpdateDragCursor(routing_id_, operation));
initial.commit09911bf2008-07-26 23:55:292786}
2787
[email protected]e80c73b2009-04-07 23:24:582788void RenderView::OnDragTargetDragOver(const gfx::Point& client_point,
[email protected]1d9f4132009-09-08 17:29:252789 const gfx::Point& screen_point,
2790 WebDragOperationsMask ops) {
2791 WebDragOperation operation = webview()->DragTargetDragOver(
2792 client_point,
2793 screen_point,
2794 ops);
initial.commit09911bf2008-07-26 23:55:292795
[email protected]1d9f4132009-09-08 17:29:252796 Send(new ViewHostMsg_UpdateDragCursor(routing_id_, operation));
initial.commit09911bf2008-07-26 23:55:292797}
2798
2799void RenderView::OnDragTargetDragLeave() {
2800 webview()->DragTargetDragLeave();
2801}
2802
[email protected]e80c73b2009-04-07 23:24:582803void RenderView::OnDragTargetDrop(const gfx::Point& client_point,
2804 const gfx::Point& screen_point) {
2805 webview()->DragTargetDrop(client_point, screen_point);
initial.commit09911bf2008-07-26 23:55:292806}
2807
2808void RenderView::OnUpdateWebPreferences(const WebPreferences& prefs) {
[email protected]2fab253a2009-08-17 23:00:592809 webkit_preferences_ = prefs;
2810 webkit_preferences_.Apply(webview());
initial.commit09911bf2008-07-26 23:55:292811}
2812
2813void RenderView::OnSetAltErrorPageURL(const GURL& url) {
2814 alternate_error_page_url_ = url;
2815}
2816
initial.commit09911bf2008-07-26 23:55:292817void RenderView::OnInstallMissingPlugin() {
2818 // This could happen when the first default plugin is deleted.
[email protected]f103ab72009-09-02 17:10:592819 if (first_default_plugin_)
2820 first_default_plugin_->InstallMissingPlugin();
initial.commit09911bf2008-07-26 23:55:292821}
2822
[email protected]b62d1a8c2009-01-13 23:54:572823void RenderView::OnFileChooserResponse(
[email protected]561abe62009-04-06 18:08:342824 const std::vector<FilePath>& file_names) {
[email protected]8029f5672009-03-20 22:33:362825 // This could happen if we navigated to a different page before the user
2826 // closed the chooser.
2827 if (!file_chooser_.get())
2828 return;
2829
[email protected]b62d1a8c2009-01-13 23:54:572830 file_chooser_->OnFileChoose(file_names);
initial.commit09911bf2008-07-26 23:55:292831 file_chooser_.reset();
2832}
2833
2834void RenderView::OnEnableViewSourceMode() {
2835 if (!webview())
2836 return;
2837 WebFrame* main_frame = webview()->GetMainFrame();
2838 if (!main_frame)
2839 return;
2840
[email protected]dd7daa82009-08-10 05:46:452841 main_frame->enableViewSourceMode(true);
initial.commit09911bf2008-07-26 23:55:292842}
2843
[email protected]0666aef2009-05-13 19:48:082844void RenderView::OnEnableIntrinsicWidthChangedMode() {
2845 send_preferred_width_changes_ = true;
2846}
2847
[email protected]80d96fa2009-06-10 22:34:512848void RenderView::OnSetRendererPrefs(const RendererPreferences& renderer_prefs) {
2849 renderer_preferences_ = renderer_prefs;
[email protected]6e282c92009-07-24 01:19:372850 UpdateFontRenderingFromRendererPrefs();
[email protected]7a74e102009-09-03 00:16:562851#if defined(OS_LINUX)
[email protected]d3ba77272009-09-03 00:06:092852 webview()->SetThemeFocusRingColor(renderer_prefs.focus_ring_color_r,
2853 renderer_prefs.focus_ring_color_g,
2854 renderer_prefs.focus_ring_color_b);
[email protected]7a74e102009-09-03 00:16:562855#endif
[email protected]80d96fa2009-06-10 22:34:512856}
2857
[email protected]581b87eb2009-07-23 23:06:562858void RenderView::OnMediaPlayerActionAt(int x,
2859 int y,
2860 const MediaPlayerAction& action) {
2861 if (!webview())
2862 return;
2863
2864 webview()->MediaPlayerActionAt(x, y, action);
2865}
2866
[email protected]7b291f92009-08-14 05:43:532867void RenderView::OnNotifyRendererViewType(ViewType::Type type) {
2868 view_type_ = type;
2869}
2870
2871void RenderView::OnUpdateBrowserWindowId(int window_id) {
2872 browser_window_id_ = window_id;
2873}
2874
initial.commit09911bf2008-07-26 23:55:292875void RenderView::OnUpdateBackForwardListCount(int back_list_count,
2876 int forward_list_count) {
2877 history_back_list_count_ = back_list_count;
2878 history_forward_list_count_ = forward_list_count;
2879}
2880
[email protected]266eb6f2008-09-30 23:56:502881void RenderView::OnGetAccessibilityInfo(
[email protected]6a983b42009-03-20 20:12:252882 const webkit_glue::WebAccessibility::InParams& in_params,
2883 webkit_glue::WebAccessibility::OutParams* out_params) {
[email protected]6c8afae52009-01-22 02:24:572884#if defined(OS_WIN)
[email protected]6a983b42009-03-20 20:12:252885 if (!web_accessibility_manager_.get()) {
2886 web_accessibility_manager_.reset(
2887 webkit_glue::WebAccessibilityManager::Create());
2888 }
[email protected]266eb6f2008-09-30 23:56:502889
[email protected]6a983b42009-03-20 20:12:252890 if (!web_accessibility_manager_->GetAccObjInfo(webview(), in_params,
2891 out_params)) {
[email protected]266eb6f2008-09-30 23:56:502892 return;
2893 }
[email protected]6c8afae52009-01-22 02:24:572894#else // defined(OS_WIN)
2895 // TODO(port): accessibility not yet implemented
2896 NOTIMPLEMENTED();
2897#endif
[email protected]266eb6f2008-09-30 23:56:502898}
2899
[email protected]6a983b42009-03-20 20:12:252900void RenderView::OnClearAccessibilityInfo(int acc_obj_id, bool clear_all) {
[email protected]6c8afae52009-01-22 02:24:572901#if defined(OS_WIN)
[email protected]6a983b42009-03-20 20:12:252902 if (!web_accessibility_manager_.get()) {
[email protected]266eb6f2008-09-30 23:56:502903 // If accessibility is not activated, ignore clearing message.
2904 return;
2905 }
[email protected]e846d0d2009-05-20 00:53:062906
[email protected]6a983b42009-03-20 20:12:252907 if (!web_accessibility_manager_->ClearAccObjMap(acc_obj_id, clear_all))
[email protected]266eb6f2008-09-30 23:56:502908 return;
[email protected]e846d0d2009-05-20 00:53:062909
[email protected]6c8afae52009-01-22 02:24:572910#else // defined(OS_WIN)
2911 // TODO(port): accessibility not yet implemented
2912 NOTIMPLEMENTED();
2913#endif
[email protected]266eb6f2008-09-30 23:56:502914}
2915
initial.commit09911bf2008-07-26 23:55:292916void RenderView::OnGetAllSavableResourceLinksForCurrentPage(
2917 const GURL& page_url) {
2918 // Prepare list to storage all savable resource links.
2919 std::vector<GURL> resources_list;
2920 std::vector<GURL> referrers_list;
2921 std::vector<GURL> frames_list;
2922 webkit_glue::SavableResourcesResult result(&resources_list,
2923 &referrers_list,
2924 &frames_list);
2925
2926 if (!webkit_glue::GetAllSavableResourceLinksForCurrentPage(webview(),
2927 page_url,
2928 &result)) {
2929 // If something is wrong when collecting all savable resource links,
2930 // send empty list to embedder(browser) to tell it failed.
2931 referrers_list.clear();
2932 resources_list.clear();
2933 frames_list.clear();
2934 }
2935
2936 // Send result of all savable resource links to embedder.
2937 Send(new ViewHostMsg_SendCurrentPageAllSavableResourceLinks(routing_id_,
2938 resources_list,
2939 referrers_list,
2940 frames_list));
2941}
2942
2943void RenderView::OnGetSerializedHtmlDataForCurrentPageWithLocalLinks(
[email protected]f6b48532009-02-12 01:56:322944 const std::vector<GURL>& links,
[email protected]fde6714d12009-02-18 22:39:312945 const std::vector<FilePath>& local_paths,
2946 const FilePath& local_directory_name) {
initial.commit09911bf2008-07-26 23:55:292947 webkit_glue::DomSerializer dom_serializer(webview()->GetMainFrame(),
2948 true,
2949 this,
2950 links,
2951 local_paths,
2952 local_directory_name);
2953 dom_serializer.SerializeDom();
2954}
2955
2956void RenderView::DidSerializeDataForFrame(const GURL& frame_url,
2957 const std::string& data, PageSavingSerializationStatus status) {
2958 Send(new ViewHostMsg_SendSerializedHtmlData(routing_id_,
2959 frame_url, data, static_cast<int32>(status)));
2960}
2961
[email protected]04b4a6c2008-08-02 00:44:472962void RenderView::OnMsgShouldClose() {
initial.commit09911bf2008-07-26 23:55:292963 bool should_close = webview()->ShouldClose();
[email protected]04b4a6c2008-08-02 00:44:472964 Send(new ViewHostMsg_ShouldClose_ACK(routing_id_, should_close));
initial.commit09911bf2008-07-26 23:55:292965}
2966
[email protected]eb6b87a2009-07-24 15:57:392967void RenderView::OnClosePage(const ViewMsg_ClosePage_Params& params) {
initial.commit09911bf2008-07-26 23:55:292968 // TODO(creis): We'd rather use webview()->Close() here, but that currently
2969 // sets the WebView's delegate_ to NULL, preventing any JavaScript dialogs
2970 // in the onunload handler from appearing. For now, we're bypassing that and
2971 // calling the FrameLoader's CloseURL method directly. This should be
2972 // revisited to avoid having two ways to close a page. Having a single way
2973 // to close that can run onunload is also useful for fixing
2974 // http://b/issue?id=753080.
2975 WebFrame* main_frame = webview()->GetMainFrame();
[email protected]7a9b51f2009-06-29 21:28:292976 if (main_frame) {
[email protected]dd7daa82009-08-10 05:46:452977 const GURL& url = main_frame->url();
[email protected]7a9b51f2009-06-29 21:28:292978 // TODO(davemoore) this code should be removed once WillCloseFrame() gets
2979 // called when a page is destroyed. DumpLoadHistograms() is safe to call
2980 // multiple times for the same frame, but it will simplify things.
[email protected]dd7daa82009-08-10 05:46:452981 if (url.SchemeIs(chrome::kHttpScheme) ||
2982 url.SchemeIs(chrome::kHttpsScheme))
[email protected]7a9b51f2009-06-29 21:28:292983 DumpLoadHistograms();
[email protected]7a9b51f2009-06-29 21:28:292984 }
[email protected]e6fae1b2009-08-06 23:20:352985 webview()->ClosePage();
initial.commit09911bf2008-07-26 23:55:292986
[email protected]eb6b87a2009-07-24 15:57:392987 // Just echo back the params in the ACK.
2988 Send(new ViewHostMsg_ClosePage_ACK(routing_id_, params));
initial.commit09911bf2008-07-26 23:55:292989}
2990
2991void RenderView::OnThemeChanged() {
[email protected]6c8afae52009-01-22 02:24:572992#if defined(OS_WIN)
initial.commit09911bf2008-07-26 23:55:292993 gfx::NativeTheme::instance()->CloseHandles();
2994 gfx::Rect view_rect(0, 0, size_.width(), size_.height());
[email protected]4873c7d2009-07-16 06:36:282995 didInvalidateRect(view_rect);
[email protected]6c8afae52009-01-22 02:24:572996#else // defined(OS_WIN)
2997 // TODO(port): we don't support theming on non-Windows platforms yet
2998 NOTIMPLEMENTED();
2999#endif
initial.commit09911bf2008-07-26 23:55:293000}
3001
[email protected]f46aff62008-10-16 07:58:053002void RenderView::DidAddHistoryItem() {
[email protected]f8901082008-10-31 23:34:033003 // We don't want to update the history length for the start page
3004 // navigation.
3005 WebFrame* main_frame = webview()->GetMainFrame();
3006 DCHECK(main_frame != NULL);
3007
[email protected]dd7daa82009-08-10 05:46:453008 WebDataSource* ds = main_frame->dataSource();
[email protected]f8901082008-10-31 23:34:033009 DCHECK(ds != NULL);
3010
[email protected]daa8c58e2009-06-15 17:21:103011 NavigationState* navigation_state = NavigationState::FromDataSource(ds);
[email protected]78a3a6f2009-07-02 16:15:013012 DCHECK(navigation_state);
[email protected]daa8c58e2009-06-15 17:21:103013 if (navigation_state->transition_type() == PageTransition::START_PAGE)
[email protected]f8901082008-10-31 23:34:033014 return;
3015
[email protected]f46aff62008-10-16 07:58:053016 history_back_list_count_++;
3017 history_forward_list_count_ = 0;
3018}
3019
[email protected]28790922009-03-09 19:48:373020void RenderView::OnMessageFromExternalHost(const std::string& message,
3021 const std::string& origin,
3022 const std::string& target) {
[email protected]3ac14a052008-08-15 21:22:153023 if (message.empty())
3024 return;
3025
[email protected]28790922009-03-09 19:48:373026 external_host_bindings_.ForwardMessageFromExternalHost(message, origin,
3027 target);
[email protected]3ac14a052008-08-15 21:22:153028}
3029
[email protected]0aa55312008-10-17 21:53:083030void RenderView::OnDisassociateFromPopupCount() {
3031 if (decrement_shared_popup_at_destruction_)
3032 shared_popup_counter_->data--;
3033 shared_popup_counter_ = new SharedRenderViewCounter(0);
3034 decrement_shared_popup_at_destruction_ = false;
3035}
3036
[email protected]15d79e12009-08-02 19:23:453037bool RenderView::MaybeLoadAlternateErrorPage(WebFrame* frame,
3038 const WebURLError& error,
3039 bool replace) {
3040 // We only show alternate error pages in the main frame. They are
3041 // intended to assist the user when navigating, so there is not much
3042 // value in showing them for failed subframes. Ideally, we would be
3043 // able to use the TYPED transition type for this, but that flag is
3044 // not preserved across page reloads.
[email protected]dd7daa82009-08-10 05:46:453045 if (frame->parent())
[email protected]15d79e12009-08-02 19:23:453046 return false;
3047
3048 // Use the alternate error page service if this is a DNS failure or
[email protected]c53976d52009-08-07 18:58:373049 // connection failure.
[email protected]15d79e12009-08-02 19:23:453050 int ec = error.reason;
3051 if (ec != net::ERR_NAME_NOT_RESOLVED &&
3052 ec != net::ERR_CONNECTION_FAILED &&
3053 ec != net::ERR_CONNECTION_REFUSED &&
3054 ec != net::ERR_ADDRESS_UNREACHABLE &&
[email protected]c53976d52009-08-07 18:58:373055 ec != net::ERR_CONNECTION_TIMED_OUT)
[email protected]15d79e12009-08-02 19:23:453056 return false;
3057
3058 const GURL& error_page_url = GetAlternateErrorPageURL(error.unreachableURL,
[email protected]7ccddb8c2009-08-04 17:36:553059 ec == net::ERR_NAME_NOT_RESOLVED ? DNS_ERROR : CONNECTION_ERROR);
[email protected]15d79e12009-08-02 19:23:453060 if (!error_page_url.is_valid())
3061 return false;
3062
3063 // Load an empty page first so there is an immediate response to the error,
3064 // and then kick off a request for the alternate error page.
[email protected]dd7daa82009-08-10 05:46:453065 frame->loadHTMLString(std::string(),
[email protected]15d79e12009-08-02 19:23:453066 GURL(kUnreachableWebDataURL),
3067 error.unreachableURL,
3068 replace);
3069
3070 // Now, create a fetcher for the error page and associate it with the data
3071 // source we just created via the LoadHTMLString call. That way if another
3072 // navigation occurs, the fetcher will get destroyed.
3073 NavigationState* navigation_state =
[email protected]dd7daa82009-08-10 05:46:453074 NavigationState::FromDataSource(frame->provisionalDataSource());
[email protected]15d79e12009-08-02 19:23:453075 navigation_state->set_alt_error_page_fetcher(
3076 new AltErrorPageResourceFetcher(
3077 error_page_url, frame, error,
3078 NewCallback(this, &RenderView::AltErrorPageFinished)));
3079 return true;
3080}
3081
initial.commit09911bf2008-07-26 23:55:293082std::string RenderView::GetAltHTMLForTemplate(
3083 const DictionaryValue& error_strings, int template_resource_id) const {
3084 const StringPiece template_html(
3085 ResourceBundle::GetSharedInstance().GetRawDataResource(
3086 template_resource_id));
3087
3088 if (template_html.empty()) {
3089 NOTREACHED() << "unable to load template. ID: " << template_resource_id;
3090 return "";
3091 }
[email protected]7cd22a52009-07-14 00:40:253092
initial.commit09911bf2008-07-26 23:55:293093 // "t" is the id of the templates root node.
[email protected]7cd22a52009-07-14 00:40:253094 return jstemplate_builder::GetTemplatesHtml(
initial.commit09911bf2008-07-26 23:55:293095 template_html, &error_strings, "t");
3096}
[email protected]0e79b9e2009-02-13 04:20:483097
[email protected]15d79e12009-08-02 19:23:453098void RenderView::AltErrorPageFinished(WebFrame* frame,
3099 const WebURLError& original_error,
3100 const std::string& html) {
3101 // Here, we replace the blank page we loaded previously.
[email protected]7ccddb8c2009-08-04 17:36:553102
3103 // If we failed to download the alternate error page, fall back to the
3104 // original error page if present. Otherwise, LoadNavigationErrorPage
3105 // will simply display a default error page.
3106 const std::string* html_to_load = &html;
3107 if (html.empty()) {
3108 NavigationState* navigation_state =
[email protected]dd7daa82009-08-10 05:46:453109 NavigationState::FromDataSource(frame->dataSource());
[email protected]7ccddb8c2009-08-04 17:36:553110 html_to_load = &navigation_state->postponed_data();
3111 }
3112 LoadNavigationErrorPage(
3113 frame, WebURLRequest(), original_error, *html_to_load, true);
[email protected]15d79e12009-08-02 19:23:453114}
3115
[email protected]30f75e62009-02-25 22:01:003116void RenderView::OnMoveOrResizeStarted() {
3117 if (webview())
3118 webview()->HideAutofillPopup();
3119}
3120
[email protected]30f75e62009-02-25 22:01:003121void RenderView::OnResize(const gfx::Size& new_size,
3122 const gfx::Rect& resizer_rect) {
3123 if (webview())
3124 webview()->HideAutofillPopup();
3125 RenderWidget::OnResize(new_size, resizer_rect);
3126}
[email protected]0aa477bd2009-03-23 22:21:433127
[email protected]05d478752009-04-08 23:38:163128void RenderView::OnClearFocusedNode() {
3129 if (webview())
3130 webview()->ClearFocusedNode();
3131}
3132
[email protected]699ab0d2009-04-23 23:19:143133void RenderView::OnSetBackground(const SkBitmap& background) {
3134 if (webview())
3135 webview()->SetIsTransparent(!background.empty());
3136
3137 SetBackground(background);
3138}
3139
[email protected]8c66c5a2009-07-22 17:26:343140void RenderView::OnSetActive(bool active) {
3141 if (webview())
3142 webview()->SetActive(active);
3143}
3144
[email protected]309d7a282009-03-24 09:18:273145void RenderView::SendExtensionRequest(const std::string& name,
3146 const std::string& args,
[email protected]c6619182009-05-12 14:59:323147 int request_id,
[email protected]2f25d7b92009-06-10 00:06:473148 bool has_callback) {
[email protected]c6619182009-05-12 14:59:323149 Send(new ViewHostMsg_ExtensionRequest(routing_id_, name, args, request_id,
[email protected]2f25d7b92009-06-10 00:06:473150 has_callback));
[email protected]309d7a282009-03-24 09:18:273151}
3152
[email protected]c6619182009-05-12 14:59:323153void RenderView::OnExtensionResponse(int request_id,
3154 bool success,
3155 const std::string& response,
3156 const std::string& error) {
[email protected]0f6053962009-07-09 19:26:353157 ExtensionProcessBindings::HandleResponse(
3158 request_id, success, response, error);
[email protected]309d7a282009-03-24 09:18:273159}
[email protected]c20210e62009-04-03 21:39:263160
[email protected]7120f132009-07-20 21:05:373161void RenderView::OnExtensionMessageInvoke(const std::string& function_name,
3162 const ListValue& args) {
3163 RendererExtensionBindings::Invoke(function_name, args, this);
3164}
3165
[email protected]e7e4f3c2009-04-21 15:24:083166// Dump all load time histograms.
[email protected]c20210e62009-04-03 21:39:263167//
[email protected]7a9b51f2009-06-29 21:28:293168// There are 13 histograms measuring various times.
[email protected]c20210e62009-04-03 21:39:263169// The time points we keep are
3170// request: time document was requested by user
3171// start: time load of document started
[email protected]a2f6bc112009-06-27 16:27:253172// commit: time load of document started
[email protected]7a9b51f2009-06-29 21:28:293173// finish_document: main document loaded, before onload()
[email protected]c20210e62009-04-03 21:39:263174// finish: after onload() and all resources are loaded
[email protected]7a9b51f2009-06-29 21:28:293175// first_paint: first paint performed
3176// first_paint_after_load: first paint performed after load is finished
3177// begin: request if it was user requested, start otherwise
3178//
[email protected]c20210e62009-04-03 21:39:263179// The times that we histogram are
[email protected]a2f6bc112009-06-27 16:27:253180// request->start,
[email protected]7a9b51f2009-06-29 21:28:293181// start->commit,
3182// commit->finish_document,
3183// finish_document->finish,
3184// begin->commit,
3185// begin->finishDoc,
3186// begin->finish,
3187// begin->first_paint,
3188// begin->first_paint_after_load
3189// commit->finishDoc,
3190// commit->first_paint,
3191// commit->first_paint_after_load,
3192// finish->first_paint_after_load,
[email protected]c20210e62009-04-03 21:39:263193//
[email protected]e7e4f3c2009-04-21 15:24:083194// It's possible for the request time not to be set, if a client
3195// redirect had been done (the user never requested the page)
3196// Also, it's possible to load a page without ever laying it out
[email protected]7a9b51f2009-06-29 21:28:293197// so first_paint and first_paint_after_load can be 0.
[email protected]c20210e62009-04-03 21:39:263198void RenderView::DumpLoadHistograms() const {
3199 WebFrame* main_frame = webview()->GetMainFrame();
[email protected]ed3fb032009-06-16 19:50:563200 NavigationState* navigation_state =
[email protected]dd7daa82009-08-10 05:46:453201 NavigationState::FromDataSource(main_frame->dataSource());
[email protected]7a9b51f2009-06-29 21:28:293202 Time finish = navigation_state->finish_load_time();
[email protected]ed3fb032009-06-16 19:50:563203
[email protected]7a9b51f2009-06-29 21:28:293204 // If we've already dumped or we haven't finished loading, do nothing.
3205 if (navigation_state->load_histograms_recorded() || finish.is_null())
3206 return;
[email protected]ed3fb032009-06-16 19:50:563207
[email protected]7a9b51f2009-06-29 21:28:293208 Time request = navigation_state->request_time();
3209 Time start = navigation_state->start_load_time();
3210 Time commit = navigation_state->commit_load_time();
3211 Time finish_doc = navigation_state->finish_document_load_time();
3212 Time first_paint = navigation_state->first_paint_time();
3213 Time first_paint_after_load =
3214 navigation_state->first_paint_after_load_time();
[email protected]c20210e62009-04-03 21:39:263215
[email protected]7a9b51f2009-06-29 21:28:293216 Time begin;
3217 // Client side redirects will have no request time.
3218 if (request.is_null()) {
3219 begin = start;
3220 } else {
3221 begin = request;
3222 UMA_HISTOGRAM_MEDIUM_TIMES("Renderer4.RequestToStart", start - request);
[email protected]e7e4f3c2009-04-21 15:24:083223 }
[email protected]7a9b51f2009-06-29 21:28:293224 UMA_HISTOGRAM_MEDIUM_TIMES("Renderer4.StartToCommit", commit - start);
3225 UMA_HISTOGRAM_MEDIUM_TIMES(
3226 "Renderer4.CommitToFinishDoc", finish_doc - commit);
3227 UMA_HISTOGRAM_MEDIUM_TIMES(
3228 "Renderer4.FinishDocToFinish", finish - finish_doc);
3229
3230 UMA_HISTOGRAM_MEDIUM_TIMES("Renderer4.BeginToCommit", commit - begin);
3231 UMA_HISTOGRAM_MEDIUM_TIMES("Renderer4.BeginToFinishDoc", finish_doc - begin);
[email protected]e695fbd62009-06-30 16:31:543232
3233 static const TimeDelta kBeginToFinishMin(TimeDelta::FromMilliseconds(10));
3234 static const TimeDelta kBeginToFinishMax(TimeDelta::FromMinutes(10));
3235 static const size_t kBeginToFinishBucketCount(100);
3236
3237 UMA_HISTOGRAM_CUSTOM_TIMES("Renderer4.BeginToFinish",
3238 finish - begin, kBeginToFinishMin,
3239 kBeginToFinishMax, kBeginToFinishBucketCount);
[email protected]0a32257a2009-07-09 18:10:413240 UMA_HISTOGRAM_CUSTOM_TIMES("Renderer4.StartToFinish",
3241 finish - start, kBeginToFinishMin,
3242 kBeginToFinishMax, kBeginToFinishBucketCount);
3243 if (!request.is_null())
3244 UMA_HISTOGRAM_CUSTOM_TIMES("Renderer4.RequestToFinish",
3245 finish - request, kBeginToFinishMin,
3246 kBeginToFinishMax, kBeginToFinishBucketCount);
[email protected]e695fbd62009-06-30 16:31:543247
[email protected]36285b52009-06-30 19:10:003248 static bool use_dns_histogram(FieldTrialList::Find("DnsImpact") &&
3249 !FieldTrialList::Find("DnsImpact")->group_name().empty());
[email protected]0a32257a2009-07-09 18:10:413250 if (use_dns_histogram) {
[email protected]36285b52009-06-30 19:10:003251 UMA_HISTOGRAM_CUSTOM_TIMES(
3252 FieldTrial::MakeName("Renderer4.BeginToFinish", "DnsImpact").data(),
3253 finish - begin, kBeginToFinishMin,
3254 kBeginToFinishMax, kBeginToFinishBucketCount);
[email protected]0a32257a2009-07-09 18:10:413255 UMA_HISTOGRAM_CUSTOM_TIMES(
3256 FieldTrial::MakeName("Renderer4.StartToFinish", "DnsImpact").data(),
3257 finish - start, kBeginToFinishMin,
3258 kBeginToFinishMax, kBeginToFinishBucketCount);
3259 if (!request.is_null())
3260 UMA_HISTOGRAM_CUSTOM_TIMES(
3261 FieldTrial::MakeName("Renderer4.RequestToFinish", "DnsImpact").data(),
3262 finish - request, kBeginToFinishMin,
3263 kBeginToFinishMax, kBeginToFinishBucketCount);
3264 }
[email protected]e695fbd62009-06-30 16:31:543265
[email protected]36285b52009-06-30 19:10:003266 static bool use_sdch_histogram(FieldTrialList::Find("GlobalSdch") &&
3267 !FieldTrialList::Find("GlobalSdch")->group_name().empty());
[email protected]0a32257a2009-07-09 18:10:413268 if (use_sdch_histogram) {
[email protected]36285b52009-06-30 19:10:003269 UMA_HISTOGRAM_CUSTOM_TIMES(
3270 FieldTrial::MakeName("Renderer4.BeginToFinish", "GlobalSdch").data(),
3271 finish - begin, kBeginToFinishMin,
3272 kBeginToFinishMax, kBeginToFinishBucketCount);
[email protected]0a32257a2009-07-09 18:10:413273 UMA_HISTOGRAM_CUSTOM_TIMES(
3274 FieldTrial::MakeName("Renderer4.StartToFinish", "GlobalSdch").data(),
3275 finish - start, kBeginToFinishMin,
3276 kBeginToFinishMax, kBeginToFinishBucketCount);
3277 if (!request.is_null())
3278 UMA_HISTOGRAM_CUSTOM_TIMES(
3279 FieldTrial::MakeName("Renderer4.RequestToFinish",
3280 "GlobalSdch").data(),
3281 finish - request, kBeginToFinishMin,
3282 kBeginToFinishMax, kBeginToFinishBucketCount);
3283 }
[email protected]7a9b51f2009-06-29 21:28:293284
[email protected]5fff93f2009-08-02 04:27:343285 static bool use_socket_late_binding_histogram =
3286 FieldTrialList::Find("SocketLateBinding") &&
3287 !FieldTrialList::Find("SocketLateBinding")->group_name().empty();
3288 if (use_socket_late_binding_histogram) {
3289 UMA_HISTOGRAM_CUSTOM_TIMES(
3290 FieldTrial::MakeName("Renderer4.BeginToFinish",
3291 "SocketLateBinding").data(),
3292 finish - begin, kBeginToFinishMin,
3293 kBeginToFinishMax, kBeginToFinishBucketCount);
3294 UMA_HISTOGRAM_CUSTOM_TIMES(
3295 FieldTrial::MakeName("Renderer4.StartToFinish",
3296 "SocketLateBinding").data(),
3297 finish - start, kBeginToFinishMin,
3298 kBeginToFinishMax, kBeginToFinishBucketCount);
3299 if (!request.is_null())
3300 UMA_HISTOGRAM_CUSTOM_TIMES(
3301 FieldTrial::MakeName("Renderer4.RequestToFinish",
3302 "SocketLateBinding").data(),
3303 finish - request, kBeginToFinishMin,
3304 kBeginToFinishMax, kBeginToFinishBucketCount);
3305 }
3306
[email protected]7e05f6c42009-07-11 01:50:483307 static bool use_cache_histogram1(FieldTrialList::Find("CacheSize") &&
3308 !FieldTrialList::Find("CacheSize")->group_name().empty());
3309 if (use_cache_histogram1)
3310 UMA_HISTOGRAM_CUSTOM_TIMES(
3311 FieldTrial::MakeName("Renderer4.StartToFinish", "CacheSize").data(),
3312 finish - start, kBeginToFinishMin,
3313 kBeginToFinishMax, kBeginToFinishBucketCount);
3314
3315 static bool use_cache_histogram2(FieldTrialList::Find("NewEviction") &&
3316 !FieldTrialList::Find("NewEviction")->group_name().empty());
3317 if (use_cache_histogram2)
3318 UMA_HISTOGRAM_CUSTOM_TIMES(
3319 FieldTrial::MakeName("Renderer4.StartToFinish", "NewEviction").data(),
3320 finish - start, kBeginToFinishMin,
3321 kBeginToFinishMax, kBeginToFinishBucketCount);
3322
[email protected]7a9b51f2009-06-29 21:28:293323 UMA_HISTOGRAM_MEDIUM_TIMES("Renderer4.CommitToFinish", finish - commit);
3324
3325 if (!first_paint.is_null()) {
3326 UMA_HISTOGRAM_MEDIUM_TIMES(
3327 "Renderer4.BeginToFirstPaint", first_paint - begin);
3328 UMA_HISTOGRAM_MEDIUM_TIMES(
3329 "Renderer4.CommitToFirstPaint", first_paint - commit);
[email protected]c20210e62009-04-03 21:39:263330 }
[email protected]7a9b51f2009-06-29 21:28:293331
3332 if (!first_paint_after_load.is_null()) {
3333 UMA_HISTOGRAM_MEDIUM_TIMES(
3334 "Renderer4.BeginToFirstPaintAfterLoad", first_paint_after_load - begin);
3335 UMA_HISTOGRAM_MEDIUM_TIMES(
3336 "Renderer4.CommitToFirstPaintAfterLoad",
3337 first_paint_after_load - commit);
3338 UMA_HISTOGRAM_MEDIUM_TIMES(
3339 "Renderer4.FinishToFirstPaintAfterLoad",
3340 first_paint_after_load - finish);
3341 }
3342
3343 navigation_state->set_load_histograms_recorded(true);
[email protected]c20210e62009-04-03 21:39:263344}
[email protected]e846d0d2009-05-20 00:53:063345
3346void RenderView::FocusAccessibilityObject(
3347 WebCore::AccessibilityObject* acc_obj) {
3348#if defined(OS_WIN)
3349 if (!web_accessibility_manager_.get()) {
3350 web_accessibility_manager_.reset(
3351 webkit_glue::WebAccessibilityManager::Create());
3352 }
3353
3354 // Retrieve the accessibility object id of the AccessibilityObject.
3355 int acc_obj_id = web_accessibility_manager_->FocusAccObj(acc_obj);
3356
3357 // If id is valid, alert the browser side that an accessibility focus change
3358 // occurred.
3359 if (acc_obj_id >= 0)
3360 Send(new ViewHostMsg_AccessibilityFocusChange(routing_id_, acc_obj_id));
3361
3362#else // defined(OS_WIN)
3363 // TODO(port): accessibility not yet implemented
3364 NOTIMPLEMENTED();
3365#endif
3366}
[email protected]daa8c58e2009-06-15 17:21:103367
3368void RenderView::SendPasswordForms(WebFrame* frame) {
[email protected]dd7daa82009-08-10 05:46:453369 WebVector<WebForm> forms;
3370 frame->forms(forms);
[email protected]daa8c58e2009-06-15 17:21:103371
3372 std::vector<PasswordForm> password_forms;
3373 for (size_t i = 0; i < forms.size(); ++i) {
3374 const WebForm& form = forms[i];
3375
3376 // Respect autocomplete=off.
3377 if (form.isAutoCompleteEnabled()) {
3378 scoped_ptr<PasswordForm> password_form(
3379 PasswordFormDomManager::CreatePasswordForm(form));
3380 if (password_form.get())
3381 password_forms.push_back(*password_form);
3382 }
3383 }
3384
3385 if (!password_forms.empty())
3386 Send(new ViewHostMsg_PasswordFormsSeen(routing_id_, password_forms));
3387}
[email protected]0fda7272009-06-26 15:49:333388
3389void RenderView::Print(WebFrame* frame, bool script_initiated) {
3390 DCHECK(frame);
3391 if (print_helper_.get() == NULL) {
3392 print_helper_.reset(new PrintWebViewHelper(this));
3393 }
3394 print_helper_->Print(frame, script_initiated);
3395}