blob: 59523a63c1684672b092b31cecc533406896d6e4 [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]ba4b17f2009-02-11 21:32:2974#include "webkit/default_plugin/default_plugin_shared.h"
[email protected]ca948a22009-06-25 19:36:1775#include "webkit/glue/glue_serialize.h"
initial.commit09911bf2008-07-26 23:55:2976#include "webkit/glue/dom_operations.h"
77#include "webkit/glue/dom_serializer.h"
[email protected]f11ca0732009-04-11 00:09:3478#include "webkit/glue/image_decoder.h"
[email protected]8e296bbd2009-07-22 21:37:1779#include "webkit/glue/media/buffered_data_source.h"
[email protected]8380c092009-06-25 17:45:5180#include "webkit/glue/media/simple_data_source.h"
initial.commit09911bf2008-07-26 23:55:2981#include "webkit/glue/password_form.h"
[email protected]ba4b17f2009-02-11 21:32:2982#include "webkit/glue/plugins/plugin_list.h"
initial.commit09911bf2008-07-26 23:55:2983#include "webkit/glue/searchable_form_data.h"
[email protected]6a983b42009-03-20 20:12:2584#include "webkit/glue/webaccessibilitymanager_impl.h"
[email protected]611cad42009-03-16 18:51:3485#include "webkit/glue/webdevtoolsagent_delegate.h"
initial.commit09911bf2008-07-26 23:55:2986#include "webkit/glue/webdropdata.h"
initial.commit09911bf2008-07-26 23:55:2987#include "webkit/glue/webkit_glue.h"
[email protected]add51772009-06-11 18:25:1788#include "webkit/glue/webmediaplayer_impl.h"
[email protected]b94d3322009-02-12 19:49:0489#include "webkit/glue/webplugin_delegate.h"
initial.commit09911bf2008-07-26 23:55:2990#include "webkit/glue/webview.h"
initial.commit09911bf2008-07-26 23:55:2991
[email protected]6c8afae52009-01-22 02:24:5792#if defined(OS_WIN)
93// TODO(port): these files are currently Windows only because they concern:
[email protected]6c8afae52009-01-22 02:24:5794// * theming
[email protected]6c8afae52009-01-22 02:24:5795#include "base/gfx/native_theme.h"
[email protected]6c8afae52009-01-22 02:24:5796#endif
97
[email protected]c20210e62009-04-03 21:39:2698using base::Time;
[email protected]e1acf6f2008-10-27 20:43:3399using base::TimeDelta;
[email protected]15d79e12009-08-02 19:23:45100using webkit_glue::AltErrorPageResourceFetcher;
[email protected]daa8c58e2009-06-15 17:21:10101using webkit_glue::AutofillForm;
[email protected]ed3fb032009-06-16 19:50:56102using webkit_glue::PasswordForm;
[email protected]daa8c58e2009-06-15 17:21:10103using webkit_glue::PasswordFormDomManager;
104using webkit_glue::SearchableFormData;
[email protected]0dea3ea2009-03-31 23:30:59105using WebKit::WebConsoleMessage;
[email protected]e6f546c32009-07-01 17:12:55106using WebKit::WebData;
[email protected]726985e22009-06-18 21:09:28107using WebKit::WebDataSource;
[email protected]e80c73b2009-04-07 23:24:58108using WebKit::WebDragData;
[email protected]daa8c58e2009-06-15 17:21:10109using WebKit::WebForm;
[email protected]dd7daa82009-08-10 05:46:45110using WebKit::WebFrame;
[email protected]ca948a22009-06-25 19:36:17111using WebKit::WebHistoryItem;
[email protected]4873c7d2009-07-16 06:36:28112using WebKit::WebNavigationPolicy;
[email protected]726985e22009-06-18 21:09:28113using WebKit::WebNavigationType;
[email protected]88efb7ec2009-07-14 16:32:59114using WebKit::WebPopupMenuInfo;
[email protected]b3f2b912009-04-09 16:18:52115using WebKit::WebRect;
[email protected]4f999132009-03-31 18:08:40116using WebKit::WebScriptSource;
[email protected]2fab253a2009-08-17 23:00:59117using WebKit::WebSettings;
[email protected]8649fb32009-06-26 17:51:02118using WebKit::WebSize;
[email protected]726985e22009-06-18 21:09:28119using WebKit::WebString;
[email protected]de570ef2009-07-29 18:27:52120using WebKit::WebTextDirection;
[email protected]726985e22009-06-18 21:09:28121using WebKit::WebURL;
122using WebKit::WebURLError;
123using WebKit::WebURLRequest;
124using WebKit::WebURLResponse;
[email protected]4873c7d2009-07-16 06:36:28125using WebKit::WebVector;
126using WebKit::WebWidget;
[email protected]27ba8532009-04-24 20:22:43127using WebKit::WebWorker;
128using WebKit::WebWorkerClient;
[email protected]e1acf6f2008-10-27 20:43:33129
initial.commit09911bf2008-07-26 23:55:29130//-----------------------------------------------------------------------------
131
132// define to write the time necessary for thumbnail/DOM text retrieval,
133// respectively, into the system debug log
134// #define TIME_BITMAP_RETRIEVAL
135// #define TIME_TEXT_RETRIEVAL
136
137// maximum number of characters in the document to index, any text beyond this
138// point will be clipped
[email protected]6c8afae52009-01-22 02:24:57139static const size_t kMaxIndexChars = 65535;
initial.commit09911bf2008-07-26 23:55:29140
141// Size of the thumbnails that we'll generate
142static const int kThumbnailWidth = 196;
143static const int kThumbnailHeight = 136;
144
145// Delay in milliseconds that we'll wait before capturing the page contents
146// and thumbnail.
147static const int kDelayForCaptureMs = 500;
148
149// Typically, we capture the page data once the page is loaded.
150// Sometimes, the page never finishes to load, preventing the page capture
151// To workaround this problem, we always perform a capture after the following
152// delay.
153static const int kDelayForForcedCaptureMs = 6000;
154
[email protected]81a34412009-01-05 19:17:24155// The default value for RenderView.delay_seconds_for_form_state_sync_, see
156// that variable for more.
157const int kDefaultDelaySecondsForFormStateSync = 5;
initial.commit09911bf2008-07-26 23:55:29158
159// The next available page ID to use. This ensures that the page IDs are
160// globally unique in the renderer.
161static int32 next_page_id_ = 1;
162
[email protected]0aa55312008-10-17 21:53:08163// The maximum number of popups that can be spawned from one page.
164static const int kMaximumNumberOfUnacknowledgedPopups = 25;
165
initial.commit09911bf2008-07-26 23:55:29166static const char* const kUnreachableWebDataURL =
[email protected]60e448982009-05-06 04:21:16167 "chrome://chromewebdata/";
initial.commit09911bf2008-07-26 23:55:29168
[email protected]50b691c2008-10-31 19:08:35169static const char* const kBackForwardNavigationScheme = "history";
170
[email protected]726985e22009-06-18 21:09:28171static void GetRedirectChain(WebDataSource* ds, std::vector<GURL>* result) {
172 WebVector<WebURL> urls;
173 ds->redirectChain(urls);
174 result->reserve(urls.size());
175 for (size_t i = 0; i < urls.size(); ++i)
176 result->push_back(urls[i]);
177}
178
initial.commit09911bf2008-07-26 23:55:29179///////////////////////////////////////////////////////////////////////////////
180
[email protected]2fab253a2009-08-17 23:00:59181RenderView::RenderView(RenderThreadBase* render_thread,
182 const WebPreferences& webkit_preferences)
[email protected]81a34412009-01-05 19:17:24183 : RenderWidget(render_thread, true),
[email protected]81e63782009-02-27 19:35:09184 enabled_bindings_(0),
[email protected]e75cb49e2009-01-05 23:13:21185 target_url_status_(TARGET_NONE),
[email protected]81a34412009-01-05 19:17:24186 is_loading_(false),
[email protected]e75cb49e2009-01-05 23:13:21187 navigation_gesture_(NavigationGestureUnknown),
[email protected]81a34412009-01-05 19:17:24188 page_id_(-1),
189 last_page_id_sent_to_browser_(-1),
190 last_indexed_page_id_(-1),
[email protected]81a34412009-01-05 19:17:24191 opened_by_user_gesture_(true),
[email protected]bb063b72009-03-27 23:18:50192 ALLOW_THIS_IN_INITIALIZER_LIST(method_factory_(this)),
[email protected]81a34412009-01-05 19:17:24193 first_default_plugin_(NULL),
[email protected]e4ac5df2009-03-17 15:33:11194 devtools_agent_(NULL),
195 devtools_client_(NULL),
[email protected]81a34412009-01-05 19:17:24196 history_back_list_count_(0),
197 history_forward_list_count_(0),
[email protected]81a34412009-01-05 19:17:24198 has_unload_listener_(false),
199 decrement_shared_popup_at_destruction_(false),
[email protected]81a34412009-01-05 19:17:24200 form_field_autofill_request_id_(0),
201 popup_notification_visible_(false),
[email protected]0666aef2009-05-13 19:48:08202 delay_seconds_for_form_state_sync_(kDefaultDelaySecondsForFormStateSync),
203 preferred_width_(0),
[email protected]5c4266922009-07-10 16:41:27204 send_preferred_width_changes_(false),
[email protected]5f450e52009-07-28 13:28:11205 determine_page_text_after_loading_stops_(false),
[email protected]7b291f92009-08-14 05:43:53206 view_type_(ViewType::INVALID),
207 browser_window_id_(-1),
[email protected]2fab253a2009-08-17 23:00:59208 webkit_preferences_(webkit_preferences) {
[email protected]7b291f92009-08-14 05:43:53209 Singleton<RenderViewSet>()->render_view_set_.insert(this);
initial.commit09911bf2008-07-26 23:55:29210}
211
212RenderView::~RenderView() {
[email protected]7b291f92009-08-14 05:43:53213 Singleton<RenderViewSet>()->render_view_set_.erase(this);
[email protected]0aa55312008-10-17 21:53:08214 if (decrement_shared_popup_at_destruction_)
215 shared_popup_counter_->data--;
216
initial.commit09911bf2008-07-26 23:55:29217 // Clear any back-pointers that might still be held by plugins.
218 PluginDelegateList::iterator it = plugin_delegates_.begin();
219 while (it != plugin_delegates_.end()) {
220 (*it)->DropRenderView();
221 it = plugin_delegates_.erase(it);
222 }
223
[email protected]5fb88962009-04-16 19:03:25224 render_thread_->RemoveFilter(audio_message_filter_);
initial.commit09911bf2008-07-26 23:55:29225}
226
227/*static*/
[email protected]0aa55312008-10-17 21:53:08228RenderView* RenderView::Create(
[email protected]81a34412009-01-05 19:17:24229 RenderThreadBase* render_thread,
[email protected]18bcc3c2009-01-27 21:39:15230 gfx::NativeViewId parent_hwnd,
[email protected]1c4947f2009-01-15 22:25:11231 base::WaitableEvent* modal_dialog_event,
[email protected]0aa55312008-10-17 21:53:08232 int32 opener_id,
[email protected]80d96fa2009-06-10 22:34:51233 const RendererPreferences& renderer_prefs,
[email protected]0aa55312008-10-17 21:53:08234 const WebPreferences& webkit_prefs,
235 SharedRenderViewCounter* counter,
236 int32 routing_id) {
initial.commit09911bf2008-07-26 23:55:29237 DCHECK(routing_id != MSG_ROUTING_NONE);
[email protected]2fab253a2009-08-17 23:00:59238 scoped_refptr<RenderView> view = new RenderView(render_thread, webkit_prefs);
initial.commit09911bf2008-07-26 23:55:29239 view->Init(parent_hwnd,
240 modal_dialog_event,
241 opener_id,
[email protected]80d96fa2009-06-10 22:34:51242 renderer_prefs,
[email protected]0aa55312008-10-17 21:53:08243 counter,
initial.commit09911bf2008-07-26 23:55:29244 routing_id); // adds reference
245 return view;
246}
247
248/*static*/
249void RenderView::SetNextPageID(int32 next_page_id) {
250 // This method should only be called during process startup, and the given
251 // page id had better not exceed our current next page id!
[email protected]4646f292009-05-20 03:49:05252 DCHECK_EQ(next_page_id_, 1);
initial.commit09911bf2008-07-26 23:55:29253 DCHECK(next_page_id >= next_page_id_);
254 next_page_id_ = next_page_id;
255}
256
257void RenderView::PluginDestroyed(WebPluginDelegateProxy* proxy) {
258 PluginDelegateList::iterator it =
259 std::find(plugin_delegates_.begin(), plugin_delegates_.end(), proxy);
260 DCHECK(it != plugin_delegates_.end());
261 plugin_delegates_.erase(it);
262 // If the plugin is deleted, we need to clear our reference in case user
263 // clicks the info bar to install. Unfortunately we are getting
264 // PluginDestroyed in single process mode. However, that is not a huge
265 // concern.
266 if (proxy == first_default_plugin_)
267 first_default_plugin_ = NULL;
268}
269
[email protected]fb466342009-07-15 00:43:08270void RenderView::PluginCrashed(base::ProcessId pid,
271 const FilePath& plugin_path) {
272 Send(new ViewHostMsg_CrashedPlugin(routing_id_, pid, plugin_path));
initial.commit09911bf2008-07-26 23:55:29273}
274
275
276void RenderView::JSOutOfMemory() {
277 Send(new ViewHostMsg_JSOutOfMemory(routing_id_));
278}
279
[email protected]18bcc3c2009-01-27 21:39:15280void RenderView::Init(gfx::NativeViewId parent_hwnd,
[email protected]1c4947f2009-01-15 22:25:11281 base::WaitableEvent* modal_dialog_event,
initial.commit09911bf2008-07-26 23:55:29282 int32 opener_id,
[email protected]80d96fa2009-06-10 22:34:51283 const RendererPreferences& renderer_prefs,
[email protected]0aa55312008-10-17 21:53:08284 SharedRenderViewCounter* counter,
initial.commit09911bf2008-07-26 23:55:29285 int32 routing_id) {
286 DCHECK(!webview());
287
288 if (opener_id != MSG_ROUTING_NONE)
289 opener_id_ = opener_id;
290
[email protected]0aa55312008-10-17 21:53:08291 if (counter) {
292 shared_popup_counter_ = counter;
293 shared_popup_counter_->data++;
294 decrement_shared_popup_at_destruction_ = true;
295 } else {
296 shared_popup_counter_ = new SharedRenderViewCounter(0);
297 decrement_shared_popup_at_destruction_ = false;
298 }
299
[email protected]80d96fa2009-06-10 22:34:51300 OnSetRendererPrefs(renderer_prefs);
301
[email protected]58bfc6b2009-06-24 09:45:02302 devtools_agent_.reset(new DevToolsAgent(routing_id, this));
[email protected]9b9d7282009-04-08 14:13:04303
[email protected]2fab253a2009-08-17 23:00:59304 webwidget_ = WebView::Create();
305 webkit_preferences_.Apply(webview());
306 webview()->InitializeMainFrame(this);
initial.commit09911bf2008-07-26 23:55:29307
[email protected]2e417c82009-04-02 22:30:26308#if defined(OS_LINUX)
309 // We have to enable ourselves as the editor delegate on linux so we can copy
310 // text selections to the X clipboard.
311 webview()->SetUseEditorDelegate(true);
312#endif
313
initial.commit09911bf2008-07-26 23:55:29314 // Don't let WebCore keep a B/F list - we have our own.
315 // We let it keep 1 entry because FrameLoader::goToItem expects an item in the
316 // backForwardList, which is used only in ASSERTs.
317 webview()->SetBackForwardListSize(1);
318
319 routing_id_ = routing_id;
[email protected]81a34412009-01-05 19:17:24320 render_thread_->AddRoute(routing_id_, this);
initial.commit09911bf2008-07-26 23:55:29321 // Take a reference on behalf of the RenderThread. This will be balanced
322 // when we receive ViewMsg_Close.
323 AddRef();
324
325 // If this is a popup, we must wait for the CreatingNew_ACK message before
326 // completing initialization. Otherwise, we can finish it now.
327 if (opener_id == MSG_ROUTING_NONE) {
328 did_show_ = true;
329 CompleteInit(parent_hwnd);
330 }
331
332 host_window_ = parent_hwnd;
[email protected]1c4947f2009-01-15 22:25:11333 modal_dialog_event_.reset(modal_dialog_event);
initial.commit09911bf2008-07-26 23:55:29334
[email protected]58bfc6b2009-06-24 09:45:02335 const CommandLine& command_line = *CommandLine::ForCurrentProcess();
[email protected]81e63782009-02-27 19:35:09336 if (command_line.HasSwitch(switches::kDomAutomationController))
337 enabled_bindings_ |= BindingsPolicy::DOM_AUTOMATION;
initial.commit09911bf2008-07-26 23:55:29338
[email protected]5fb88962009-04-16 19:03:25339 audio_message_filter_ = new AudioMessageFilter(routing_id_);
340 render_thread_->AddFilter(audio_message_filter_);
initial.commit09911bf2008-07-26 23:55:29341}
342
343void RenderView::OnMessageReceived(const IPC::Message& message) {
[email protected]f8b6b6f2009-03-10 16:48:26344 WebFrame* main_frame = webview() ? webview()->GetMainFrame() : NULL;
[email protected]ef916272009-07-08 21:40:55345 child_process_logging::ScopedActiveURLSetter url_setter(
[email protected]dd7daa82009-08-10 05:46:45346 main_frame ? main_frame->url() : WebURL());
[email protected]f8b6b6f2009-03-10 16:48:26347
[email protected]b2abac72009-02-26 12:39:28348 // If this is developer tools renderer intercept tools messages first.
[email protected]e4ac5df2009-03-17 15:33:11349 if (devtools_client_.get() && devtools_client_->OnMessageReceived(message))
[email protected]b2abac72009-02-26 12:39:28350 return;
[email protected]b4b967e2009-04-22 11:33:05351 if (devtools_agent_.get() && devtools_agent_->OnMessageReceived(message))
352 return;
[email protected]b2abac72009-02-26 12:39:28353
initial.commit09911bf2008-07-26 23:55:29354 IPC_BEGIN_MESSAGE_MAP(RenderView, message)
initial.commit09911bf2008-07-26 23:55:29355 IPC_MESSAGE_HANDLER(ViewMsg_CaptureThumbnail, SendThumbnail)
initial.commit09911bf2008-07-26 23:55:29356 IPC_MESSAGE_HANDLER(ViewMsg_PrintPages, OnPrintPages)
[email protected]82270452009-06-19 15:58:01357 IPC_MESSAGE_HANDLER(ViewMsg_PrintingDone, OnPrintingDone)
initial.commit09911bf2008-07-26 23:55:29358 IPC_MESSAGE_HANDLER(ViewMsg_Navigate, OnNavigate)
359 IPC_MESSAGE_HANDLER(ViewMsg_Stop, OnStop)
360 IPC_MESSAGE_HANDLER(ViewMsg_LoadAlternateHTMLText, OnLoadAlternateHTMLText)
361 IPC_MESSAGE_HANDLER(ViewMsg_StopFinding, OnStopFinding)
362 IPC_MESSAGE_HANDLER(ViewMsg_Undo, OnUndo)
363 IPC_MESSAGE_HANDLER(ViewMsg_Redo, OnRedo)
364 IPC_MESSAGE_HANDLER(ViewMsg_Cut, OnCut)
365 IPC_MESSAGE_HANDLER(ViewMsg_Copy, OnCopy)
366 IPC_MESSAGE_HANDLER(ViewMsg_Paste, OnPaste)
367 IPC_MESSAGE_HANDLER(ViewMsg_Replace, OnReplace)
[email protected]bbbd545c2008-12-15 20:18:04368 IPC_MESSAGE_HANDLER(ViewMsg_ToggleSpellCheck, OnToggleSpellCheck)
initial.commit09911bf2008-07-26 23:55:29369 IPC_MESSAGE_HANDLER(ViewMsg_Delete, OnDelete)
370 IPC_MESSAGE_HANDLER(ViewMsg_SelectAll, OnSelectAll)
371 IPC_MESSAGE_HANDLER(ViewMsg_CopyImageAt, OnCopyImageAt)
[email protected]4b59ae602009-06-23 20:58:15372 IPC_MESSAGE_HANDLER(ViewMsg_ExecuteEditCommand, OnExecuteEditCommand)
initial.commit09911bf2008-07-26 23:55:29373 IPC_MESSAGE_HANDLER(ViewMsg_Find, OnFind)
[email protected]5c4266922009-07-10 16:41:27374 IPC_MESSAGE_HANDLER(ViewMsg_DeterminePageText, OnDeterminePageText)
[email protected]630e26b2008-10-14 22:55:17375 IPC_MESSAGE_HANDLER(ViewMsg_Zoom, OnZoom)
[email protected]ea8c7452009-04-02 20:47:06376 IPC_MESSAGE_HANDLER(ViewMsg_InsertText, OnInsertText)
initial.commit09911bf2008-07-26 23:55:29377 IPC_MESSAGE_HANDLER(ViewMsg_SetPageEncoding, OnSetPageEncoding)
[email protected]b2abac72009-02-26 12:39:28378 IPC_MESSAGE_HANDLER(ViewMsg_SetupDevToolsClient, OnSetupDevToolsClient)
[email protected]bf5c2ff392009-07-08 16:24:33379 IPC_MESSAGE_HANDLER(ViewMsg_DownloadFavIcon, OnDownloadFavIcon)
initial.commit09911bf2008-07-26 23:55:29380 IPC_MESSAGE_HANDLER(ViewMsg_ScriptEvalRequest, OnScriptEvalRequest)
[email protected]1810e132009-03-24 23:35:48381 IPC_MESSAGE_HANDLER(ViewMsg_CSSInsertRequest, OnCSSInsertRequest)
initial.commit09911bf2008-07-26 23:55:29382 IPC_MESSAGE_HANDLER(ViewMsg_AddMessageToConsole, OnAddMessageToConsole)
initial.commit09911bf2008-07-26 23:55:29383 IPC_MESSAGE_HANDLER(ViewMsg_ReservePageIDRange, OnReservePageIDRange)
384 IPC_MESSAGE_HANDLER(ViewMsg_UploadFile, OnUploadFileRequest)
385 IPC_MESSAGE_HANDLER(ViewMsg_FormFill, OnFormFill)
386 IPC_MESSAGE_HANDLER(ViewMsg_FillPasswordForm, OnFillPasswordForm)
387 IPC_MESSAGE_HANDLER(ViewMsg_DragTargetDragEnter, OnDragTargetDragEnter)
388 IPC_MESSAGE_HANDLER(ViewMsg_DragTargetDragOver, OnDragTargetDragOver)
389 IPC_MESSAGE_HANDLER(ViewMsg_DragTargetDragLeave, OnDragTargetDragLeave)
390 IPC_MESSAGE_HANDLER(ViewMsg_DragTargetDrop, OnDragTargetDrop)
[email protected]18cb2572008-08-21 20:34:45391 IPC_MESSAGE_HANDLER(ViewMsg_AllowBindings, OnAllowBindings)
initial.commit09911bf2008-07-26 23:55:29392 IPC_MESSAGE_HANDLER(ViewMsg_SetDOMUIProperty, OnSetDOMUIProperty)
[email protected]266eb6f2008-09-30 23:56:50393 IPC_MESSAGE_HANDLER(ViewMsg_DragSourceEndedOrMoved,
394 OnDragSourceEndedOrMoved)
initial.commit09911bf2008-07-26 23:55:29395 IPC_MESSAGE_HANDLER(ViewMsg_DragSourceSystemDragEnded,
396 OnDragSourceSystemDragEnded)
397 IPC_MESSAGE_HANDLER(ViewMsg_SetInitialFocus, OnSetInitialFocus)
398 IPC_MESSAGE_HANDLER(ViewMsg_FindReplyACK, OnFindReplyAck)
399 IPC_MESSAGE_HANDLER(ViewMsg_UpdateTargetURL_ACK, OnUpdateTargetURLAck)
400 IPC_MESSAGE_HANDLER(ViewMsg_UpdateWebPreferences, OnUpdateWebPreferences)
401 IPC_MESSAGE_HANDLER(ViewMsg_SetAltErrorPageURL, OnSetAltErrorPageURL)
402 IPC_MESSAGE_HANDLER(ViewMsg_InstallMissingPlugin, OnInstallMissingPlugin)
403 IPC_MESSAGE_HANDLER(ViewMsg_RunFileChooserResponse, OnFileChooserResponse)
404 IPC_MESSAGE_HANDLER(ViewMsg_EnableViewSourceMode, OnEnableViewSourceMode)
405 IPC_MESSAGE_HANDLER(ViewMsg_UpdateBackForwardListCount,
406 OnUpdateBackForwardListCount)
407 IPC_MESSAGE_HANDLER(ViewMsg_GetAllSavableResourceLinksForCurrentPage,
408 OnGetAllSavableResourceLinksForCurrentPage)
[email protected]f09c7182009-03-10 12:54:04409 IPC_MESSAGE_HANDLER(
410 ViewMsg_GetSerializedHtmlDataForCurrentPageWithLocalLinks,
411 OnGetSerializedHtmlDataForCurrentPageWithLocalLinks)
initial.commit09911bf2008-07-26 23:55:29412 IPC_MESSAGE_HANDLER(ViewMsg_GetApplicationInfo, OnGetApplicationInfo)
[email protected]266eb6f2008-09-30 23:56:50413 IPC_MESSAGE_HANDLER(ViewMsg_GetAccessibilityInfo, OnGetAccessibilityInfo)
414 IPC_MESSAGE_HANDLER(ViewMsg_ClearAccessibilityInfo,
415 OnClearAccessibilityInfo)
initial.commit09911bf2008-07-26 23:55:29416 IPC_MESSAGE_HANDLER(ViewMsg_ShouldClose, OnMsgShouldClose)
417 IPC_MESSAGE_HANDLER(ViewMsg_ClosePage, OnClosePage)
418 IPC_MESSAGE_HANDLER(ViewMsg_ThemeChanged, OnThemeChanged)
[email protected]18cb2572008-08-21 20:34:45419 IPC_MESSAGE_HANDLER(ViewMsg_HandleMessageFromExternalHost,
420 OnMessageFromExternalHost)
[email protected]0aa55312008-10-17 21:53:08421 IPC_MESSAGE_HANDLER(ViewMsg_DisassociateFromPopupCount,
422 OnDisassociateFromPopupCount)
[email protected]0ebf3872008-11-07 21:35:03423 IPC_MESSAGE_HANDLER(ViewMsg_AutofillSuggestions,
424 OnReceivedAutofillSuggestions)
[email protected]2c4410d2009-05-06 23:46:22425 IPC_MESSAGE_HANDLER(ViewMsg_PopupNotificationVisibilityChanged,
426 OnPopupNotificationVisibilityChanged)
[email protected]30f75e62009-02-25 22:01:00427 IPC_MESSAGE_HANDLER(ViewMsg_MoveOrResizeStarted, OnMoveOrResizeStarted)
[email protected]309d7a282009-03-24 09:18:27428 IPC_MESSAGE_HANDLER(ViewMsg_ExtensionResponse, OnExtensionResponse)
[email protected]7120f132009-07-20 21:05:37429 IPC_MESSAGE_HANDLER(ViewMsg_ExtensionMessageInvoke,
430 OnExtensionMessageInvoke)
[email protected]05d478752009-04-08 23:38:16431 IPC_MESSAGE_HANDLER(ViewMsg_ClearFocusedNode, OnClearFocusedNode)
[email protected]699ab0d2009-04-23 23:19:14432 IPC_MESSAGE_HANDLER(ViewMsg_SetBackground, OnSetBackground)
[email protected]0666aef2009-05-13 19:48:08433 IPC_MESSAGE_HANDLER(ViewMsg_EnableIntrinsicWidthChangedMode,
434 OnEnableIntrinsicWidthChangedMode)
[email protected]80d96fa2009-06-10 22:34:51435 IPC_MESSAGE_HANDLER(ViewMsg_SetRendererPrefs, OnSetRendererPrefs)
[email protected]7b291f92009-08-14 05:43:53436 IPC_MESSAGE_HANDLER(ViewMsg_UpdateBrowserWindowId,
437 OnUpdateBrowserWindowId)
438 IPC_MESSAGE_HANDLER(ViewMsg_NotifyRenderViewType,
439 OnNotifyRendererViewType)
[email protected]581b87eb2009-07-23 23:06:56440 IPC_MESSAGE_HANDLER(ViewMsg_MediaPlayerActionAt, OnMediaPlayerActionAt)
[email protected]8c66c5a2009-07-22 17:26:34441 IPC_MESSAGE_HANDLER(ViewMsg_SetActive, OnSetActive)
[email protected]634a6f92008-12-01 21:39:31442
initial.commit09911bf2008-07-26 23:55:29443 // Have the super handle all other messages.
444 IPC_MESSAGE_UNHANDLED(RenderWidget::OnMessageReceived(message))
445 IPC_END_MESSAGE_MAP()
446}
447
initial.commit09911bf2008-07-26 23:55:29448void RenderView::SendThumbnail() {
449 WebFrame* main_frame = webview()->GetMainFrame();
450 if (!main_frame)
451 return;
452
453 // get the URL for this page
[email protected]dd7daa82009-08-10 05:46:45454 GURL url(main_frame->url());
initial.commit09911bf2008-07-26 23:55:29455 if (url.is_empty())
456 return;
457
458 if (size_.IsEmpty())
459 return; // Don't create an empty thumbnail!
460
461 ThumbnailScore score;
462 SkBitmap thumbnail;
[email protected]8649fb32009-06-26 17:51:02463 if (!CaptureThumbnail(webview(), kThumbnailWidth, kThumbnailHeight,
[email protected]b6e4bec2008-11-12 01:17:15464 &thumbnail, &score))
465 return;
466
initial.commit09911bf2008-07-26 23:55:29467 // send the thumbnail message to the browser process
[email protected]674741932009-02-04 23:44:46468 Send(new ViewHostMsg_Thumbnail(routing_id_, url, score, thumbnail));
initial.commit09911bf2008-07-26 23:55:29469}
470
[email protected]068637222009-01-29 16:58:07471void RenderView::OnPrintPages() {
initial.commit09911bf2008-07-26 23:55:29472 DCHECK(webview());
[email protected]aa82249f2009-07-16 17:23:58473 if (webview()) {
474 // If the user has selected text in the currently focused frame we print
475 // only that frame (this makes print selection work for multiple frames).
[email protected]dd7daa82009-08-10 05:46:45476 if (webview()->GetFocusedFrame()->hasSelection())
[email protected]aa82249f2009-07-16 17:23:58477 Print(webview()->GetFocusedFrame(), false);
478 else
479 Print(webview()->GetMainFrame(), false);
480 }
initial.commit09911bf2008-07-26 23:55:29481}
482
[email protected]82270452009-06-19 15:58:01483void RenderView::OnPrintingDone(int document_cookie, bool success) {
484 // Ignoring document cookie here since only one print job can be outstanding
485 // per renderer and document_cookie is 0 when printing is successful.
486 DCHECK(print_helper_.get());
487 if (print_helper_.get() != NULL) {
488 print_helper_->DidFinishPrinting(success);
489 }
490}
491
initial.commit09911bf2008-07-26 23:55:29492void RenderView::CapturePageInfo(int load_id, bool preliminary_capture) {
493 if (load_id != page_id_)
494 return; // this capture call is no longer relevant due to navigation
495 if (load_id == last_indexed_page_id_)
496 return; // we already indexed this page
497
498 if (!webview())
499 return;
500
501 WebFrame* main_frame = webview()->GetMainFrame();
502 if (!main_frame)
503 return;
504
505 // Don't index/capture pages that are in view source mode.
[email protected]dd7daa82009-08-10 05:46:45506 if (main_frame->isViewSourceModeEnabled())
initial.commit09911bf2008-07-26 23:55:29507 return;
508
509 // Don't index/capture pages that failed to load. This only checks the top
510 // level frame so the thumbnail may contain a frame that failed to load.
[email protected]dd7daa82009-08-10 05:46:45511 WebDataSource* ds = main_frame->dataSource();
[email protected]726985e22009-06-18 21:09:28512 if (ds && ds->hasUnreachableURL())
initial.commit09911bf2008-07-26 23:55:29513 return;
514
515 if (!preliminary_capture)
516 last_indexed_page_id_ = load_id;
517
518 // get the URL for this page
[email protected]dd7daa82009-08-10 05:46:45519 GURL url(main_frame->url());
initial.commit09911bf2008-07-26 23:55:29520 if (url.is_empty())
521 return;
522
523 // full text
524 std::wstring contents;
525 CaptureText(main_frame, &contents);
526 if (contents.size()) {
527 // Send the text to the browser for indexing.
528 Send(new ViewHostMsg_PageContents(url, load_id, contents));
529 }
530
[email protected]5c4266922009-07-10 16:41:27531 // Send over text content of this page to the browser.
532 if (determine_page_text_after_loading_stops_) {
533 determine_page_text_after_loading_stops_ = false;
534 Send(new ViewMsg_DeterminePageText_Reply(routing_id_, contents));
535 }
536
initial.commit09911bf2008-07-26 23:55:29537 // thumbnail
538 SendThumbnail();
539}
540
541void RenderView::CaptureText(WebFrame* frame, std::wstring* contents) {
542 contents->clear();
543 if (!frame)
544 return;
545
[email protected]0faf0bd92008-09-09 20:53:27546 // Don't index any https pages. People generally don't want their bank
547 // accounts, etc. indexed on their computer, especially since some of these
548 // things are not marked cachable.
549 // TODO(brettw) we may want to consider more elaborate heuristics such as
550 // the cachability of the page. We may also want to consider subframes (this
551 // test will still index subframes if the subframe is SSL).
[email protected]dd7daa82009-08-10 05:46:45552 if (GURL(frame->url()).SchemeIsSecure())
[email protected]0faf0bd92008-09-09 20:53:27553 return;
554
initial.commit09911bf2008-07-26 23:55:29555#ifdef TIME_TEXT_RETRIEVAL
556 double begin = time_util::GetHighResolutionTimeNow();
557#endif
558
559 // get the contents of the frame
[email protected]dd7daa82009-08-10 05:46:45560 *contents = UTF16ToWideHack(frame->contentAsText(kMaxIndexChars));
initial.commit09911bf2008-07-26 23:55:29561
562#ifdef TIME_TEXT_RETRIEVAL
563 double end = time_util::GetHighResolutionTimeNow();
564 char buf[128];
565 sprintf_s(buf, "%d chars retrieved for indexing in %gms\n",
566 contents.size(), (end - begin)*1000);
567 OutputDebugStringA(buf);
568#endif
569
570 // When the contents are clipped to the maximum, we don't want to have a
571 // partial word indexed at the end that might have been clipped. Therefore,
572 // terminate the string at the last space to ensure no words are clipped.
573 if (contents->size() == kMaxIndexChars) {
574 size_t last_space_index = contents->find_last_of(kWhitespaceWide);
575 if (last_space_index == std::wstring::npos)
576 return; // don't index if we got a huge block of text with no spaces
577 contents->resize(last_space_index);
578 }
579}
580
[email protected]8649fb32009-06-26 17:51:02581bool RenderView::CaptureThumbnail(WebView* view,
initial.commit09911bf2008-07-26 23:55:29582 int w,
583 int h,
584 SkBitmap* thumbnail,
585 ThumbnailScore* score) {
586#ifdef TIME_BITMAP_RETRIEVAL
587 double begin = time_util::GetHighResolutionTimeNow();
588#endif
589
[email protected]4873c7d2009-07-16 06:36:28590 view->layout();
591 const WebSize& size = view->size();
[email protected]b6e4bec2008-11-12 01:17:15592
[email protected]8649fb32009-06-26 17:51:02593 skia::PlatformCanvas canvas;
594 if (!canvas.initialize(size.width, size.height, true))
595 return false;
[email protected]4873c7d2009-07-16 06:36:28596 view->paint(&canvas, WebRect(0, 0, size.width, size.height));
[email protected]8649fb32009-06-26 17:51:02597
598 skia::BitmapPlatformDevice& device =
599 static_cast<skia::BitmapPlatformDevice&>(canvas.getTopPlatformDevice());
600
601 const SkBitmap& src_bmp = device.accessBitmap(false);
initial.commit09911bf2008-07-26 23:55:29602
603 SkRect dest_rect;
604 dest_rect.set(0, 0, SkIntToScalar(w), SkIntToScalar(h));
605 float dest_aspect = dest_rect.width() / dest_rect.height();
606
607 // Get the src rect so that we can preserve the aspect ratio while filling
608 // the destination.
609 SkIRect src_rect;
610 if (src_bmp.width() < dest_rect.width() ||
611 src_bmp.height() < dest_rect.height()) {
612 // Source image is smaller: we clip the part of source image within the
613 // dest rect, and then stretch it to fill the dest rect. We don't respect
614 // the aspect ratio in this case.
615 src_rect.set(0, 0, static_cast<S16CPU>(dest_rect.width()),
616 static_cast<S16CPU>(dest_rect.height()));
617 score->good_clipping = false;
618 } else {
619 float src_aspect = static_cast<float>(src_bmp.width()) / src_bmp.height();
620 if (src_aspect > dest_aspect) {
621 // Wider than tall, clip horizontally: we center the smaller thumbnail in
622 // the wider screen.
623 S16CPU new_width = static_cast<S16CPU>(src_bmp.height() * dest_aspect);
624 S16CPU x_offset = (src_bmp.width() - new_width) / 2;
625 src_rect.set(x_offset, 0, new_width + x_offset, src_bmp.height());
626 score->good_clipping = false;
627 } else {
628 src_rect.set(0, 0, src_bmp.width(),
629 static_cast<S16CPU>(src_bmp.width() / dest_aspect));
630 score->good_clipping = true;
631 }
632 }
633
[email protected]dd7daa82009-08-10 05:46:45634 score->at_top = (view->GetMainFrame()->scrollOffset().height == 0);
initial.commit09911bf2008-07-26 23:55:29635
636 SkBitmap subset;
[email protected]8649fb32009-06-26 17:51:02637 device.accessBitmap(false).extractSubset(&subset, src_rect);
initial.commit09911bf2008-07-26 23:55:29638
639 // Resample the subset that we want to get it the right size.
[email protected]465b34b72008-12-12 20:19:14640 *thumbnail = skia::ImageOperations::Resize(
641 subset, skia::ImageOperations::RESIZE_LANCZOS3, w, h);
initial.commit09911bf2008-07-26 23:55:29642
643 score->boring_score = CalculateBoringScore(thumbnail);
644
645#ifdef TIME_BITMAP_RETRIEVAL
646 double end = time_util::GetHighResolutionTimeNow();
647 char buf[128];
648 sprintf_s(buf, "thumbnail in %gms\n", (end - begin) * 1000);
649 OutputDebugStringA(buf);
650#endif
[email protected]b6e4bec2008-11-12 01:17:15651 return true;
initial.commit09911bf2008-07-26 23:55:29652}
653
654double RenderView::CalculateBoringScore(SkBitmap* bitmap) {
655 int histogram[256] = {0};
656 color_utils::BuildLumaHistogram(bitmap, histogram);
657
658 int color_count = *std::max_element(histogram, histogram + 256);
659 int pixel_count = bitmap->width() * bitmap->height();
660 return static_cast<double>(color_count) / pixel_count;
661}
662
663void RenderView::OnNavigate(const ViewMsg_Navigate_Params& params) {
664 if (!webview())
665 return;
666
[email protected]8c785c62009-07-13 14:20:15667 if (devtools_agent_.get())
668 devtools_agent_->OnNavigate();
669
[email protected]ef916272009-07-08 21:40:55670 child_process_logging::ScopedActiveURLSetter url_setter(params.url);
[email protected]f8b6b6f2009-03-10 16:48:26671
initial.commit09911bf2008-07-26 23:55:29672 AboutHandler::MaybeHandle(params.url);
673
674 bool is_reload = params.reload;
675
676 WebFrame* main_frame = webview()->GetMainFrame();
[email protected]dd7daa82009-08-10 05:46:45677 if (is_reload && main_frame->currentHistoryItem().isNull()) {
initial.commit09911bf2008-07-26 23:55:29678 // We cannot reload if we do not have any history state. This happens, for
679 // example, when recovering from a crash. Our workaround here is a bit of
680 // a hack since it means that reload after a crashed tab does not cause an
681 // end-to-end cache validation.
682 is_reload = false;
683 }
684
[email protected]77f17a82009-05-21 04:42:54685 // A navigation resulting from loading a javascript URL should not be treated
686 // as a browser initiated event. Instead, we want it to look as if the page
687 // initiated any load resulting from JS execution.
688 if (!params.url.SchemeIs(chrome::kJavaScriptScheme)) {
[email protected]daa8c58e2009-06-15 17:21:10689 pending_navigation_state_.reset(NavigationState::CreateBrowserInitiated(
[email protected]77f17a82009-05-21 04:42:54690 params.page_id, params.transition, params.request_time));
691 }
initial.commit09911bf2008-07-26 23:55:29692
[email protected]04d3c6e2009-05-22 17:00:13693 // If we are reloading, then WebKit will use the history state of the current
694 // page, so we should just ignore any given history state. Otherwise, if we
695 // have history state, then we need to navigate to it, which corresponds to a
696 // back/forward navigation event.
[email protected]e6f546c32009-07-01 17:12:55697 if (is_reload) {
[email protected]dd7daa82009-08-10 05:46:45698 main_frame->reload();
[email protected]e6f546c32009-07-01 17:12:55699 } else if (!params.state.empty()) {
[email protected]04d3c6e2009-05-22 17:00:13700 // We must know the page ID of the page we are navigating back to.
[email protected]f929f2f22009-06-12 16:56:58701 DCHECK_NE(params.page_id, -1);
[email protected]dd7daa82009-08-10 05:46:45702 main_frame->loadHistoryItem(
[email protected]ca948a22009-06-25 19:36:17703 webkit_glue::HistoryItemFromString(params.state));
[email protected]04d3c6e2009-05-22 17:00:13704 } else {
705 // Navigate to the given URL.
[email protected]726985e22009-06-18 21:09:28706 WebURLRequest request(params.url);
initial.commit09911bf2008-07-26 23:55:29707
[email protected]e6f546c32009-07-01 17:12:55708 // A session history navigation should have been accompanied by state.
709 DCHECK_EQ(params.page_id, -1);
[email protected]04d3c6e2009-05-22 17:00:13710
[email protected]dd7daa82009-08-10 05:46:45711 if (main_frame->isViewSourceModeEnabled())
[email protected]e6f546c32009-07-01 17:12:55712 request.setCachePolicy(WebURLRequest::ReturnCacheDataElseLoad);
[email protected]04d3c6e2009-05-22 17:00:13713
[email protected]726985e22009-06-18 21:09:28714 if (params.referrer.is_valid()) {
715 request.setHTTPHeaderField(WebString::fromUTF8("Referer"),
716 WebString::fromUTF8(params.referrer.spec()));
717 }
[email protected]04d3c6e2009-05-22 17:00:13718
[email protected]dd7daa82009-08-10 05:46:45719 main_frame->loadRequest(request);
[email protected]c0588052008-10-27 23:01:50720 }
721
[email protected]77f17a82009-05-21 04:42:54722 // In case LoadRequest failed before DidCreateDataSource was called.
723 pending_navigation_state_.reset();
initial.commit09911bf2008-07-26 23:55:29724}
725
726// Stop loading the current page
727void RenderView::OnStop() {
728 if (webview())
729 webview()->StopLoading();
730}
731
[email protected]e6f546c32009-07-01 17:12:55732void RenderView::OnLoadAlternateHTMLText(const std::string& html,
initial.commit09911bf2008-07-26 23:55:29733 bool new_navigation,
734 const GURL& display_url,
735 const std::string& security_info) {
736 if (!webview())
737 return;
738
[email protected]e6f546c32009-07-01 17:12:55739 pending_navigation_state_.reset(NavigationState::CreateBrowserInitiated(
740 new_navigation ? -1 : page_id_, PageTransition::LINK, Time::Now()));
741 pending_navigation_state_->set_security_info(security_info);
initial.commit09911bf2008-07-26 23:55:29742
[email protected]dd7daa82009-08-10 05:46:45743 webview()->GetMainFrame()->loadHTMLString(html,
[email protected]e6f546c32009-07-01 17:12:55744 GURL(kUnreachableWebDataURL),
745 display_url,
746 !new_navigation);
747
748 pending_navigation_state_.reset();
initial.commit09911bf2008-07-26 23:55:29749}
750
751void RenderView::OnCopyImageAt(int x, int y) {
752 webview()->CopyImageAt(x, y);
753}
754
[email protected]68b1e922009-06-23 16:00:25755void RenderView::OnExecuteEditCommand(const std::string& name,
756 const std::string& value) {
757 if (!webview() || !webview()->GetFocusedFrame())
758 return;
759
[email protected]dd7daa82009-08-10 05:46:45760 webview()->GetFocusedFrame()->executeCommand(
761 WebString::fromUTF8(name), WebString::fromUTF8(value));
[email protected]68b1e922009-06-23 16:00:25762}
763
[email protected]b2abac72009-02-26 12:39:28764void RenderView::OnSetupDevToolsClient() {
[email protected]e4ac5df2009-03-17 15:33:11765 DCHECK(!devtools_client_.get());
766 devtools_client_.reset(new DevToolsClient(this));
[email protected]b2abac72009-02-26 12:39:28767}
768
initial.commit09911bf2008-07-26 23:55:29769void RenderView::OnStopFinding(bool clear_selection) {
770 WebView* view = webview();
771 if (!view)
772 return;
773
774 if (clear_selection)
[email protected]a100d76bb2009-08-14 17:50:22775 view->GetFocusedFrame()->executeCommand(WebString::fromUTF8("Unselect"));
initial.commit09911bf2008-07-26 23:55:29776
777 WebFrame* frame = view->GetMainFrame();
778 while (frame) {
[email protected]dd7daa82009-08-10 05:46:45779 frame->stopFinding(clear_selection);
initial.commit09911bf2008-07-26 23:55:29780 frame = view->GetNextFrameAfter(frame, false);
781 }
782}
783
784void RenderView::OnFindReplyAck() {
785 // Check if there is any queued up request waiting to be sent.
786 if (queued_find_reply_message_.get()) {
787 // Send the search result over to the browser process.
788 Send(queued_find_reply_message_.get());
789 queued_find_reply_message_.release();
790 }
791}
792
793void RenderView::OnUpdateTargetURLAck() {
794 // Check if there is a targeturl waiting to be sent.
795 if (target_url_status_ == TARGET_PENDING) {
796 Send(new ViewHostMsg_UpdateTargetURL(routing_id_, page_id_,
797 pending_target_url_));
798 }
799
800 target_url_status_ = TARGET_NONE;
801}
802
803void RenderView::OnUndo() {
804 if (!webview())
805 return;
806
[email protected]dd7daa82009-08-10 05:46:45807 webview()->GetFocusedFrame()->executeCommand(WebString::fromUTF8("Undo"));
808 UserMetricsRecordAction(L"Undo");
initial.commit09911bf2008-07-26 23:55:29809}
810
811void RenderView::OnRedo() {
812 if (!webview())
813 return;
814
[email protected]dd7daa82009-08-10 05:46:45815 webview()->GetFocusedFrame()->executeCommand(WebString::fromUTF8("Redo"));
816 UserMetricsRecordAction(L"Redo");
initial.commit09911bf2008-07-26 23:55:29817}
818
819void RenderView::OnCut() {
820 if (!webview())
821 return;
822
[email protected]dd7daa82009-08-10 05:46:45823 webview()->GetFocusedFrame()->executeCommand(WebString::fromUTF8("Cut"));
824 UserMetricsRecordAction(L"Cut");
initial.commit09911bf2008-07-26 23:55:29825}
826
827void RenderView::OnCopy() {
828 if (!webview())
829 return;
830
[email protected]dd7daa82009-08-10 05:46:45831 webview()->GetFocusedFrame()->executeCommand(WebString::fromUTF8("Copy"));
832 UserMetricsRecordAction(L"Copy");
initial.commit09911bf2008-07-26 23:55:29833}
834
835void RenderView::OnPaste() {
836 if (!webview())
837 return;
838
[email protected]dd7daa82009-08-10 05:46:45839 webview()->GetFocusedFrame()->executeCommand(WebString::fromUTF8("Paste"));
840 UserMetricsRecordAction(L"Paste");
initial.commit09911bf2008-07-26 23:55:29841}
842
843void RenderView::OnReplace(const std::wstring& text) {
844 if (!webview())
845 return;
846
[email protected]dd7daa82009-08-10 05:46:45847 webview()->GetFocusedFrame()->replaceSelection(WideToUTF16Hack(text));
initial.commit09911bf2008-07-26 23:55:29848}
849
[email protected]bbbd545c2008-12-15 20:18:04850void RenderView::OnToggleSpellCheck() {
851 if (!webview())
852 return;
853
[email protected]dd7daa82009-08-10 05:46:45854 WebFrame* frame = webview()->GetFocusedFrame();
855 frame->enableContinuousSpellChecking(
856 !frame->isContinuousSpellCheckingEnabled());
[email protected]bbbd545c2008-12-15 20:18:04857}
858
initial.commit09911bf2008-07-26 23:55:29859void RenderView::OnDelete() {
860 if (!webview())
861 return;
862
[email protected]dd7daa82009-08-10 05:46:45863 webview()->GetFocusedFrame()->executeCommand(WebString::fromUTF8("Delete"));
864 UserMetricsRecordAction(L"DeleteSelection");
initial.commit09911bf2008-07-26 23:55:29865}
866
867void RenderView::OnSelectAll() {
868 if (!webview())
869 return;
870
[email protected]a100d76bb2009-08-14 17:50:22871 webview()->GetFocusedFrame()->executeCommand(
872 WebString::fromUTF8("SelectAll"));
873 UserMetricsRecordAction(L"SelectAll");
initial.commit09911bf2008-07-26 23:55:29874}
875
876void RenderView::OnSetInitialFocus(bool reverse) {
877 if (!webview())
878 return;
879 webview()->SetInitialFocus(reverse);
880}
881
882///////////////////////////////////////////////////////////////////////////////
883
884// Tell the embedding application that the URL of the active page has changed
885void RenderView::UpdateURL(WebFrame* frame) {
[email protected]dd7daa82009-08-10 05:46:45886 WebDataSource* ds = frame->dataSource();
initial.commit09911bf2008-07-26 23:55:29887 DCHECK(ds);
888
[email protected]726985e22009-06-18 21:09:28889 const WebURLRequest& request = ds->request();
890 const WebURLRequest& original_request = ds->originalRequest();
891 const WebURLResponse& response = ds->response();
initial.commit09911bf2008-07-26 23:55:29892
[email protected]daa8c58e2009-06-15 17:21:10893 NavigationState* navigation_state = NavigationState::FromDataSource(ds);
894 DCHECK(navigation_state);
initial.commit09911bf2008-07-26 23:55:29895
896 ViewHostMsg_FrameNavigate_Params params;
[email protected]726985e22009-06-18 21:09:28897 params.http_status_code = response.httpStatusCode();
initial.commit09911bf2008-07-26 23:55:29898 params.is_post = false;
899 params.page_id = page_id_;
[email protected]726985e22009-06-18 21:09:28900 params.is_content_filtered = response.isContentFiltered();
[email protected]e6f546c32009-07-01 17:12:55901 if (!navigation_state->security_info().empty()) {
initial.commit09911bf2008-07-26 23:55:29902 // SSL state specified in the request takes precedence over the one in the
903 // response.
904 // So far this is only intended for error pages that are not expected to be
905 // over ssl, so we should not get any clash.
[email protected]726985e22009-06-18 21:09:28906 DCHECK(response.securityInfo().isEmpty());
[email protected]e6f546c32009-07-01 17:12:55907 params.security_info = navigation_state->security_info();
initial.commit09911bf2008-07-26 23:55:29908 } else {
[email protected]726985e22009-06-18 21:09:28909 params.security_info = response.securityInfo();
initial.commit09911bf2008-07-26 23:55:29910 }
911
912 // Set the URL to be displayed in the browser UI to the user.
[email protected]726985e22009-06-18 21:09:28913 if (ds->hasUnreachableURL()) {
914 params.url = ds->unreachableURL();
initial.commit09911bf2008-07-26 23:55:29915 } else {
[email protected]726985e22009-06-18 21:09:28916 params.url = request.url();
initial.commit09911bf2008-07-26 23:55:29917 }
918
[email protected]726985e22009-06-18 21:09:28919 GetRedirectChain(ds, &params.redirects);
920 params.should_update_history = !ds->hasUnreachableURL();
initial.commit09911bf2008-07-26 23:55:29921
922 const SearchableFormData* searchable_form_data =
[email protected]daa8c58e2009-06-15 17:21:10923 navigation_state->searchable_form_data();
initial.commit09911bf2008-07-26 23:55:29924 if (searchable_form_data) {
925 params.searchable_form_url = searchable_form_data->url();
926 params.searchable_form_element_name = searchable_form_data->element_name();
927 params.searchable_form_encoding = searchable_form_data->encoding();
928 }
929
930 const PasswordForm* password_form_data =
[email protected]daa8c58e2009-06-15 17:21:10931 navigation_state->password_form_data();
initial.commit09911bf2008-07-26 23:55:29932 if (password_form_data)
933 params.password_form = *password_form_data;
934
935 params.gesture = navigation_gesture_;
936 navigation_gesture_ = NavigationGestureUnknown;
937
[email protected]dd7daa82009-08-10 05:46:45938 if (!frame->parent()) {
initial.commit09911bf2008-07-26 23:55:29939 // Top-level navigation.
940
941 // Update contents MIME type for main frame.
[email protected]9c5645b2009-08-11 03:37:55942 params.contents_mime_type = ds->response().mimeType().utf8();
initial.commit09911bf2008-07-26 23:55:29943
[email protected]daa8c58e2009-06-15 17:21:10944 params.transition = navigation_state->transition_type();
initial.commit09911bf2008-07-26 23:55:29945 if (!PageTransition::IsMainFrame(params.transition)) {
946 // If the main frame does a load, it should not be reported as a subframe
947 // navigation. This can occur in the following case:
948 // 1. You're on a site with frames.
949 // 2. You do a subframe navigation. This is stored with transition type
950 // MANUAL_SUBFRAME.
951 // 3. You navigate to some non-frame site, say, google.com.
952 // 4. You navigate back to the page from step 2. Since it was initially
953 // MANUAL_SUBFRAME, it will be that same transition type here.
954 // We don't want that, because any navigation that changes the toplevel
955 // frame should be tracked as a toplevel navigation (this allows us to
956 // update the URL bar, etc).
957 params.transition = PageTransition::LINK;
958 }
959
initial.commit09911bf2008-07-26 23:55:29960 // If we have a valid consumed client redirect source,
961 // the page contained a client redirect (meta refresh, document.loc...),
962 // so we set the referrer and transition to match.
963 if (completed_client_redirect_src_.is_valid()) {
[email protected]77e09a92008-08-01 18:11:04964 DCHECK(completed_client_redirect_src_ == params.redirects[0]);
initial.commit09911bf2008-07-26 23:55:29965 params.referrer = completed_client_redirect_src_;
966 params.transition = static_cast<PageTransition::Type>(
967 params.transition | PageTransition::CLIENT_REDIRECT);
968 } else {
969 // Bug 654101: the referrer will be empty on https->http transitions. It
970 // would be nice if we could get the real referrer from somewhere.
[email protected]726985e22009-06-18 21:09:28971 params.referrer = GURL(
972 original_request.httpHeaderField(WebString::fromUTF8("Referer")));
initial.commit09911bf2008-07-26 23:55:29973 }
974
[email protected]726985e22009-06-18 21:09:28975 string16 method = request.httpMethod();
976 if (EqualsASCII(method, "POST"))
initial.commit09911bf2008-07-26 23:55:29977 params.is_post = true;
978
979 Send(new ViewHostMsg_FrameNavigate(routing_id_, params));
980 } else {
981 // Subframe navigation: the type depends on whether this navigation
982 // generated a new session history entry. When they do generate a session
983 // history entry, it means the user initiated the navigation and we should
984 // mark it as such. This test checks if this is the first time UpdateURL
985 // has been called since WillNavigateToURL was called to initiate the load.
986 if (page_id_ > last_page_id_sent_to_browser_)
987 params.transition = PageTransition::MANUAL_SUBFRAME;
988 else
989 params.transition = PageTransition::AUTO_SUBFRAME;
990
initial.commit09911bf2008-07-26 23:55:29991 Send(new ViewHostMsg_FrameNavigate(routing_id_, params));
992 }
993
994 last_page_id_sent_to_browser_ =
995 std::max(last_page_id_sent_to_browser_, page_id_);
996
997 // If we end up reusing this WebRequest (for example, due to a #ref click),
[email protected]daa8c58e2009-06-15 17:21:10998 // we don't want the transition type to persist. Just clear it.
999 navigation_state->set_transition_type(PageTransition::LINK);
[email protected]266eb6f2008-09-30 23:56:501000
[email protected]6c8afae52009-01-22 02:24:571001#if defined(OS_WIN)
[email protected]6a983b42009-03-20 20:12:251002 if (web_accessibility_manager_.get()) {
[email protected]be645db2009-02-06 20:36:331003 // Clear accessibility info cache.
[email protected]6a983b42009-03-20 20:12:251004 web_accessibility_manager_->ClearAccObjMap(-1, true);
[email protected]266eb6f2008-09-30 23:56:501005 }
[email protected]6c8afae52009-01-22 02:24:571006#else
[email protected]7d926f92009-03-03 14:26:541007 // TODO(port): accessibility not yet implemented. See http://crbug.com/8288.
[email protected]6c8afae52009-01-22 02:24:571008#endif
initial.commit09911bf2008-07-26 23:55:291009}
1010
1011// Tell the embedding application that the title of the active page has changed
1012void RenderView::UpdateTitle(WebFrame* frame, const std::wstring& title) {
1013 // Ignore all but top level navigations...
[email protected]f0af6a72009-05-30 05:25:171014 if (webview()->GetMainFrame() == frame) {
1015 Send(new ViewHostMsg_UpdateTitle(
1016 routing_id_,
1017 page_id_,
1018 title.length() > chrome::kMaxTitleChars ?
1019 title.substr(0, chrome::kMaxTitleChars) : title));
1020 }
initial.commit09911bf2008-07-26 23:55:291021}
1022
1023void RenderView::UpdateEncoding(WebFrame* frame,
[email protected]e38f40152008-09-12 23:08:301024 const std::wstring& encoding_name) {
initial.commit09911bf2008-07-26 23:55:291025 // Only update main frame's encoding_name.
1026 if (webview()->GetMainFrame() == frame &&
1027 last_encoding_name_ != encoding_name) {
[email protected]e38f40152008-09-12 23:08:301028 // Save the encoding name for later comparing.
initial.commit09911bf2008-07-26 23:55:291029 last_encoding_name_ = encoding_name;
1030
[email protected]e38f40152008-09-12 23:08:301031 Send(new ViewHostMsg_UpdateEncoding(routing_id_, last_encoding_name_));
initial.commit09911bf2008-07-26 23:55:291032 }
1033}
1034
[email protected]f4d34b52008-11-24 23:05:011035// Sends the previous session history state to the browser so it will be saved
1036// before we navigate to a new page. This must be called *before* the page ID
1037// has been updated so we know what it was.
initial.commit09911bf2008-07-26 23:55:291038void RenderView::UpdateSessionHistory(WebFrame* frame) {
1039 // If we have a valid page ID at this point, then it corresponds to the page
1040 // we are navigating away from. Otherwise, this is the first navigation, so
1041 // there is no past session history to record.
1042 if (page_id_ == -1)
1043 return;
1044
[email protected]ca948a22009-06-25 19:36:171045 const WebHistoryItem& item =
[email protected]dd7daa82009-08-10 05:46:451046 webview()->GetMainFrame()->previousHistoryItem();
[email protected]ca948a22009-06-25 19:36:171047 if (item.isNull())
initial.commit09911bf2008-07-26 23:55:291048 return;
[email protected]ca948a22009-06-25 19:36:171049
1050 Send(new ViewHostMsg_UpdateState(
1051 routing_id_, page_id_, webkit_glue::HistoryItemToString(item)));
initial.commit09911bf2008-07-26 23:55:291052}
1053
1054///////////////////////////////////////////////////////////////////////////////
1055// WebViewDelegate
1056
[email protected]80d96fa2009-06-10 22:34:511057bool RenderView::CanAcceptLoadDrops() const {
1058 return renderer_preferences_.can_accept_load_drops;
1059}
1060
initial.commit09911bf2008-07-26 23:55:291061void RenderView::DidStartLoading(WebView* webview) {
1062 if (is_loading_) {
1063 DLOG(WARNING) << "DidStartLoading called while loading";
1064 return;
1065 }
1066
1067 is_loading_ = true;
1068 // Clear the pointer so that we can assign it only when there is an unknown
1069 // plugin on a page.
1070 first_default_plugin_ = NULL;
1071
[email protected]329581b2009-04-28 06:52:351072 Send(new ViewHostMsg_DidStartLoading(routing_id_));
initial.commit09911bf2008-07-26 23:55:291073}
1074
1075void RenderView::DidStopLoading(WebView* webview) {
1076 if (!is_loading_) {
1077 DLOG(WARNING) << "DidStopLoading called while not loading";
1078 return;
1079 }
1080
1081 is_loading_ = false;
1082
1083 // NOTE: For now we're doing the safest thing, and sending out notification
1084 // when done loading. This currently isn't an issue as the favicon is only
1085 // displayed when done loading. Ideally we would send notification when
1086 // finished parsing the head, but webkit doesn't support that yet.
1087 // The feed discovery code would also benefit from access to the head.
[email protected]dd7daa82009-08-10 05:46:451088 GURL favicon_url(webview->GetMainFrame()->favIconURL());
initial.commit09911bf2008-07-26 23:55:291089 if (!favicon_url.is_empty())
1090 Send(new ViewHostMsg_UpdateFavIconURL(routing_id_, page_id_, favicon_url));
1091
[email protected]dd7daa82009-08-10 05:46:451092 AddGURLSearchProvider(webview->GetMainFrame()->openSearchDescriptionURL(),
initial.commit09911bf2008-07-26 23:55:291093 true); // autodetected
1094
[email protected]329581b2009-04-28 06:52:351095 Send(new ViewHostMsg_DidStopLoading(routing_id_));
initial.commit09911bf2008-07-26 23:55:291096
1097 MessageLoop::current()->PostDelayedTask(FROM_HERE,
1098 method_factory_.NewRunnableMethod(&RenderView::CapturePageInfo, page_id_,
1099 false),
1100 kDelayForCaptureMs);
1101
1102 // The page is loaded. Try to process the file we need to upload if any.
1103 ProcessPendingUpload();
1104
1105 // Since the page is done loading, we are sure we don't need to try
1106 // again.
1107 ResetPendingUpload();
1108}
1109
[email protected]77f17a82009-05-21 04:42:541110void RenderView::DidCreateDataSource(WebFrame* frame, WebDataSource* ds) {
[email protected]daa8c58e2009-06-15 17:21:101111 // The rest of RenderView assumes that a WebDataSource will always have a
1112 // non-null NavigationState.
1113 if (pending_navigation_state_.get()) {
[email protected]726985e22009-06-18 21:09:281114 ds->setExtraData(pending_navigation_state_.release());
[email protected]daa8c58e2009-06-15 17:21:101115 } else {
[email protected]726985e22009-06-18 21:09:281116 ds->setExtraData(NavigationState::CreateContentInitiated());
[email protected]daa8c58e2009-06-15 17:21:101117 }
[email protected]77f17a82009-05-21 04:42:541118}
1119
[email protected]a2f6bc112009-06-27 16:27:251120void RenderView::DidPaint() {
1121 WebFrame* main_frame = webview()->GetMainFrame();
1122
[email protected]dd7daa82009-08-10 05:46:451123 if (main_frame->provisionalDataSource()) {
[email protected]a2f6bc112009-06-27 16:27:251124 // If we have a provisional frame we are between the start
1125 // and commit stages of loading...ignore this paint.
1126 return;
1127 }
1128
[email protected]dd7daa82009-08-10 05:46:451129 WebDataSource* ds = main_frame->dataSource();
[email protected]a2f6bc112009-06-27 16:27:251130 NavigationState* navigation_state = NavigationState::FromDataSource(ds);
[email protected]78a3a6f2009-07-02 16:15:011131 DCHECK(navigation_state);
1132
1133 Time now = Time::Now();
1134 if (navigation_state->first_paint_time().is_null()) {
1135 navigation_state->set_first_paint_time(now);
1136 }
1137 if (navigation_state->first_paint_after_load_time().is_null() &&
1138 !navigation_state->finish_load_time().is_null()) {
1139 navigation_state->set_first_paint_after_load_time(now);
[email protected]a2f6bc112009-06-27 16:27:251140 }
1141}
1142
initial.commit09911bf2008-07-26 23:55:291143void RenderView::DidStartProvisionalLoadForFrame(
1144 WebView* webview,
1145 WebFrame* frame,
1146 NavigationGesture gesture) {
[email protected]dd7daa82009-08-10 05:46:451147 WebDataSource* ds = frame->provisionalDataSource();
[email protected]ed3fb032009-06-16 19:50:561148 NavigationState* navigation_state = NavigationState::FromDataSource(ds);
1149
1150 navigation_state->set_start_load_time(Time::Now());
1151
1152 // Update the request time if WebKit has better knowledge of it.
1153 if (navigation_state->request_time().is_null()) {
[email protected]726985e22009-06-18 21:09:281154 double event_time = ds->triggeringEventTime();
[email protected]ed3fb032009-06-16 19:50:561155 if (event_time != 0.0)
1156 navigation_state->set_request_time(Time::FromDoubleT(event_time));
1157 }
1158
[email protected]dd7daa82009-08-10 05:46:451159 bool is_top_most = !frame->parent();
[email protected]ed3fb032009-06-16 19:50:561160 if (is_top_most) {
initial.commit09911bf2008-07-26 23:55:291161 navigation_gesture_ = gesture;
[email protected]266eb6f2008-09-30 23:56:501162
[email protected]77e09a92008-08-01 18:11:041163 // Make sure redirect tracking state is clear for the new load.
1164 completed_client_redirect_src_ = GURL();
[email protected]dd7daa82009-08-10 05:46:451165 } else if (frame->parent()->isLoading()) {
[email protected]15d79e12009-08-02 19:23:451166 // Take note of AUTO_SUBFRAME loads here, so that we can know how to
1167 // load an error page. See DidFailProvisionalLoadWithError.
1168 navigation_state->set_transition_type(PageTransition::AUTO_SUBFRAME);
[email protected]77e09a92008-08-01 18:11:041169 }
initial.commit09911bf2008-07-26 23:55:291170
1171 Send(new ViewHostMsg_DidStartProvisionalLoadForFrame(
[email protected]726985e22009-06-18 21:09:281172 routing_id_, is_top_most, ds->request().url()));
initial.commit09911bf2008-07-26 23:55:291173}
1174
1175bool RenderView::DidLoadResourceFromMemoryCache(WebView* webview,
[email protected]726985e22009-06-18 21:09:281176 const WebURLRequest& request,
1177 const WebURLResponse& response,
initial.commit09911bf2008-07-26 23:55:291178 WebFrame* frame) {
1179 // Let the browser know we loaded a resource from the memory cache. This
1180 // message is needed to display the correct SSL indicators.
[email protected]dd7daa82009-08-10 05:46:451181 Send(new ViewHostMsg_DidLoadResourceFromMemoryCache(
1182 routing_id_,
1183 request.url(),
1184 frame->securityOrigin().utf8(),
1185 frame->top()->securityOrigin().utf8(),
[email protected]726985e22009-06-18 21:09:281186 response.securityInfo()));
initial.commit09911bf2008-07-26 23:55:291187
1188 return false;
1189}
1190
1191void RenderView::DidReceiveProvisionalLoadServerRedirect(WebView* webview,
1192 WebFrame* frame) {
1193 if (frame == webview->GetMainFrame()) {
1194 // Received a redirect on the main frame.
1195 WebDataSource* data_source =
[email protected]dd7daa82009-08-10 05:46:451196 webview->GetMainFrame()->provisionalDataSource();
initial.commit09911bf2008-07-26 23:55:291197 if (!data_source) {
1198 // Should only be invoked when we have a data source.
1199 NOTREACHED();
1200 return;
1201 }
[email protected]726985e22009-06-18 21:09:281202 std::vector<GURL> redirects;
1203 GetRedirectChain(data_source, &redirects);
initial.commit09911bf2008-07-26 23:55:291204 if (redirects.size() >= 2) {
1205 Send(new ViewHostMsg_DidRedirectProvisionalLoad(
1206 routing_id_, page_id_, redirects[redirects.size() - 2],
1207 redirects[redirects.size() - 1]));
1208 }
1209 }
1210}
1211
1212void RenderView::DidFailProvisionalLoadWithError(WebView* webview,
[email protected]726985e22009-06-18 21:09:281213 const WebURLError& error,
initial.commit09911bf2008-07-26 23:55:291214 WebFrame* frame) {
1215 // Notify the browser that we failed a provisional load with an error.
1216 //
1217 // Note: It is important this notification occur before DidStopLoading so the
1218 // SSL manager can react to the provisional load failure before being
1219 // notified the load stopped.
1220 //
[email protected]dd7daa82009-08-10 05:46:451221 WebDataSource* ds = frame->provisionalDataSource();
initial.commit09911bf2008-07-26 23:55:291222 DCHECK(ds);
1223
[email protected]726985e22009-06-18 21:09:281224 const WebURLRequest& failed_request = ds->request();
initial.commit09911bf2008-07-26 23:55:291225
1226 bool show_repost_interstitial =
[email protected]726985e22009-06-18 21:09:281227 (error.reason == net::ERR_CACHE_MISS &&
1228 EqualsASCII(failed_request.httpMethod(), "POST"));
initial.commit09911bf2008-07-26 23:55:291229 Send(new ViewHostMsg_DidFailProvisionalLoadWithError(
[email protected]dd7daa82009-08-10 05:46:451230 routing_id_, !frame->parent(), error.reason, error.unreachableURL,
initial.commit09911bf2008-07-26 23:55:291231 show_repost_interstitial));
1232
initial.commit09911bf2008-07-26 23:55:291233 // Don't display an error page if this is simply a cancelled load. Aside
1234 // from being dumb, WebCore doesn't expect it and it will cause a crash.
[email protected]726985e22009-06-18 21:09:281235 if (error.reason == net::ERR_ABORTED)
initial.commit09911bf2008-07-26 23:55:291236 return;
1237
[email protected]546ddd172009-06-25 00:25:011238 // Make sure we never show errors in view source mode.
[email protected]dd7daa82009-08-10 05:46:451239 frame->enableViewSourceMode(false);
[email protected]546ddd172009-06-25 00:25:011240
[email protected]15d79e12009-08-02 19:23:451241 NavigationState* navigation_state = NavigationState::FromDataSource(ds);
1242
initial.commit09911bf2008-07-26 23:55:291243 // If this is a failed back/forward/reload navigation, then we need to do a
1244 // 'replace' load. This is necessary to avoid messing up session history.
1245 // Otherwise, we do a normal load, which simulates a 'go' navigation as far
1246 // as session history is concerned.
[email protected]15d79e12009-08-02 19:23:451247 //
1248 // AUTO_SUBFRAME loads should always be treated as loads that do not advance
1249 // the page id.
1250 //
1251 bool replace =
1252 navigation_state->pending_page_id() != -1 ||
1253 navigation_state->transition_type() == PageTransition::AUTO_SUBFRAME;
initial.commit09911bf2008-07-26 23:55:291254
[email protected]15d79e12009-08-02 19:23:451255 // If we failed on a browser initiated request, then make sure that our error
1256 // page load is regarded as the same browser initiated request.
1257 if (!navigation_state->is_content_initiated()) {
1258 pending_navigation_state_.reset(NavigationState::CreateBrowserInitiated(
1259 navigation_state->pending_page_id(),
1260 navigation_state->transition_type(),
1261 navigation_state->request_time()));
initial.commit09911bf2008-07-26 23:55:291262 }
[email protected]5df266ac2008-10-15 19:50:131263
[email protected]15d79e12009-08-02 19:23:451264 // Provide the user with a more helpful error page?
1265 if (MaybeLoadAlternateErrorPage(frame, error, replace))
1266 return;
1267
[email protected]be645db2009-02-06 20:36:331268 // Fallback to a local error page.
[email protected]726985e22009-06-18 21:09:281269 LoadNavigationErrorPage(frame, failed_request, error, std::string(),
[email protected]5df266ac2008-10-15 19:50:131270 replace);
initial.commit09911bf2008-07-26 23:55:291271}
1272
1273void RenderView::LoadNavigationErrorPage(WebFrame* frame,
[email protected]726985e22009-06-18 21:09:281274 const WebURLRequest& failed_request,
1275 const WebURLError& error,
initial.commit09911bf2008-07-26 23:55:291276 const std::string& html,
1277 bool replace) {
[email protected]726985e22009-06-18 21:09:281278 GURL failed_url = error.unreachableURL;
initial.commit09911bf2008-07-26 23:55:291279
1280 std::string alt_html;
1281 if (html.empty()) {
1282 // Use a local error page.
1283 int resource_id;
1284 DictionaryValue error_strings;
[email protected]726985e22009-06-18 21:09:281285 if (error.reason == net::ERR_CACHE_MISS &&
1286 EqualsASCII(failed_request.httpMethod(), "POST")) {
initial.commit09911bf2008-07-26 23:55:291287 GetFormRepostErrorValues(failed_url, &error_strings);
1288 resource_id = IDR_ERROR_NO_DETAILS_HTML;
1289 } else {
1290 GetLocalizedErrorValues(error, &error_strings);
1291 resource_id = IDR_NET_ERROR_HTML;
1292 }
[email protected]8e50b602009-03-03 22:59:431293 error_strings.SetString(L"textdirection",
1294 (l10n_util::GetTextDirection() == l10n_util::RIGHT_TO_LEFT) ?
1295 L"rtl" : L"ltr");
initial.commit09911bf2008-07-26 23:55:291296
1297 alt_html = GetAltHTMLForTemplate(error_strings, resource_id);
1298 } else {
1299 alt_html = html;
1300 }
1301
[email protected]dd7daa82009-08-10 05:46:451302 frame->loadHTMLString(alt_html,
[email protected]e6f546c32009-07-01 17:12:551303 GURL(kUnreachableWebDataURL),
1304 failed_url,
1305 replace);
initial.commit09911bf2008-07-26 23:55:291306}
1307
[email protected]7ccddb8c2009-08-04 17:36:551308void RenderView::DidReceiveDocumentData(WebFrame* frame, const char* data,
1309 size_t data_len) {
1310 NavigationState* navigation_state =
[email protected]dd7daa82009-08-10 05:46:451311 NavigationState::FromDataSource(frame->dataSource());
[email protected]7ccddb8c2009-08-04 17:36:551312 if (!navigation_state->postpone_loading_data()) {
[email protected]dd7daa82009-08-10 05:46:451313 frame->commitDocumentData(data, data_len);
[email protected]7ccddb8c2009-08-04 17:36:551314 return;
1315 }
1316
1317 // Continue buffering the response data for the original 404 page. If it
1318 // grows too large, then we'll just let it through.
1319 navigation_state->append_postponed_data(data, data_len);
1320 if (navigation_state->postponed_data().size() >= 512) {
1321 navigation_state->set_postpone_loading_data(false);
[email protected]dd7daa82009-08-10 05:46:451322 frame->commitDocumentData(navigation_state->postponed_data().data(),
[email protected]7ccddb8c2009-08-04 17:36:551323 navigation_state->postponed_data().size());
1324 navigation_state->clear_postponed_data();
1325 }
1326}
1327
initial.commit09911bf2008-07-26 23:55:291328void RenderView::DidCommitLoadForFrame(WebView *webview, WebFrame* frame,
1329 bool is_new_navigation) {
[email protected]daa8c58e2009-06-15 17:21:101330 NavigationState* navigation_state =
[email protected]dd7daa82009-08-10 05:46:451331 NavigationState::FromDataSource(frame->dataSource());
initial.commit09911bf2008-07-26 23:55:291332
[email protected]a2f6bc112009-06-27 16:27:251333 navigation_state->set_commit_load_time(Time::Now());
initial.commit09911bf2008-07-26 23:55:291334 if (is_new_navigation) {
1335 // When we perform a new navigation, we need to update the previous session
1336 // history entry with state for the page we are leaving.
1337 UpdateSessionHistory(frame);
1338
1339 // We bump our Page ID to correspond with the new session history entry.
1340 page_id_ = next_page_id_++;
1341
1342 MessageLoop::current()->PostDelayedTask(FROM_HERE,
1343 method_factory_.NewRunnableMethod(&RenderView::CapturePageInfo,
1344 page_id_, true),
1345 kDelayForForcedCaptureMs);
1346 } else {
[email protected]15d79e12009-08-02 19:23:451347 // Inspect the navigation_state on this frame to see if the navigation
1348 // corresponds to a session history navigation... Note: |frame| may or
1349 // may not be the toplevel frame, but for the case of capturing session
1350 // history, the first committed frame suffices. We keep track of whether
1351 // we've seen this commit before so that only capture session history once
1352 // per navigation.
[email protected]f4d34b52008-11-24 23:05:011353 //
1354 // Note that we need to check if the page ID changed. In the case of a
1355 // reload, the page ID doesn't change, and UpdateSessionHistory gets the
1356 // previous URL and the current page ID, which would be wrong.
[email protected]15d79e12009-08-02 19:23:451357 if (navigation_state->pending_page_id() != -1 &&
1358 navigation_state->pending_page_id() != page_id_ &&
1359 !navigation_state->request_committed()) {
initial.commit09911bf2008-07-26 23:55:291360 // This is a successful session history navigation!
1361 UpdateSessionHistory(frame);
[email protected]77f17a82009-05-21 04:42:541362 page_id_ = navigation_state->pending_page_id();
initial.commit09911bf2008-07-26 23:55:291363 }
1364 }
1365
1366 // Remember that we've already processed this request, so we don't update
1367 // the session history again. We do this regardless of whether this is
1368 // a session history navigation, because if we attempted a session history
1369 // navigation without valid HistoryItem state, WebCore will think it is a
1370 // new navigation.
[email protected]daa8c58e2009-06-15 17:21:101371 navigation_state->set_request_committed(true);
initial.commit09911bf2008-07-26 23:55:291372
1373 UpdateURL(frame);
1374
1375 // If this committed load was initiated by a client redirect, we're
1376 // at the last stop now, so clear it.
1377 completed_client_redirect_src_ = GURL();
1378
1379 // Check whether we have new encoding name.
1380 UpdateEncoding(frame, webview->GetMainFrameEncodingName());
1381}
1382
1383void RenderView::DidReceiveTitle(WebView* webview,
1384 const std::wstring& title,
1385 WebFrame* frame) {
1386 UpdateTitle(frame, title);
1387
1388 // Also check whether we have new encoding name.
1389 UpdateEncoding(frame, webview->GetMainFrameEncodingName());
1390}
1391
1392void RenderView::DidFinishLoadForFrame(WebView* webview, WebFrame* frame) {
[email protected]dd7daa82009-08-10 05:46:451393 WebDataSource* ds = frame->dataSource();
[email protected]a2f6bc112009-06-27 16:27:251394 NavigationState* navigation_state = NavigationState::FromDataSource(ds);
[email protected]78a3a6f2009-07-02 16:15:011395 DCHECK(navigation_state);
1396 navigation_state->set_finish_load_time(Time::Now());
initial.commit09911bf2008-07-26 23:55:291397}
1398
1399void RenderView::DidFailLoadWithError(WebView* webview,
[email protected]726985e22009-06-18 21:09:281400 const WebURLError& error,
initial.commit09911bf2008-07-26 23:55:291401 WebFrame* frame) {
[email protected]546ddd172009-06-25 00:25:011402 // Currently this function is empty. When you implement something here and it
1403 // will display any error messages in HTML, please make sure to call
1404 // frame->SetInViewSourceMode(false) not to show them in view source mode.
initial.commit09911bf2008-07-26 23:55:291405}
1406
1407void RenderView::DidFinishDocumentLoadForFrame(WebView* webview,
1408 WebFrame* frame) {
[email protected]dd7daa82009-08-10 05:46:451409 WebDataSource* ds = frame->dataSource();
[email protected]a2f6bc112009-06-27 16:27:251410 NavigationState* navigation_state = NavigationState::FromDataSource(ds);
[email protected]78a3a6f2009-07-02 16:15:011411 DCHECK(navigation_state);
1412 navigation_state->set_finish_document_load_time(Time::Now());
[email protected]a2f6bc112009-06-27 16:27:251413
[email protected]09b8f82f2009-06-16 20:22:111414 Send(new ViewHostMsg_DocumentLoadedInFrame(routing_id_));
1415
[email protected]daa8c58e2009-06-15 17:21:101416 // The document has now been fully loaded. Scan for password forms to be
1417 // sent up to the browser.
1418 SendPasswordForms(frame);
1419
initial.commit09911bf2008-07-26 23:55:291420 // Check whether we have new encoding name.
1421 UpdateEncoding(frame, webview->GetMainFrameEncodingName());
[email protected]1e0f70402008-10-16 23:57:471422
[email protected]8930d472009-02-21 08:05:281423 if (RenderThread::current()) // Will be NULL during unit tests.
1424 RenderThread::current()->user_script_slave()->InjectScripts(
[email protected]0afe8272009-02-14 04:15:161425 frame, UserScript::DOCUMENT_END);
initial.commit09911bf2008-07-26 23:55:291426}
1427
1428void RenderView::DidHandleOnloadEventsForFrame(WebView* webview,
1429 WebFrame* frame) {
1430}
1431
1432void RenderView::DidChangeLocationWithinPageForFrame(WebView* webview,
1433 WebFrame* frame,
1434 bool is_new_navigation) {
[email protected]77f17a82009-05-21 04:42:541435 // If this was a reference fragment navigation that we initiated, then we
1436 // could end up having a non-null pending navigation state. We just need to
1437 // update the ExtraData on the datasource so that others who read the
1438 // ExtraData will get the new NavigationState. Similarly, if we did not
[email protected]daa8c58e2009-06-15 17:21:101439 // initiate this navigation, then we need to take care to reset any pre-
1440 // existing navigation state to a content-initiated navigation state.
1441 // DidCreateDataSource conveniently takes care of this for us.
[email protected]dd7daa82009-08-10 05:46:451442 DidCreateDataSource(frame, frame->dataSource());
[email protected]77f17a82009-05-21 04:42:541443
initial.commit09911bf2008-07-26 23:55:291444 DidCommitLoadForFrame(webview, frame, is_new_navigation);
[email protected]77f17a82009-05-21 04:42:541445
[email protected]9d806f52009-03-12 22:50:541446 const string16& title =
[email protected]dd7daa82009-08-10 05:46:451447 webview->GetMainFrame()->dataSource()->pageTitle();
[email protected]9d806f52009-03-12 22:50:541448 UpdateTitle(frame, UTF16ToWideHack(title));
initial.commit09911bf2008-07-26 23:55:291449}
1450
initial.commit09911bf2008-07-26 23:55:291451void RenderView::DidCompleteClientRedirect(WebView* webview,
1452 WebFrame* frame,
1453 const GURL& source) {
1454 if (webview->GetMainFrame() == frame)
1455 completed_client_redirect_src_ = source;
1456}
1457
[email protected]7a9b51f2009-06-29 21:28:291458void RenderView::WillCloseFrame(WebView* webview, WebFrame* frame) {
[email protected]dd7daa82009-08-10 05:46:451459 if (!frame->parent()) {
1460 const GURL& url = frame->url();
[email protected]7a9b51f2009-06-29 21:28:291461 if (url.SchemeIs("http") || url.SchemeIs("https"))
1462 DumpLoadHistograms();
1463 }
1464}
1465
[email protected]daa8c58e2009-06-15 17:21:101466void RenderView::WillSubmitForm(WebView* webview, WebFrame* frame,
1467 const WebForm& form) {
1468 NavigationState* navigation_state =
[email protected]dd7daa82009-08-10 05:46:451469 NavigationState::FromDataSource(frame->provisionalDataSource());
[email protected]daa8c58e2009-06-15 17:21:101470
1471 if (navigation_state->transition_type() == PageTransition::LINK)
1472 navigation_state->set_transition_type(PageTransition::FORM_SUBMIT);
1473
1474 // Save these to be processed when the ensuing navigation is committed.
1475 navigation_state->set_searchable_form_data(
1476 SearchableFormData::Create(form));
1477 navigation_state->set_password_form_data(
1478 PasswordFormDomManager::CreatePasswordForm(form));
1479
1480 if (form.isAutoCompleteEnabled()) {
1481 scoped_ptr<AutofillForm> autofill_form(AutofillForm::Create(form));
1482 if (autofill_form.get())
1483 Send(new ViewHostMsg_AutofillFormSubmitted(routing_id_, *autofill_form));
1484 }
1485}
1486
[email protected]7ccddb8c2009-08-04 17:36:551487void RenderView::WillSendRequest(WebFrame* frame, uint32 identifier,
[email protected]a1353852009-08-06 05:34:221488 WebURLRequest* request,
1489 const WebURLResponse& redirect_response) {
[email protected]726985e22009-06-18 21:09:281490 request->setRequestorID(routing_id_);
[email protected]5b35a6b2009-03-16 19:58:081491}
1492
[email protected]7ccddb8c2009-08-04 17:36:551493void RenderView::DidReceiveResponse(WebFrame* frame, uint32 identifier,
1494 const WebURLResponse& response) {
1495 // Consider loading an alternate error page for 404 responses.
1496 if (response.httpStatusCode() != 404)
1497 return;
1498
1499 // Only do this for responses that correspond to a provisional data source
1500 // of the top-most frame. If we have a provisional data source, then we
1501 // can't have any sub-resources yet, so we know that this response must
1502 // correspond to a frame load.
[email protected]dd7daa82009-08-10 05:46:451503 if (!frame->provisionalDataSource() || frame->parent())
[email protected]7ccddb8c2009-08-04 17:36:551504 return;
1505
1506 // If we are in view source mode, then just let the user see the source of
1507 // the server's 404 error page.
[email protected]dd7daa82009-08-10 05:46:451508 if (frame->isViewSourceModeEnabled())
[email protected]7ccddb8c2009-08-04 17:36:551509 return;
1510
1511 // Can we even load an alternate error page for this URL?
1512 if (!GetAlternateErrorPageURL(response.url(), HTTP_404).is_valid())
1513 return;
1514
1515 NavigationState* navigation_state =
[email protected]dd7daa82009-08-10 05:46:451516 NavigationState::FromDataSource(frame->provisionalDataSource());
[email protected]7ccddb8c2009-08-04 17:36:551517 navigation_state->set_postpone_loading_data(true);
1518 navigation_state->clear_postponed_data();
1519}
1520
1521void RenderView::DidFinishLoading(WebFrame* frame, uint32 identifier) {
1522 NavigationState* navigation_state =
[email protected]dd7daa82009-08-10 05:46:451523 NavigationState::FromDataSource(frame->dataSource());
[email protected]7ccddb8c2009-08-04 17:36:551524 if (!navigation_state->postpone_loading_data())
1525 return;
1526
1527 // The server returned a 404 and the content was < 512 bytes (which we
1528 // suppressed). Go ahead and fetch the alternate page content.
1529
[email protected]dd7daa82009-08-10 05:46:451530 const GURL& frame_url = frame->url();
[email protected]7ccddb8c2009-08-04 17:36:551531
1532 const GURL& error_page_url = GetAlternateErrorPageURL(frame_url, HTTP_404);
1533 DCHECK(error_page_url.is_valid());
1534
1535 WebURLError original_error;
1536 original_error.unreachableURL = frame_url;
1537
1538 navigation_state->set_alt_error_page_fetcher(
1539 new AltErrorPageResourceFetcher(
1540 error_page_url, frame, original_error,
1541 NewCallback(this, &RenderView::AltErrorPageFinished)));
1542}
1543
1544void RenderView::BindDOMAutomationController(WebFrame* frame) {
initial.commit09911bf2008-07-26 23:55:291545 dom_automation_controller_.set_message_sender(this);
1546 dom_automation_controller_.set_routing_id(routing_id_);
[email protected]7ccddb8c2009-08-04 17:36:551547 dom_automation_controller_.BindToJavascript(frame,
initial.commit09911bf2008-07-26 23:55:291548 L"domAutomationController");
1549}
1550
[email protected]7ccddb8c2009-08-04 17:36:551551void RenderView::WindowObjectCleared(WebFrame* frame) {
[email protected]81e63782009-02-27 19:35:091552 if (BindingsPolicy::is_dom_automation_enabled(enabled_bindings_))
[email protected]7ccddb8c2009-08-04 17:36:551553 BindDOMAutomationController(frame);
[email protected]81e63782009-02-27 19:35:091554 if (BindingsPolicy::is_dom_ui_enabled(enabled_bindings_)) {
initial.commit09911bf2008-07-26 23:55:291555 dom_ui_bindings_.set_message_sender(this);
1556 dom_ui_bindings_.set_routing_id(routing_id_);
[email protected]7ccddb8c2009-08-04 17:36:551557 dom_ui_bindings_.BindToJavascript(frame, L"chrome");
initial.commit09911bf2008-07-26 23:55:291558 }
[email protected]81e63782009-02-27 19:35:091559 if (BindingsPolicy::is_external_host_enabled(enabled_bindings_)) {
[email protected]18cb2572008-08-21 20:34:451560 external_host_bindings_.set_message_sender(this);
1561 external_host_bindings_.set_routing_id(routing_id_);
[email protected]7ccddb8c2009-08-04 17:36:551562 external_host_bindings_.BindToJavascript(frame, L"externalHost");
[email protected]18cb2572008-08-21 20:34:451563 }
initial.commit09911bf2008-07-26 23:55:291564}
1565
[email protected]0afe8272009-02-14 04:15:161566void RenderView::DocumentElementAvailable(WebFrame* frame) {
[email protected]4b8323b2009-04-17 18:45:441567 // TODO(mpcomplete): remove this before Chrome extensions ship.
1568 // HACK. This is a temporary workaround to allow cross-origin XHR for Chrome
1569 // extensions. It grants full access to every origin, when we really want
1570 // to be able to restrict them more specifically.
[email protected]dd7daa82009-08-10 05:46:451571 GURL url = frame->url();
[email protected]e95ad332009-08-03 19:44:251572 if (url.SchemeIs(chrome::kExtensionScheme))
[email protected]dd7daa82009-08-10 05:46:451573 frame->grantUniversalAccess();
[email protected]d959ce22009-04-15 21:03:421574
[email protected]8930d472009-02-21 08:05:281575 if (RenderThread::current()) // Will be NULL during unit tests.
1576 RenderThread::current()->user_script_slave()->InjectScripts(
[email protected]0afe8272009-02-14 04:15:161577 frame, UserScript::DOCUMENT_START);
[email protected]e95ad332009-08-03 19:44:251578
1579 // Notify the browser about non-blank documents loading in the top frame.
1580 if (url.is_valid() && url.spec() != "about:blank") {
1581 if (frame == webview()->GetMainFrame())
1582 Send(new ViewHostMsg_DocumentAvailableInMainFrame(routing_id_));
1583 }
[email protected]0afe8272009-02-14 04:15:161584}
1585
[email protected]b6ce15972009-07-14 22:14:011586void RenderView::DidCreateScriptContextForFrame(WebFrame* webframe) {
[email protected]7120f132009-07-20 21:05:371587 EventBindings::HandleContextCreated(webframe, false);
[email protected]f816c012009-06-26 21:48:321588}
1589
[email protected]b6ce15972009-07-14 22:14:011590void RenderView::DidDestroyScriptContextForFrame(WebFrame* webframe) {
[email protected]f816c012009-06-26 21:48:321591 EventBindings::HandleContextDestroyed(webframe);
1592}
1593
[email protected]b6ce15972009-07-14 22:14:011594void RenderView::DidCreateIsolatedScriptContext(WebFrame* webframe) {
[email protected]7120f132009-07-20 21:05:371595 EventBindings::HandleContextCreated(webframe, true);
[email protected]b6ce15972009-07-14 22:14:011596}
1597
[email protected]4873c7d2009-07-16 06:36:281598WebNavigationPolicy RenderView::PolicyForNavigationAction(
initial.commit09911bf2008-07-26 23:55:291599 WebView* webview,
1600 WebFrame* frame,
[email protected]726985e22009-06-18 21:09:281601 const WebURLRequest& request,
initial.commit09911bf2008-07-26 23:55:291602 WebNavigationType type,
[email protected]4873c7d2009-07-16 06:36:281603 WebNavigationPolicy default_policy,
initial.commit09911bf2008-07-26 23:55:291604 bool is_redirect) {
[email protected]5f450e52009-07-28 13:28:111605 // Webkit is asking whether to navigate to a new URL.
1606 // This is fine normally, except if we're showing UI from one security
1607 // context and they're trying to navigate to a different context.
1608 const GURL& url = request.url();
1609
1610 // If the browser is interested, then give it a chance to look at top level
1611 // navigations
1612 if (renderer_preferences_.browser_handles_top_level_requests &&
1613 // Only send once.
1614 last_top_level_navigation_page_id_ != page_id_ &&
1615 // Not interested in reloads.
1616 type != WebKit::WebNavigationTypeReload &&
[email protected]87d3a2952009-08-10 18:07:371617 type != WebKit::WebNavigationTypeFormSubmitted &&
[email protected]5f450e52009-07-28 13:28:111618 // Must be a top level frame.
[email protected]dd7daa82009-08-10 05:46:451619 frame->parent() == NULL) {
[email protected]5f450e52009-07-28 13:28:111620 // Skip if navigation is on the same page (using '#').
[email protected]dd7daa82009-08-10 05:46:451621 GURL frame_origin = GURL(frame->url()).GetOrigin();
[email protected]5f450e52009-07-28 13:28:111622 if (url.GetOrigin() != frame_origin || url.ref().empty()) {
1623 last_top_level_navigation_page_id_ = page_id_;
1624 OpenURL(webview, url, GURL(), default_policy);
1625 return WebKit::WebNavigationPolicyIgnore; // Suppress the load here.
1626 }
1627 }
1628
[email protected]daa8c58e2009-06-15 17:21:101629 // A content initiated navigation may have originated from a link-click,
1630 // script, drag-n-drop operation, etc.
[email protected]77f17a82009-05-21 04:42:541631 bool is_content_initiated =
[email protected]dd7daa82009-08-10 05:46:451632 NavigationState::FromDataSource(frame->provisionalDataSource())->
[email protected]daa8c58e2009-06-15 17:21:101633 is_content_initiated();
[email protected]77f17a82009-05-21 04:42:541634
initial.commit09911bf2008-07-26 23:55:291635 // We only care about navigations that are within the current tab (as opposed
1636 // to, for example, opening a new window).
1637 // But we sometimes navigate to about:blank to clear a tab, and we want to
1638 // still allow that.
[email protected]4873c7d2009-07-16 06:36:281639 if (default_policy == WebKit::WebNavigationPolicyCurrentTab &&
[email protected]dd7daa82009-08-10 05:46:451640 is_content_initiated && frame->parent() == NULL &&
[email protected]4873c7d2009-07-16 06:36:281641 !url.SchemeIs(chrome::kAboutScheme)) {
[email protected]77f17a82009-05-21 04:42:541642 // When we received such unsolicited navigations, we sometimes want to
1643 // punt them up to the browser to handle.
1644 if (BindingsPolicy::is_dom_ui_enabled(enabled_bindings_) ||
[email protected]1e5f53a2009-06-15 23:48:041645 BindingsPolicy::is_extension_enabled(enabled_bindings_) ||
[email protected]dd7daa82009-08-10 05:46:451646 frame->isViewSourceModeEnabled() ||
[email protected]a2176742009-07-03 12:13:481647 url.SchemeIs(chrome::kViewSourceScheme) ||
1648 url.SchemeIs(chrome::kPrintScheme)) {
[email protected]4873c7d2009-07-16 06:36:281649 OpenURL(webview, url, GURL(), default_policy);
1650 return WebKit::WebNavigationPolicyIgnore; // Suppress the load here.
initial.commit09911bf2008-07-26 23:55:291651 }
1652 }
1653
1654 // Detect when a page is "forking" a new tab that can be safely rendered in
1655 // its own process. This is done by sites like Gmail that try to open links
1656 // in new windows without script connections back to the original page. We
1657 // treat such cases as browser navigations (in which we will create a new
1658 // renderer for a cross-site navigation), rather than WebKit navigations.
1659 //
1660 // We use the following heuristic to decide whether to fork a new page in its
1661 // own process:
1662 // The parent page must open a new tab to about:blank, set the new tab's
1663 // window.opener to null, and then redirect the tab to a cross-site URL using
1664 // JavaScript.
1665 bool is_fork =
1666 // Must start from a tab showing about:blank, which is later redirected.
[email protected]dd7daa82009-08-10 05:46:451667 GURL(frame->url()) == GURL("about:blank") &&
initial.commit09911bf2008-07-26 23:55:291668 // Must be the first real navigation of the tab.
1669 GetHistoryBackListCount() < 1 &&
1670 GetHistoryForwardListCount() < 1 &&
1671 // The parent page must have set the child's window.opener to null before
1672 // redirecting to the desired URL.
[email protected]dd7daa82009-08-10 05:46:451673 frame->opener() == NULL &&
initial.commit09911bf2008-07-26 23:55:291674 // Must be a top-level frame.
[email protected]dd7daa82009-08-10 05:46:451675 frame->parent() == NULL &&
[email protected]77f17a82009-05-21 04:42:541676 // Must not have issued the request from this page.
1677 is_content_initiated &&
initial.commit09911bf2008-07-26 23:55:291678 // Must be targeted at the current tab.
[email protected]4873c7d2009-07-16 06:36:281679 default_policy == WebKit::WebNavigationPolicyCurrentTab &&
initial.commit09911bf2008-07-26 23:55:291680 // Must be a JavaScript navigation, which appears as "other".
[email protected]726985e22009-06-18 21:09:281681 type == WebKit::WebNavigationTypeOther;
initial.commit09911bf2008-07-26 23:55:291682 if (is_fork) {
1683 // Open the URL via the browser, not via WebKit.
[email protected]4873c7d2009-07-16 06:36:281684 OpenURL(webview, url, GURL(), default_policy);
1685 return WebKit::WebNavigationPolicyIgnore;
initial.commit09911bf2008-07-26 23:55:291686 }
1687
[email protected]4873c7d2009-07-16 06:36:281688 return default_policy;
initial.commit09911bf2008-07-26 23:55:291689}
1690
[email protected]a455d3812009-03-05 20:18:071691void RenderView::RunJavaScriptAlert(WebFrame* webframe,
initial.commit09911bf2008-07-26 23:55:291692 const std::wstring& message) {
[email protected]478ff2ed2009-04-21 23:49:181693 RunJavaScriptMessage(MessageBoxFlags::kIsJavascriptAlert,
initial.commit09911bf2008-07-26 23:55:291694 message,
1695 std::wstring(),
[email protected]dd7daa82009-08-10 05:46:451696 webframe->url(),
initial.commit09911bf2008-07-26 23:55:291697 NULL);
1698}
1699
[email protected]a455d3812009-03-05 20:18:071700bool RenderView::RunJavaScriptConfirm(WebFrame* webframe,
initial.commit09911bf2008-07-26 23:55:291701 const std::wstring& message) {
[email protected]478ff2ed2009-04-21 23:49:181702 return RunJavaScriptMessage(MessageBoxFlags::kIsJavascriptConfirm,
initial.commit09911bf2008-07-26 23:55:291703 message,
1704 std::wstring(),
[email protected]dd7daa82009-08-10 05:46:451705 webframe->url(),
initial.commit09911bf2008-07-26 23:55:291706 NULL);
1707}
1708
[email protected]a455d3812009-03-05 20:18:071709bool RenderView::RunJavaScriptPrompt(WebFrame* webframe,
initial.commit09911bf2008-07-26 23:55:291710 const std::wstring& message,
1711 const std::wstring& default_value,
1712 std::wstring* result) {
[email protected]478ff2ed2009-04-21 23:49:181713 return RunJavaScriptMessage(MessageBoxFlags::kIsJavascriptPrompt,
initial.commit09911bf2008-07-26 23:55:291714 message,
1715 default_value,
[email protected]dd7daa82009-08-10 05:46:451716 webframe->url(),
initial.commit09911bf2008-07-26 23:55:291717 result);
1718}
1719
1720bool RenderView::RunJavaScriptMessage(int type,
1721 const std::wstring& message,
1722 const std::wstring& default_value,
[email protected]a455d3812009-03-05 20:18:071723 const GURL& frame_url,
initial.commit09911bf2008-07-26 23:55:291724 std::wstring* result) {
1725 bool success = false;
1726 std::wstring result_temp;
1727 if (!result)
1728 result = &result_temp;
1729 IPC::SyncMessage* msg = new ViewHostMsg_RunJavaScriptMessage(
[email protected]a455d3812009-03-05 20:18:071730 routing_id_, message, default_value, frame_url, type, &success, result);
initial.commit09911bf2008-07-26 23:55:291731
[email protected]1c4947f2009-01-15 22:25:111732 msg->set_pump_messages_event(modal_dialog_event_.get());
initial.commit09911bf2008-07-26 23:55:291733 Send(msg);
1734
1735 return success;
1736}
1737
1738void RenderView::AddGURLSearchProvider(const GURL& osd_url, bool autodetected) {
1739 if (!osd_url.is_empty())
1740 Send(new ViewHostMsg_PageHasOSDD(routing_id_, page_id_, osd_url,
1741 autodetected));
1742}
1743
[email protected]a455d3812009-03-05 20:18:071744bool RenderView::RunBeforeUnloadConfirm(WebFrame* webframe,
initial.commit09911bf2008-07-26 23:55:291745 const std::wstring& message) {
1746 bool success = false;
1747 // This is an ignored return value, but is included so we can accept the same
1748 // response as RunJavaScriptMessage.
1749 std::wstring ignored_result;
1750 IPC::SyncMessage* msg = new ViewHostMsg_RunBeforeUnloadConfirm(
[email protected]dd7daa82009-08-10 05:46:451751 routing_id_, webframe->url(), message, &success, &ignored_result);
initial.commit09911bf2008-07-26 23:55:291752
[email protected]1c4947f2009-01-15 22:25:111753 msg->set_pump_messages_event(modal_dialog_event_.get());
initial.commit09911bf2008-07-26 23:55:291754 Send(msg);
1755
1756 return success;
1757}
1758
[email protected]0ebf3872008-11-07 21:35:031759void RenderView::QueryFormFieldAutofill(const std::wstring& field_name,
1760 const std::wstring& text,
1761 int64 node_id) {
1762 static int message_id_counter = 0;
1763 form_field_autofill_request_id_ = message_id_counter++;
1764 Send(new ViewHostMsg_QueryFormFieldAutofill(routing_id_,
1765 field_name, text,
1766 node_id,
1767 form_field_autofill_request_id_));
1768}
1769
[email protected]4d2b6fb2009-03-20 22:28:171770void RenderView::RemoveStoredAutofillEntry(const std::wstring& name,
1771 const std::wstring& value) {
1772 Send(new ViewHostMsg_RemoveAutofillEntry(routing_id_, name, value));
1773}
1774
[email protected]0ebf3872008-11-07 21:35:031775void RenderView::OnReceivedAutofillSuggestions(
1776 int64 node_id,
1777 int request_id,
[email protected]8d0f15c2008-11-11 01:01:091778 const std::vector<std::wstring>& suggestions,
[email protected]0ebf3872008-11-07 21:35:031779 int default_suggestion_index) {
1780 if (!webview() || request_id != form_field_autofill_request_id_)
1781 return;
1782
1783 webview()->AutofillSuggestionsForNode(node_id, suggestions,
1784 default_suggestion_index);
1785}
1786
[email protected]2c4410d2009-05-06 23:46:221787void RenderView::OnPopupNotificationVisibilityChanged(bool visible) {
[email protected]634a6f92008-12-01 21:39:311788 popup_notification_visible_ = visible;
1789}
1790
initial.commit09911bf2008-07-26 23:55:291791void RenderView::ShowModalHTMLDialog(const GURL& url, int width, int height,
1792 const std::string& json_arguments,
1793 std::string* json_retval) {
1794 IPC::SyncMessage* msg = new ViewHostMsg_ShowModalHTMLDialog(
1795 routing_id_, url, width, height, json_arguments, json_retval);
1796
[email protected]1c4947f2009-01-15 22:25:111797 msg->set_pump_messages_event(modal_dialog_event_.get());
initial.commit09911bf2008-07-26 23:55:291798 Send(msg);
1799}
1800
1801uint32 RenderView::GetCPBrowsingContext() {
1802 uint32 context = 0;
1803 Send(new ViewHostMsg_GetCPBrowsingContext(&context));
1804 return context;
1805}
1806
1807// Tell the browser to display a destination link.
1808void RenderView::UpdateTargetURL(WebView* webview, const GURL& url) {
1809 if (url != target_url_) {
1810 if (target_url_status_ == TARGET_INFLIGHT ||
1811 target_url_status_ == TARGET_PENDING) {
1812 // If we have a request in-flight, save the URL to be sent when we
1813 // receive an ACK to the in-flight request. We can happily overwrite
1814 // any existing pending sends.
1815 pending_target_url_ = url;
1816 target_url_status_ = TARGET_PENDING;
1817 } else {
1818 Send(new ViewHostMsg_UpdateTargetURL(routing_id_, page_id_, url));
1819 target_url_ = url;
1820 target_url_status_ = TARGET_INFLIGHT;
1821 }
1822 }
1823}
1824
[email protected]b62d1a8c2009-01-13 23:54:571825void RenderView::RunFileChooser(bool multi_select,
[email protected]b949f1112009-04-12 20:03:081826 const string16& title,
1827 const FilePath& default_filename,
initial.commit09911bf2008-07-26 23:55:291828 WebFileChooserCallback* file_chooser) {
1829 if (file_chooser_.get()) {
1830 // TODO(brettw): bug 1235154: This should be a synchronous message to deal
1831 // with the fact that web pages can programatically trigger this. With the
1832 // asnychronous messages, we can get an additional call when one is pending,
1833 // which this test is for. For now, we just ignore the additional file
1834 // chooser request. WebKit doesn't do anything to expect the callback, so
1835 // we can just ignore calling it.
1836 delete file_chooser;
1837 return;
1838 }
1839 file_chooser_.reset(file_chooser);
[email protected]b62d1a8c2009-01-13 23:54:571840 Send(new ViewHostMsg_RunFileChooser(routing_id_, multi_select, title,
[email protected]b949f1112009-04-12 20:03:081841 default_filename));
initial.commit09911bf2008-07-26 23:55:291842}
1843
1844void RenderView::AddMessageToConsole(WebView* webview,
1845 const std::wstring& message,
1846 unsigned int line_no,
1847 const std::wstring& source_id) {
1848 Send(new ViewHostMsg_AddMessageToConsole(routing_id_, message,
1849 static_cast<int32>(line_no),
1850 source_id));
1851}
1852
1853void RenderView::AddSearchProvider(const std::string& url) {
1854 AddGURLSearchProvider(GURL(url),
1855 false); // not autodetected
1856}
1857
[email protected]c88a70fe2009-05-05 20:00:221858WebView* RenderView::CreateWebView(WebView* webview,
1859 bool user_gesture,
1860 const GURL& creator_url) {
[email protected]0aa55312008-10-17 21:53:081861 // Check to make sure we aren't overloading on popups.
1862 if (shared_popup_counter_->data > kMaximumNumberOfUnacknowledgedPopups)
1863 return NULL;
1864
[email protected]634a6f92008-12-01 21:39:311865 // This window can't be closed from a window.close() call until we receive a
1866 // message from the Browser process explicitly allowing it.
1867 popup_notification_visible_ = true;
1868
initial.commit09911bf2008-07-26 23:55:291869 int32 routing_id = MSG_ROUTING_NONE;
[email protected]6c8afae52009-01-22 02:24:571870
[email protected]18bcc3c2009-01-27 21:39:151871 ModalDialogEvent modal_dialog_event;
[email protected]6c8afae52009-01-22 02:24:571872 render_thread_->Send(
[email protected]15787f8f2008-10-17 15:29:031873 new ViewHostMsg_CreateWindow(routing_id_, user_gesture, &routing_id,
1874 &modal_dialog_event));
initial.commit09911bf2008-07-26 23:55:291875 if (routing_id == MSG_ROUTING_NONE) {
initial.commit09911bf2008-07-26 23:55:291876 return NULL;
1877 }
1878
1879 // The WebView holds a reference to this new RenderView
[email protected]6c8afae52009-01-22 02:24:571880 base::WaitableEvent* waitable_event = new base::WaitableEvent
1881#if defined(OS_WIN)
[email protected]18bcc3c2009-01-27 21:39:151882 (modal_dialog_event.event);
[email protected]6c8afae52009-01-22 02:24:571883#else
1884 (true, false);
1885#endif
[email protected]81a34412009-01-05 19:17:241886 RenderView* view = RenderView::Create(render_thread_,
[email protected]1c4947f2009-01-15 22:25:111887 NULL, waitable_event, routing_id_,
[email protected]2fab253a2009-08-17 23:00:591888 renderer_preferences_,
1889 webkit_preferences_,
[email protected]80d96fa2009-06-10 22:34:511890 shared_popup_counter_, routing_id);
[email protected]ed4bf2d2009-05-05 00:10:061891 view->opened_by_user_gesture_ = user_gesture;
[email protected]c88a70fe2009-05-05 20:00:221892 view->creator_url_ = creator_url;
initial.commit09911bf2008-07-26 23:55:291893
1894 // Copy over the alternate error page URL so we can have alt error pages in
1895 // the new render view (we don't need the browser to send the URL back down).
1896 view->alternate_error_page_url_ = alternate_error_page_url_;
1897
1898 return view->webview();
1899}
1900
[email protected]0ebf3872008-11-07 21:35:031901WebWidget* RenderView::CreatePopupWidget(WebView* webview,
[email protected]cfd727f2009-01-09 20:21:111902 bool activatable) {
[email protected]8085dbc82008-09-26 22:53:441903 RenderWidget* widget = RenderWidget::Create(routing_id_,
[email protected]81a34412009-01-05 19:17:241904 render_thread_,
[email protected]cfd727f2009-01-09 20:21:111905 activatable);
initial.commit09911bf2008-07-26 23:55:291906 return widget->webwidget();
1907}
1908
[email protected]88efb7ec2009-07-14 16:32:591909WebWidget* RenderView::CreatePopupWidgetWithInfo(WebView* webview,
1910 const WebPopupMenuInfo& info) {
1911 RenderWidget* widget = RenderWidget::Create(routing_id_,
1912 render_thread_,
1913 true);
1914 widget->ConfigureAsExternalPopupMenu(info);
1915 return widget->webwidget();
1916}
1917
initial.commit09911bf2008-07-26 23:55:291918WebPluginDelegate* RenderView::CreatePluginDelegate(
1919 WebView* webview,
1920 const GURL& url,
1921 const std::string& mime_type,
1922 const std::string& clsid,
1923 std::string* actual_mime_type) {
[email protected]6273e2e72009-04-17 00:13:551924 if (!PluginChannelHost::IsListening())
1925 return NULL;
1926
[email protected]9dd9e8382009-06-05 18:23:211927 GURL policy_url;
1928 if (webview->GetMainFrame())
[email protected]dd7daa82009-08-10 05:46:451929 policy_url = webview->GetMainFrame()->url();
[email protected]9dd9e8382009-06-05 18:23:211930
[email protected]f5cdaff2009-05-19 21:01:471931 FilePath path;
1932 render_thread_->Send(
[email protected]9dd9e8382009-06-05 18:23:211933 new ViewHostMsg_GetPluginPath(url, policy_url, mime_type, clsid, &path,
[email protected]f5cdaff2009-05-19 21:01:471934 actual_mime_type));
1935 if (path.value().empty())
1936 return NULL;
1937
1938 std::string mime_type_to_use;
1939 if (!actual_mime_type->empty())
1940 mime_type_to_use = *actual_mime_type;
1941 else
1942 mime_type_to_use = mime_type;
1943
[email protected]88a1fb47a2009-03-13 00:18:061944 if (RenderProcess::current()->in_process_plugins()) {
[email protected]6bf1a812009-07-11 01:57:281945#if defined(OS_WIN) // In-proc plugins aren't supported on Linux or Mac.
[email protected]b94d3322009-02-12 19:49:041946 return WebPluginDelegate::Create(path,
1947 mime_type_to_use,
1948 gfx::NativeViewFromId(host_window_));
[email protected]6bf1a812009-07-11 01:57:281949#else
1950 NOTIMPLEMENTED();
1951 return NULL;
[email protected]ffeba6d2009-04-27 20:43:261952#endif
[email protected]6bf1a812009-07-11 01:57:281953 }
initial.commit09911bf2008-07-26 23:55:291954
1955 WebPluginDelegateProxy* proxy =
[email protected]f5cdaff2009-05-19 21:01:471956 WebPluginDelegateProxy::Create(url, mime_type_to_use, clsid, this);
initial.commit09911bf2008-07-26 23:55:291957 if (!proxy)
1958 return NULL;
1959
initial.commit09911bf2008-07-26 23:55:291960 plugin_delegates_.push_back(proxy);
1961
1962 return proxy;
1963}
1964
[email protected]4e6be3f2009-05-07 02:24:441965WebKit::WebMediaPlayer* RenderView::CreateWebMediaPlayer(
1966 WebKit::WebMediaPlayerClient* client) {
[email protected]add51772009-06-11 18:25:171967 scoped_refptr<media::FilterFactoryCollection> factory =
1968 new media::FilterFactoryCollection();
1969 // Add in any custom filter factories first.
1970 const CommandLine* cmd_line = CommandLine::ForCurrentProcess();
1971 if (!cmd_line->HasSwitch(switches::kDisableAudio)) {
1972 // Add the chrome specific audio renderer.
1973 factory->AddFactory(
1974 AudioRendererImpl::CreateFactory(audio_message_filter()));
1975 }
[email protected]8380c092009-06-25 17:45:511976
1977 // TODO(hclam): obtain the following parameters from |client|.
1978 webkit_glue::MediaResourceLoaderBridgeFactory* bridge_factory =
1979 new webkit_glue::MediaResourceLoaderBridgeFactory(
1980 GURL::EmptyGURL(), // referrer
1981 "null", // frame origin
1982 "null", // main_frame_origin
1983 base::GetCurrentProcId(),
1984 WebAppCacheContext::kNoAppCacheContextId,
1985 routing_id());
1986
[email protected]add51772009-06-11 18:25:171987 if (!cmd_line->HasSwitch(switches::kSimpleDataSource)) {
1988 // Add the chrome specific media data source.
[email protected]70ab61c92009-06-16 19:29:391989 factory->AddFactory(
[email protected]8e296bbd2009-07-22 21:37:171990 webkit_glue::BufferedDataSource::CreateFactory(MessageLoop::current(),
1991 bridge_factory));
[email protected]8380c092009-06-25 17:45:511992 } else {
1993 factory->AddFactory(
1994 webkit_glue::SimpleDataSource::CreateFactory(MessageLoop::current(),
1995 bridge_factory));
[email protected]add51772009-06-11 18:25:171996 }
1997 return new webkit_glue::WebMediaPlayerImpl(client, factory);
[email protected]ec9212f2008-12-18 21:40:361998}
1999
initial.commit09911bf2008-07-26 23:55:292000void RenderView::OnMissingPluginStatus(WebPluginDelegate* delegate,
2001 int status) {
[email protected]6c8afae52009-01-22 02:24:572002#if defined(OS_WIN)
initial.commit09911bf2008-07-26 23:55:292003 if (first_default_plugin_ == NULL) {
2004 // Show the InfoBar for the first available plugin.
2005 if (status == default_plugin::MISSING_PLUGIN_AVAILABLE) {
2006 first_default_plugin_ = delegate;
2007 Send(new ViewHostMsg_MissingPluginStatus(routing_id_, status));
2008 }
2009 } else {
2010 // Closes the InfoBar if user clicks on the plugin (instead of the InfoBar)
2011 // to start the download/install.
2012 if (status == default_plugin::MISSING_PLUGIN_USER_STARTED_DOWNLOAD) {
2013 Send(new ViewHostMsg_MissingPluginStatus(routing_id_, status));
2014 }
2015 }
[email protected]6c8afae52009-01-22 02:24:572016#else
2017 // TODO(port): plugins current not supported
2018 NOTIMPLEMENTED();
2019#endif
initial.commit09911bf2008-07-26 23:55:292020}
2021
[email protected]eb47a132009-03-04 00:39:562022WebWorker* RenderView::CreateWebWorker(WebWorkerClient* client) {
[email protected]ec775ef2009-05-01 21:20:472023 return new WebWorkerProxy(client, RenderThread::current(), routing_id_);
[email protected]eb47a132009-03-04 00:39:562024}
2025
initial.commit09911bf2008-07-26 23:55:292026void RenderView::OpenURL(WebView* webview, const GURL& url,
[email protected]c0588052008-10-27 23:01:502027 const GURL& referrer,
[email protected]4873c7d2009-07-16 06:36:282028 WebNavigationPolicy policy) {
2029 Send(new ViewHostMsg_OpenURL(
2030 routing_id_, url, referrer, NavigationPolicyToDisposition(policy)));
initial.commit09911bf2008-07-26 23:55:292031}
2032
[email protected]1d522202009-04-04 01:56:422033void RenderView::DidContentsSizeChange(WebWidget* webwidget,
2034 int new_width,
2035 int new_height) {
[email protected]0666aef2009-05-13 19:48:082036 // We don't always want to send the change messages over IPC, only if we've
2037 // be put in that mode by getting a |ViewMsg_EnableIntrinsicWidthChangedMode|
2038 // message.
2039 // TODO(rafaelw): Figure out where the best place to set this for extensions
2040 // is. It isn't clean to test for ExtensionView by examining the
2041 // enabled_bindings. This needs to be generalized as it becomes clear what
2042 // extension toolbars need.
2043 if (BindingsPolicy::is_extension_enabled(enabled_bindings_) ||
2044 send_preferred_width_changes_) {
2045 // WebCore likes to tell us things have changed even when they haven't, so
2046 // cache the width and only send the IPC message when we're sure the
2047 // width is different.
[email protected]dd7daa82009-08-10 05:46:452048 int width = webview()->GetMainFrame()->contentsPreferredWidth();
[email protected]0666aef2009-05-13 19:48:082049 if (width != preferred_width_) {
2050 Send(new ViewHostMsg_DidContentsPreferredWidthChange(routing_id_, width));
2051 preferred_width_ = width;
2052 }
[email protected]1d522202009-04-04 01:56:422053 }
2054}
2055
initial.commit09911bf2008-07-26 23:55:292056// We are supposed to get a single call to Show for a newly created RenderView
2057// that was created via RenderView::CreateWebView. So, we wait until this
2058// point to dispatch the ShowView message.
2059//
2060// This method provides us with the information about how to display the newly
2061// created RenderView (i.e., as a constrained popup or as a new tab).
2062//
[email protected]4873c7d2009-07-16 06:36:282063void RenderView::show(WebNavigationPolicy policy) {
initial.commit09911bf2008-07-26 23:55:292064 DCHECK(!did_show_) << "received extraneous Show call";
2065 DCHECK(opener_id_ != MSG_ROUTING_NONE);
2066
2067 if (did_show_)
2068 return;
2069 did_show_ = true;
2070
2071 // NOTE: initial_pos_ may still have its default values at this point, but
2072 // that's okay. It'll be ignored if disposition is not NEW_POPUP, or the
2073 // browser process will impose a default position otherwise.
[email protected]4873c7d2009-07-16 06:36:282074 Send(new ViewHostMsg_ShowView(opener_id_, routing_id_,
2075 NavigationPolicyToDisposition(policy), initial_pos_,
2076 opened_by_user_gesture_, creator_url_));
[email protected]2533ce12009-05-09 00:02:242077 SetPendingWindowRect(initial_pos_);
initial.commit09911bf2008-07-26 23:55:292078}
2079
[email protected]4873c7d2009-07-16 06:36:282080void RenderView::closeWidgetSoon() {
[email protected]2c4410d2009-05-06 23:46:222081 if (!popup_notification_visible_)
[email protected]4873c7d2009-07-16 06:36:282082 RenderWidget::closeWidgetSoon();
[email protected]634a6f92008-12-01 21:39:312083}
2084
[email protected]4873c7d2009-07-16 06:36:282085void RenderView::runModal() {
initial.commit09911bf2008-07-26 23:55:292086 DCHECK(did_show_) << "should already have shown the view";
2087
2088 IPC::SyncMessage* msg = new ViewHostMsg_RunModal(routing_id_);
2089
[email protected]1c4947f2009-01-15 22:25:112090 msg->set_pump_messages_event(modal_dialog_event_.get());
initial.commit09911bf2008-07-26 23:55:292091 Send(msg);
2092}
2093
2094void RenderView::SyncNavigationState() {
2095 if (!webview())
2096 return;
2097
[email protected]dd7daa82009-08-10 05:46:452098 const WebHistoryItem& item = webview()->GetMainFrame()->currentHistoryItem();
[email protected]ca948a22009-06-25 19:36:172099 if (item.isNull())
initial.commit09911bf2008-07-26 23:55:292100 return;
[email protected]ca948a22009-06-25 19:36:172101
2102 Send(new ViewHostMsg_UpdateState(
2103 routing_id_, page_id_, webkit_glue::HistoryItemToString(item)));
initial.commit09911bf2008-07-26 23:55:292104}
2105
2106void RenderView::ShowContextMenu(WebView* webview,
[email protected]581b87eb2009-07-23 23:06:562107 ContextNodeType node_type,
initial.commit09911bf2008-07-26 23:55:292108 int x,
2109 int y,
2110 const GURL& link_url,
[email protected]574a1d62009-07-17 03:23:462111 const GURL& src_url,
initial.commit09911bf2008-07-26 23:55:292112 const GURL& page_url,
2113 const GURL& frame_url,
[email protected]574a1d62009-07-17 03:23:462114 const ContextMenuMediaParams& media_params,
initial.commit09911bf2008-07-26 23:55:292115 const std::wstring& selection_text,
2116 const std::wstring& misspelled_word,
[email protected]6aa376b2008-09-23 18:49:522117 int edit_flags,
[email protected]c9825a42009-05-01 22:51:502118 const std::string& security_info,
2119 const std::string& frame_charset) {
[email protected]e09ba552009-02-05 03:26:292120 ContextMenuParams params;
[email protected]581b87eb2009-07-23 23:06:562121 params.node_type = node_type;
initial.commit09911bf2008-07-26 23:55:292122 params.x = x;
2123 params.y = y;
[email protected]574a1d62009-07-17 03:23:462124 params.src_url = src_url;
initial.commit09911bf2008-07-26 23:55:292125 params.link_url = link_url;
[email protected]e6c79812009-04-22 22:31:422126 params.unfiltered_link_url = link_url;
initial.commit09911bf2008-07-26 23:55:292127 params.page_url = page_url;
2128 params.frame_url = frame_url;
[email protected]574a1d62009-07-17 03:23:462129 params.media_params = media_params;
initial.commit09911bf2008-07-26 23:55:292130 params.selection_text = selection_text;
2131 params.misspelled_word = misspelled_word;
[email protected]be645db2009-02-06 20:36:332132 params.spellcheck_enabled =
[email protected]dd7daa82009-08-10 05:46:452133 webview->GetFocusedFrame()->isContinuousSpellCheckingEnabled();
initial.commit09911bf2008-07-26 23:55:292134 params.edit_flags = edit_flags;
[email protected]6aa376b2008-09-23 18:49:522135 params.security_info = security_info;
[email protected]c9825a42009-05-01 22:51:502136 params.frame_charset = frame_charset;
initial.commit09911bf2008-07-26 23:55:292137 Send(new ViewHostMsg_ContextMenu(routing_id_, params));
2138}
2139
[email protected]e80c73b2009-04-07 23:24:582140void RenderView::StartDragging(WebView* webview,
2141 const WebDragData& drag_data) {
2142 Send(new ViewHostMsg_StartDragging(routing_id_, WebDropData(drag_data)));
initial.commit09911bf2008-07-26 23:55:292143}
2144
2145void RenderView::TakeFocus(WebView* webview, bool reverse) {
2146 Send(new ViewHostMsg_TakeFocus(routing_id_, reverse));
2147}
2148
2149void RenderView::DidDownloadImage(int id,
2150 const GURL& image_url,
2151 bool errored,
2152 const SkBitmap& image) {
[email protected]bf5c2ff392009-07-08 16:24:332153 Send(new ViewHostMsg_DidDownloadFavIcon(routing_id_, id, image_url, errored,
2154 image));
initial.commit09911bf2008-07-26 23:55:292155}
2156
[email protected]bf5c2ff392009-07-08 16:24:332157void RenderView::OnDownloadFavIcon(int id,
2158 const GURL& image_url,
2159 int image_size) {
[email protected]f11ca0732009-04-11 00:09:342160 bool data_image_failed = false;
2161 if (image_url.SchemeIs("data")) {
2162 SkBitmap data_image = ImageFromDataUrl(image_url);
2163 data_image_failed = data_image.empty();
2164 if (!data_image_failed) {
[email protected]bf5c2ff392009-07-08 16:24:332165 Send(new ViewHostMsg_DidDownloadFavIcon(routing_id_, id, image_url, false,
2166 data_image));
[email protected]f11ca0732009-04-11 00:09:342167 }
2168 }
2169
[email protected]bf5c2ff392009-07-08 16:24:332170 if (data_image_failed ||
2171 !webview()->DownloadImage(id, image_url, image_size)) {
2172 Send(new ViewHostMsg_DidDownloadFavIcon(routing_id_, id, image_url, true,
2173 SkBitmap()));
2174 }
initial.commit09911bf2008-07-26 23:55:292175}
2176
[email protected]f11ca0732009-04-11 00:09:342177SkBitmap RenderView::ImageFromDataUrl(const GURL& url) const {
2178 std::string mime_type, char_set, data;
2179 if (net::DataURL::Parse(url, &mime_type, &char_set, &data) && !data.empty()) {
2180 // Decode the favicon using WebKit's image decoder.
2181 webkit_glue::ImageDecoder decoder(gfx::Size(kFavIconSize, kFavIconSize));
2182 const unsigned char* src_data =
2183 reinterpret_cast<const unsigned char*>(&data[0]);
2184
2185 return decoder.Decode(src_data, data.size());
2186 }
2187 return SkBitmap();
2188}
2189
initial.commit09911bf2008-07-26 23:55:292190void RenderView::OnGetApplicationInfo(int page_id) {
2191 webkit_glue::WebApplicationInfo app_info;
2192 if (page_id == page_id_)
2193 webkit_glue::GetApplicationInfo(webview(), &app_info);
2194
2195 // Prune out any data URLs in the set of icons. The browser process expects
2196 // any icon with a data URL to have originated from a favicon. We don't want
2197 // to decode arbitrary data URLs in the browser process. See
2198 // http://b/issue?id=1162972
2199 for (size_t i = 0; i < app_info.icons.size(); ++i) {
[email protected]6de74452009-02-25 18:04:592200 if (app_info.icons[i].url.SchemeIs(chrome::kDataScheme)) {
initial.commit09911bf2008-07-26 23:55:292201 app_info.icons.erase(app_info.icons.begin() + i);
2202 --i;
2203 }
2204 }
2205
2206 Send(new ViewHostMsg_DidGetApplicationInfo(routing_id_, page_id, app_info));
2207}
2208
[email protected]7ccddb8c2009-08-04 17:36:552209GURL RenderView::GetAlternateErrorPageURL(const GURL& failed_url,
initial.commit09911bf2008-07-26 23:55:292210 ErrorPageType error_type) {
[email protected]7ccddb8c2009-08-04 17:36:552211 if (failed_url.SchemeIsSecure()) {
initial.commit09911bf2008-07-26 23:55:292212 // If the URL that failed was secure, then the embedding web page was not
2213 // expecting a network attacker to be able to manipulate its contents. As
2214 // we fetch alternate error pages over HTTP, we would be allowing a network
2215 // attacker to manipulate the contents of the response if we tried to use
2216 // the link doctor here.
2217 return GURL::EmptyGURL();
2218 }
2219
2220 // Grab the base URL from the browser process.
2221 if (!alternate_error_page_url_.is_valid())
2222 return GURL::EmptyGURL();
2223
2224 // Strip query params from the failed URL.
2225 GURL::Replacements remove_params;
2226 remove_params.ClearUsername();
2227 remove_params.ClearPassword();
2228 remove_params.ClearQuery();
2229 remove_params.ClearRef();
[email protected]7ccddb8c2009-08-04 17:36:552230 const GURL url_to_send = failed_url.ReplaceComponents(remove_params);
initial.commit09911bf2008-07-26 23:55:292231
2232 // Construct the query params to send to link doctor.
2233 std::string params(alternate_error_page_url_.query());
2234 params.append("&url=");
2235 params.append(EscapeQueryParamValue(url_to_send.spec()));
2236 params.append("&sourceid=chrome");
2237 params.append("&error=");
2238 switch (error_type) {
2239 case DNS_ERROR:
2240 params.append("dnserror");
2241 break;
2242
2243 case HTTP_404:
2244 params.append("http404");
2245 break;
2246
[email protected]5df266ac2008-10-15 19:50:132247 case CONNECTION_ERROR:
[email protected]e1f934b2009-01-26 20:41:332248 params.append("connectionfailure");
[email protected]5df266ac2008-10-15 19:50:132249 break;
2250
initial.commit09911bf2008-07-26 23:55:292251 default:
2252 NOTREACHED() << "unknown ErrorPageType";
2253 }
2254
2255 // OK, build the final url to return.
2256 GURL::Replacements link_doctor_params;
2257 link_doctor_params.SetQueryStr(params);
2258 GURL url = alternate_error_page_url_.ReplaceComponents(link_doctor_params);
2259 return url;
2260}
2261
[email protected]7ea066a2009-04-06 20:21:592262void RenderView::OnFind(int request_id,
2263 const string16& search_text,
2264 const WebKit::WebFindOptions& options) {
initial.commit09911bf2008-07-26 23:55:292265 WebFrame* main_frame = webview()->GetMainFrame();
2266 WebFrame* frame_after_main = webview()->GetNextFrameAfter(main_frame, true);
2267 WebFrame* focused_frame = webview()->GetFocusedFrame();
2268 WebFrame* search_frame = focused_frame; // start searching focused frame.
2269
2270 bool multi_frame = (frame_after_main != main_frame);
2271
2272 // If we have multiple frames, we don't want to wrap the search within the
2273 // frame, so we check here if we only have main_frame in the chain.
2274 bool wrap_within_frame = !multi_frame;
2275
[email protected]b3f2b912009-04-09 16:18:522276 WebRect selection_rect;
initial.commit09911bf2008-07-26 23:55:292277 bool result = false;
2278
2279 do {
[email protected]dd7daa82009-08-10 05:46:452280 result = search_frame->find(
[email protected]7ea066a2009-04-06 20:21:592281 request_id, search_text, options, wrap_within_frame, &selection_rect);
initial.commit09911bf2008-07-26 23:55:292282
2283 if (!result) {
2284 // don't leave text selected as you move to the next frame.
[email protected]a100d76bb2009-08-14 17:50:222285 search_frame->executeCommand(WebString::fromUTF8("Unselect"));
initial.commit09911bf2008-07-26 23:55:292286
2287 // Find the next frame, but skip the invisible ones.
2288 do {
2289 // What is the next frame to search? (we might be going backwards). Note
2290 // that we specify wrap=true so that search_frame never becomes NULL.
[email protected]7ea066a2009-04-06 20:21:592291 search_frame = options.forward ?
initial.commit09911bf2008-07-26 23:55:292292 webview()->GetNextFrameAfter(search_frame, true) :
2293 webview()->GetPreviousFrameBefore(search_frame, true);
[email protected]dd7daa82009-08-10 05:46:452294 } while (!search_frame->hasVisibleContent() &&
2295 search_frame != focused_frame);
initial.commit09911bf2008-07-26 23:55:292296
[email protected]884db412008-11-24 23:46:502297 // Make sure selection doesn't affect the search operation in new frame.
[email protected]a100d76bb2009-08-14 17:50:222298 search_frame->executeCommand(WebString::fromUTF8("Unselect"));
initial.commit09911bf2008-07-26 23:55:292299
2300 // If we have multiple frames and we have wrapped back around to the
2301 // focused frame, we need to search it once more allowing wrap within
2302 // the frame, otherwise it will report 'no match' if the focused frame has
2303 // reported matches, but no frames after the focused_frame contain a
2304 // match for the search word(s).
2305 if (multi_frame && search_frame == focused_frame) {
[email protected]dd7daa82009-08-10 05:46:452306 result = search_frame->find(
[email protected]7ea066a2009-04-06 20:21:592307 request_id, search_text, options, true, // Force wrapping.
2308 &selection_rect);
initial.commit09911bf2008-07-26 23:55:292309 }
2310 }
2311
initial.commit09911bf2008-07-26 23:55:292312 webview()->SetFocusedFrame(search_frame);
2313 } while (!result && search_frame != focused_frame);
2314
[email protected]7ea066a2009-04-06 20:21:592315 if (options.findNext) {
[email protected]4f3dc372009-02-24 00:10:292316 // Force the main_frame to report the actual count.
[email protected]dd7daa82009-08-10 05:46:452317 main_frame->increaseMatchCount(0, request_id);
[email protected]4f3dc372009-02-24 00:10:292318 } else {
2319 // If nothing is found, set result to "0 of 0", otherwise, set it to
2320 // "-1 of 1" to indicate that we found at least one item, but we don't know
2321 // yet what is active.
2322 int ordinal = result ? -1 : 0; // -1 here means, we might know more later.
2323 int match_count = result ? 1 : 0; // 1 here means possibly more coming.
initial.commit09911bf2008-07-26 23:55:292324
[email protected]4f3dc372009-02-24 00:10:292325 // If we find no matches then this will be our last status update.
2326 // Otherwise the scoping effort will send more results.
2327 bool final_status_update = !result;
initial.commit09911bf2008-07-26 23:55:292328
[email protected]4f3dc372009-02-24 00:10:292329 // Send the search result over to the browser process.
[email protected]4f999132009-03-31 18:08:402330 Send(new ViewHostMsg_Find_Reply(routing_id_,
[email protected]7ea066a2009-04-06 20:21:592331 request_id,
[email protected]4f3dc372009-02-24 00:10:292332 match_count,
2333 selection_rect,
2334 ordinal,
2335 final_status_update));
initial.commit09911bf2008-07-26 23:55:292336
initial.commit09911bf2008-07-26 23:55:292337 // Scoping effort begins, starting with the mainframe.
2338 search_frame = main_frame;
2339
[email protected]dd7daa82009-08-10 05:46:452340 main_frame->resetMatchCount();
initial.commit09911bf2008-07-26 23:55:292341
2342 do {
2343 // Cancel all old scoping requests before starting a new one.
[email protected]dd7daa82009-08-10 05:46:452344 search_frame->cancelPendingScopingEffort();
initial.commit09911bf2008-07-26 23:55:292345
2346 // We don't start another scoping effort unless at least one match has
2347 // been found.
2348 if (result) {
2349 // Start new scoping request. If the scoping function determines that it
2350 // needs to scope, it will defer until later.
[email protected]dd7daa82009-08-10 05:46:452351 search_frame->scopeStringMatches(request_id,
[email protected]7ea066a2009-04-06 20:21:592352 search_text,
2353 options,
initial.commit09911bf2008-07-26 23:55:292354 true); // reset the tickmarks
2355 }
2356
2357 // Iterate to the next frame. The frame will not necessarily scope, for
2358 // example if it is not visible.
2359 search_frame = webview()->GetNextFrameAfter(search_frame, true);
2360 } while (search_frame != main_frame);
2361 }
2362}
2363
[email protected]5c4266922009-07-10 16:41:272364void RenderView::OnDeterminePageText() {
2365 if (!is_loading_) {
2366 if (!webview())
2367 return;
2368 WebFrame* main_frame = webview()->GetMainFrame();
2369 std::wstring contents;
2370 CaptureText(main_frame, &contents);
2371 Send(new ViewMsg_DeterminePageText_Reply(routing_id_, contents));
2372 determine_page_text_after_loading_stops_ = false;
2373 return;
2374 }
2375
2376 // We set |determine_page_text_after_loading_stops_| true here so that,
2377 // after page has been loaded completely, the text in the page is captured.
2378 determine_page_text_after_loading_stops_ = true;
2379}
2380
initial.commit09911bf2008-07-26 23:55:292381void RenderView::ReportFindInPageMatchCount(int count, int request_id,
2382 bool final_update) {
2383 // If we have a message that has been queued up, then we should just replace
2384 // it. The ACK from the browser will make sure it gets sent when the browser
2385 // wants it.
2386 if (queued_find_reply_message_.get()) {
2387 IPC::Message* msg = new ViewHostMsg_Find_Reply(
2388 routing_id_,
2389 request_id,
2390 count,
[email protected]b3f2b912009-04-09 16:18:522391 gfx::Rect(),
initial.commit09911bf2008-07-26 23:55:292392 -1, // Don't update active match ordinal.
2393 final_update);
2394 queued_find_reply_message_.reset(msg);
2395 } else {
2396 // Send the search result over to the browser process.
2397 Send(new ViewHostMsg_Find_Reply(
2398 routing_id_,
2399 request_id,
2400 count,
[email protected]b3f2b912009-04-09 16:18:522401 gfx::Rect(),
initial.commit09911bf2008-07-26 23:55:292402 -1, // // Don't update active match ordinal.
2403 final_update));
2404 }
2405}
2406
2407void RenderView::ReportFindInPageSelection(int request_id,
2408 int active_match_ordinal,
[email protected]b3f2b912009-04-09 16:18:522409 const WebRect& selection_rect) {
initial.commit09911bf2008-07-26 23:55:292410 // Send the search result over to the browser process.
2411 Send(new ViewHostMsg_Find_Reply(routing_id_,
2412 request_id,
2413 -1,
2414 selection_rect,
2415 active_match_ordinal,
2416 false));
2417}
2418
[email protected]ed4bf2d2009-05-05 00:10:062419bool RenderView::WasOpenedByUserGesture() const {
initial.commit09911bf2008-07-26 23:55:292420 return opened_by_user_gesture_;
2421}
2422
[email protected]7f40fc5b2009-06-12 19:23:082423void RenderView::SpellCheck(const std::wstring& word, int* misspell_location,
2424 int* misspell_length) {
2425 Send(new ViewHostMsg_SpellCheck(routing_id_, word, misspell_location,
2426 misspell_length));
initial.commit09911bf2008-07-26 23:55:292427}
2428
[email protected]26ea6c42009-06-10 22:32:212429std::wstring RenderView::GetAutoCorrectWord(
2430 const std::wstring& misspelled_word) {
2431 std::wstring autocorrect_word;
[email protected]eda2b5a2009-05-12 19:30:212432 const CommandLine& command_line = *CommandLine::ForCurrentProcess();
2433 if (command_line.HasSwitch(switches::kAutoSpellCorrect)) {
2434 Send(new ViewHostMsg_GetAutoCorrectWord(routing_id_, misspelled_word,
2435 &autocorrect_word));
2436 }
[email protected]26ea6c42009-06-10 22:32:212437
2438 return autocorrect_word;
[email protected]eda2b5a2009-05-12 19:30:212439}
2440
initial.commit09911bf2008-07-26 23:55:292441void RenderView::SetInputMethodState(bool enabled) {
2442 // Save the updated IME status and mark the input focus has been updated.
2443 // The IME status is to be sent to a browser process next time when
2444 // the input caret is rendered.
[email protected]9f23f592008-11-17 08:36:342445 if (!ime_control_busy_) {
2446 ime_control_updated_ = true;
2447 ime_control_new_state_ = enabled;
2448 }
initial.commit09911bf2008-07-26 23:55:292449}
2450
2451void RenderView::ScriptedPrint(WebFrame* frame) {
[email protected]aa82249f2009-07-16 17:23:582452 DCHECK(webview());
2453 if (webview()) {
2454 // Print the full page - not just the frame the javascript is running from.
2455 Print(webview()->GetMainFrame(), true);
2456 }
initial.commit09911bf2008-07-26 23:55:292457}
2458
initial.commit09911bf2008-07-26 23:55:292459void RenderView::UserMetricsRecordAction(const std::wstring& action) {
2460 Send(new ViewHostMsg_UserMetricsRecordAction(routing_id_, action));
2461}
2462
2463void RenderView::DnsPrefetch(const std::vector<std::string>& host_names) {
2464 Send(new ViewHostMsg_DnsPrefetch(host_names));
2465}
2466
[email protected]630e26b2008-10-14 22:55:172467void RenderView::OnZoom(int function) {
2468 static const bool kZoomIsTextOnly = false;
2469 switch (function) {
2470 case PageZoom::SMALLER:
2471 webview()->ZoomOut(kZoomIsTextOnly);
initial.commit09911bf2008-07-26 23:55:292472 break;
[email protected]630e26b2008-10-14 22:55:172473 case PageZoom::STANDARD:
2474 webview()->ResetZoom();
initial.commit09911bf2008-07-26 23:55:292475 break;
[email protected]630e26b2008-10-14 22:55:172476 case PageZoom::LARGER:
2477 webview()->ZoomIn(kZoomIsTextOnly);
initial.commit09911bf2008-07-26 23:55:292478 break;
2479 default:
2480 NOTREACHED();
2481 }
2482}
2483
[email protected]ea8c7452009-04-02 20:47:062484void RenderView::OnInsertText(const string16& text) {
[email protected]5f9e0b82009-05-08 22:13:392485 WebFrame* frame = webview()->GetFocusedFrame();
2486 if (!frame)
2487 return;
[email protected]dd7daa82009-08-10 05:46:452488 frame->insertText(text);
[email protected]ea8c7452009-04-02 20:47:062489}
2490
[email protected]e38f40152008-09-12 23:08:302491void RenderView::OnSetPageEncoding(const std::wstring& encoding_name) {
initial.commit09911bf2008-07-26 23:55:292492 webview()->SetPageEncoding(encoding_name);
2493}
2494
[email protected]f6e59a62009-05-13 21:12:032495void RenderView::NavigateBackForwardSoon(int offset) {
[email protected]f46aff62008-10-16 07:58:052496 history_back_list_count_ += offset;
2497 history_forward_list_count_ -= offset;
2498
initial.commit09911bf2008-07-26 23:55:292499 Send(new ViewHostMsg_GoToEntryAtOffset(routing_id_, offset));
2500}
2501
2502int RenderView::GetHistoryBackListCount() {
2503 return history_back_list_count_;
2504}
2505
2506int RenderView::GetHistoryForwardListCount() {
2507 return history_forward_list_count_;
2508}
2509
2510void RenderView::OnNavStateChanged(WebView* webview) {
[email protected]81a34412009-01-05 19:17:242511 if (!nav_state_sync_timer_.IsRunning()) {
2512 nav_state_sync_timer_.Start(
2513 TimeDelta::FromSeconds(delay_seconds_for_form_state_sync_), this,
2514 &RenderView::SyncNavigationState);
2515 }
initial.commit09911bf2008-07-26 23:55:292516}
2517
2518void RenderView::SetTooltipText(WebView* webview,
[email protected]de570ef2009-07-29 18:27:522519 const std::wstring& tooltip_text,
2520 WebTextDirection text_direction_hint) {
2521 Send(new ViewHostMsg_SetTooltipText(routing_id_, tooltip_text,
2522 text_direction_hint));
initial.commit09911bf2008-07-26 23:55:292523}
2524
[email protected]2e417c82009-04-02 22:30:262525void RenderView::DidChangeSelection(bool is_empty_selection) {
2526#if defined(OS_LINUX)
[email protected]5dd768212009-08-13 23:34:492527 if (!handling_input_event_)
2528 return;
[email protected]d5d7b8002009-05-18 21:20:542529 // TODO(estade): investigate incremental updates to the selection so that we
2530 // don't send the entire selection over IPC every time.
[email protected]2e417c82009-04-02 22:30:262531 if (!is_empty_selection) {
[email protected]d5d7b8002009-05-18 21:20:542532 // Sometimes we get repeated DidChangeSelection calls from webkit when
2533 // the selection hasn't actually changed. We don't want to report these
2534 // because it will cause us to continually claim the X clipboard.
2535 const std::string& this_selection =
[email protected]dd7daa82009-08-10 05:46:452536 webview()->GetFocusedFrame()->selectionAsText().utf8();
[email protected]d5d7b8002009-05-18 21:20:542537 if (this_selection == last_selection_)
2538 return;
2539
[email protected]dbadbcc2009-04-09 00:57:102540 Send(new ViewHostMsg_SelectionChanged(routing_id_,
[email protected]d5d7b8002009-05-18 21:20:542541 this_selection));
2542 last_selection_ = this_selection;
[email protected]4f61a022009-06-25 23:49:012543 } else {
2544 last_selection_.clear();
[email protected]2e417c82009-04-02 22:30:262545 }
2546#endif
2547}
2548
initial.commit09911bf2008-07-26 23:55:292549void RenderView::DownloadUrl(const GURL& url, const GURL& referrer) {
2550 Send(new ViewHostMsg_DownloadUrl(routing_id_, url, referrer));
2551}
2552
[email protected]0df30122009-06-03 12:13:082553void RenderView::UpdateInspectorSettings(const std::wstring& raw_settings) {
2554 Send(new ViewHostMsg_UpdateInspectorSettings(routing_id_, raw_settings));
2555}
2556
[email protected]611cad42009-03-16 18:51:342557WebDevToolsAgentDelegate* RenderView::GetWebDevToolsAgentDelegate() {
[email protected]b75b7d072009-04-06 13:47:002558 return devtools_agent_.get();
[email protected]611cad42009-03-16 18:51:342559}
2560
[email protected]ea8c7452009-04-02 20:47:062561void RenderView::PasteFromSelectionClipboard() {
2562 Send(new ViewHostMsg_PasteFromSelectionClipboard(routing_id_));
2563}
2564
[email protected]dd7daa82009-08-10 05:46:452565WebFrame* RenderView::GetChildFrame(const std::wstring& xpath) const {
2566 if (xpath.empty())
2567 return webview()->GetMainFrame();
2568
2569 // xpath string can represent a frame deep down the tree (across multiple
2570 // frame DOMs).
2571 // Example, /html/body/table/tbody/tr/td/iframe\n/frameset/frame[0]
2572 // should break into 2 xpaths
2573 // /html/body/table/tbody/tr/td/iframe & /frameset/frame[0]
2574
2575 WebFrame* frame = webview()->GetMainFrame();
2576
2577 std::wstring xpath_remaining = xpath;
2578 while (!xpath_remaining.empty()) {
2579 std::wstring::size_type delim_pos = xpath_remaining.find_first_of(L'\n');
2580 std::wstring xpath_child;
2581 if (delim_pos != std::wstring::npos) {
2582 xpath_child = xpath_remaining.substr(0, delim_pos);
2583 xpath_remaining.erase(0, delim_pos + 1);
2584 } else {
2585 xpath_remaining.swap(xpath_child);
2586 }
2587 frame = frame->findChildByExpression(WideToUTF16Hack(xpath_child));
initial.commit09911bf2008-07-26 23:55:292588 }
2589
[email protected]dd7daa82009-08-10 05:46:452590 return frame;
initial.commit09911bf2008-07-26 23:55:292591}
2592
[email protected]f29acf52008-11-03 20:08:332593void RenderView::EvaluateScript(const std::wstring& frame_xpath,
2594 const std::wstring& script) {
initial.commit09911bf2008-07-26 23:55:292595 WebFrame* web_frame = GetChildFrame(frame_xpath);
2596 if (!web_frame)
2597 return;
2598
[email protected]dd7daa82009-08-10 05:46:452599 web_frame->executeScript(WebScriptSource(WideToUTF16Hack(script)));
initial.commit09911bf2008-07-26 23:55:292600}
2601
[email protected]1810e132009-03-24 23:35:482602void RenderView::InsertCSS(const std::wstring& frame_xpath,
2603 const std::string& css) {
2604 WebFrame* web_frame = GetChildFrame(frame_xpath);
2605 if (!web_frame)
2606 return;
2607
[email protected]dd7daa82009-08-10 05:46:452608 web_frame->insertStyleText(WebString::fromUTF8(css));
[email protected]1810e132009-03-24 23:35:482609}
2610
initial.commit09911bf2008-07-26 23:55:292611void RenderView::OnScriptEvalRequest(const std::wstring& frame_xpath,
2612 const std::wstring& jscript) {
[email protected]f29acf52008-11-03 20:08:332613 EvaluateScript(frame_xpath, jscript);
initial.commit09911bf2008-07-26 23:55:292614}
2615
[email protected]1810e132009-03-24 23:35:482616void RenderView::OnCSSInsertRequest(const std::wstring& frame_xpath,
2617 const std::string& css) {
2618 InsertCSS(frame_xpath, css);
[email protected]ae461542009-06-19 19:03:412619
2620 // Notify RenderViewHost that css has been inserted into the frame.
2621 Send(new ViewHostMsg_OnCSSInserted(routing_id_));
[email protected]1810e132009-03-24 23:35:482622}
2623
[email protected]7ea066a2009-04-06 20:21:592624void RenderView::OnAddMessageToConsole(
2625 const string16& frame_xpath,
2626 const string16& message,
2627 const WebConsoleMessage::Level& level) {
2628 WebFrame* web_frame = GetChildFrame(UTF16ToWideHack(frame_xpath));
[email protected]0dea3ea2009-03-31 23:30:592629 if (web_frame)
[email protected]dd7daa82009-08-10 05:46:452630 web_frame->addMessageToConsole(WebConsoleMessage(level, message));
initial.commit09911bf2008-07-26 23:55:292631}
2632
[email protected]81e63782009-02-27 19:35:092633void RenderView::OnAllowBindings(int enabled_bindings_flags) {
2634 enabled_bindings_ |= enabled_bindings_flags;
initial.commit09911bf2008-07-26 23:55:292635}
2636
2637void RenderView::OnSetDOMUIProperty(const std::string& name,
2638 const std::string& value) {
[email protected]81e63782009-02-27 19:35:092639 DCHECK(BindingsPolicy::is_dom_ui_enabled(enabled_bindings_));
initial.commit09911bf2008-07-26 23:55:292640 dom_ui_bindings_.SetProperty(name, value);
2641}
2642
2643void RenderView::OnReservePageIDRange(int size_of_range) {
2644 next_page_id_ += size_of_range + 1;
2645}
2646
[email protected]e80c73b2009-04-07 23:24:582647void RenderView::OnDragSourceEndedOrMoved(const gfx::Point& client_point,
2648 const gfx::Point& screen_point,
[email protected]5f9ae6c2009-07-08 02:38:032649 bool ended, bool cancelled) {
2650 if (ended) {
2651 if (cancelled)
2652 webview()->DragSourceCancelledAt(client_point, screen_point);
2653 else
2654 webview()->DragSourceEndedAt(client_point, screen_point);
2655 } else {
[email protected]e80c73b2009-04-07 23:24:582656 webview()->DragSourceMovedTo(client_point, screen_point);
[email protected]5f9ae6c2009-07-08 02:38:032657 }
initial.commit09911bf2008-07-26 23:55:292658}
2659
2660void RenderView::OnDragSourceSystemDragEnded() {
2661 webview()->DragSourceSystemDragEnded();
2662}
2663
2664void RenderView::OnUploadFileRequest(const ViewMsg_UploadFile_Params& p) {
2665 webkit_glue::FileUploadData* f = new webkit_glue::FileUploadData;
2666 f->file_path = p.file_path;
2667 f->form_name = p.form;
2668 f->file_name = p.file;
2669 f->submit_name = p.submit;
2670
2671 // Build the other form values map.
2672 if (!p.other_values.empty()) {
2673 std::vector<std::wstring> e;
2674 std::vector<std::wstring> kvp;
2675 std::vector<std::wstring>::iterator i;
2676
2677 SplitString(p.other_values, L'\n', &e);
2678 for (i = e.begin(); i != e.end(); ++i) {
2679 SplitString(*i, L'=', &kvp);
2680 if (kvp.size() == 2)
2681 f->other_form_values[kvp[0]] = kvp[1];
2682 kvp.clear();
2683 }
2684 }
2685
2686 pending_upload_data_.reset(f);
2687 ProcessPendingUpload();
2688}
2689
2690void RenderView::ProcessPendingUpload() {
2691 webkit_glue::FileUploadData* f = pending_upload_data_.get();
2692 if (f && webview() && webkit_glue::FillFormToUploadFile(webview(), *f))
2693 ResetPendingUpload();
2694}
2695
2696void RenderView::ResetPendingUpload() {
2697 pending_upload_data_.reset();
2698}
2699
2700void RenderView::OnFormFill(const FormData& form) {
2701 webkit_glue::FillForm(this->webview(), form);
2702}
2703
2704void RenderView::OnFillPasswordForm(
[email protected]daa8c58e2009-06-15 17:21:102705 const webkit_glue::PasswordFormDomManager::FillData& form_data) {
initial.commit09911bf2008-07-26 23:55:292706 webkit_glue::FillPasswordForm(this->webview(), form_data);
2707}
2708
2709void RenderView::OnDragTargetDragEnter(const WebDropData& drop_data,
[email protected]e80c73b2009-04-07 23:24:582710 const gfx::Point& client_point,
2711 const gfx::Point& screen_point) {
2712 bool is_drop_target = webview()->DragTargetDragEnter(
2713 drop_data.ToDragData(),
2714 drop_data.identity,
2715 client_point,
2716 screen_point);
initial.commit09911bf2008-07-26 23:55:292717
2718 Send(new ViewHostMsg_UpdateDragCursor(routing_id_, is_drop_target));
2719}
2720
[email protected]e80c73b2009-04-07 23:24:582721void RenderView::OnDragTargetDragOver(const gfx::Point& client_point,
2722 const gfx::Point& screen_point) {
2723 bool is_drop_target =
2724 webview()->DragTargetDragOver(client_point, screen_point);
initial.commit09911bf2008-07-26 23:55:292725
2726 Send(new ViewHostMsg_UpdateDragCursor(routing_id_, is_drop_target));
2727}
2728
2729void RenderView::OnDragTargetDragLeave() {
2730 webview()->DragTargetDragLeave();
2731}
2732
[email protected]e80c73b2009-04-07 23:24:582733void RenderView::OnDragTargetDrop(const gfx::Point& client_point,
2734 const gfx::Point& screen_point) {
2735 webview()->DragTargetDrop(client_point, screen_point);
initial.commit09911bf2008-07-26 23:55:292736}
2737
2738void RenderView::OnUpdateWebPreferences(const WebPreferences& prefs) {
[email protected]2fab253a2009-08-17 23:00:592739 webkit_preferences_ = prefs;
2740 webkit_preferences_.Apply(webview());
initial.commit09911bf2008-07-26 23:55:292741}
2742
2743void RenderView::OnSetAltErrorPageURL(const GURL& url) {
2744 alternate_error_page_url_ = url;
2745}
2746
initial.commit09911bf2008-07-26 23:55:292747void RenderView::OnInstallMissingPlugin() {
2748 // This could happen when the first default plugin is deleted.
2749 if (first_default_plugin_ == NULL)
2750 return;
2751 first_default_plugin_->InstallMissingPlugin();
2752}
2753
[email protected]b62d1a8c2009-01-13 23:54:572754void RenderView::OnFileChooserResponse(
[email protected]561abe62009-04-06 18:08:342755 const std::vector<FilePath>& file_names) {
[email protected]8029f5672009-03-20 22:33:362756 // This could happen if we navigated to a different page before the user
2757 // closed the chooser.
2758 if (!file_chooser_.get())
2759 return;
2760
[email protected]b62d1a8c2009-01-13 23:54:572761 file_chooser_->OnFileChoose(file_names);
initial.commit09911bf2008-07-26 23:55:292762 file_chooser_.reset();
2763}
2764
2765void RenderView::OnEnableViewSourceMode() {
2766 if (!webview())
2767 return;
2768 WebFrame* main_frame = webview()->GetMainFrame();
2769 if (!main_frame)
2770 return;
2771
[email protected]dd7daa82009-08-10 05:46:452772 main_frame->enableViewSourceMode(true);
initial.commit09911bf2008-07-26 23:55:292773}
2774
[email protected]0666aef2009-05-13 19:48:082775void RenderView::OnEnableIntrinsicWidthChangedMode() {
2776 send_preferred_width_changes_ = true;
2777}
2778
[email protected]80d96fa2009-06-10 22:34:512779void RenderView::OnSetRendererPrefs(const RendererPreferences& renderer_prefs) {
2780 renderer_preferences_ = renderer_prefs;
[email protected]6e282c92009-07-24 01:19:372781 UpdateFontRenderingFromRendererPrefs();
[email protected]80d96fa2009-06-10 22:34:512782}
2783
[email protected]581b87eb2009-07-23 23:06:562784void RenderView::OnMediaPlayerActionAt(int x,
2785 int y,
2786 const MediaPlayerAction& action) {
2787 if (!webview())
2788 return;
2789
2790 webview()->MediaPlayerActionAt(x, y, action);
2791}
2792
[email protected]7b291f92009-08-14 05:43:532793void RenderView::OnNotifyRendererViewType(ViewType::Type type) {
2794 view_type_ = type;
2795}
2796
2797void RenderView::OnUpdateBrowserWindowId(int window_id) {
2798 browser_window_id_ = window_id;
2799}
2800
initial.commit09911bf2008-07-26 23:55:292801void RenderView::OnUpdateBackForwardListCount(int back_list_count,
2802 int forward_list_count) {
2803 history_back_list_count_ = back_list_count;
2804 history_forward_list_count_ = forward_list_count;
2805}
2806
[email protected]266eb6f2008-09-30 23:56:502807void RenderView::OnGetAccessibilityInfo(
[email protected]6a983b42009-03-20 20:12:252808 const webkit_glue::WebAccessibility::InParams& in_params,
2809 webkit_glue::WebAccessibility::OutParams* out_params) {
[email protected]6c8afae52009-01-22 02:24:572810#if defined(OS_WIN)
[email protected]6a983b42009-03-20 20:12:252811 if (!web_accessibility_manager_.get()) {
2812 web_accessibility_manager_.reset(
2813 webkit_glue::WebAccessibilityManager::Create());
2814 }
[email protected]266eb6f2008-09-30 23:56:502815
[email protected]6a983b42009-03-20 20:12:252816 if (!web_accessibility_manager_->GetAccObjInfo(webview(), in_params,
2817 out_params)) {
[email protected]266eb6f2008-09-30 23:56:502818 return;
2819 }
[email protected]6c8afae52009-01-22 02:24:572820#else // defined(OS_WIN)
2821 // TODO(port): accessibility not yet implemented
2822 NOTIMPLEMENTED();
2823#endif
[email protected]266eb6f2008-09-30 23:56:502824}
2825
[email protected]6a983b42009-03-20 20:12:252826void RenderView::OnClearAccessibilityInfo(int acc_obj_id, bool clear_all) {
[email protected]6c8afae52009-01-22 02:24:572827#if defined(OS_WIN)
[email protected]6a983b42009-03-20 20:12:252828 if (!web_accessibility_manager_.get()) {
[email protected]266eb6f2008-09-30 23:56:502829 // If accessibility is not activated, ignore clearing message.
2830 return;
2831 }
[email protected]e846d0d2009-05-20 00:53:062832
[email protected]6a983b42009-03-20 20:12:252833 if (!web_accessibility_manager_->ClearAccObjMap(acc_obj_id, clear_all))
[email protected]266eb6f2008-09-30 23:56:502834 return;
[email protected]e846d0d2009-05-20 00:53:062835
[email protected]6c8afae52009-01-22 02:24:572836#else // defined(OS_WIN)
2837 // TODO(port): accessibility not yet implemented
2838 NOTIMPLEMENTED();
2839#endif
[email protected]266eb6f2008-09-30 23:56:502840}
2841
initial.commit09911bf2008-07-26 23:55:292842void RenderView::OnGetAllSavableResourceLinksForCurrentPage(
2843 const GURL& page_url) {
2844 // Prepare list to storage all savable resource links.
2845 std::vector<GURL> resources_list;
2846 std::vector<GURL> referrers_list;
2847 std::vector<GURL> frames_list;
2848 webkit_glue::SavableResourcesResult result(&resources_list,
2849 &referrers_list,
2850 &frames_list);
2851
2852 if (!webkit_glue::GetAllSavableResourceLinksForCurrentPage(webview(),
2853 page_url,
2854 &result)) {
2855 // If something is wrong when collecting all savable resource links,
2856 // send empty list to embedder(browser) to tell it failed.
2857 referrers_list.clear();
2858 resources_list.clear();
2859 frames_list.clear();
2860 }
2861
2862 // Send result of all savable resource links to embedder.
2863 Send(new ViewHostMsg_SendCurrentPageAllSavableResourceLinks(routing_id_,
2864 resources_list,
2865 referrers_list,
2866 frames_list));
2867}
2868
2869void RenderView::OnGetSerializedHtmlDataForCurrentPageWithLocalLinks(
[email protected]f6b48532009-02-12 01:56:322870 const std::vector<GURL>& links,
[email protected]fde6714d12009-02-18 22:39:312871 const std::vector<FilePath>& local_paths,
2872 const FilePath& local_directory_name) {
initial.commit09911bf2008-07-26 23:55:292873 webkit_glue::DomSerializer dom_serializer(webview()->GetMainFrame(),
2874 true,
2875 this,
2876 links,
2877 local_paths,
2878 local_directory_name);
2879 dom_serializer.SerializeDom();
2880}
2881
2882void RenderView::DidSerializeDataForFrame(const GURL& frame_url,
2883 const std::string& data, PageSavingSerializationStatus status) {
2884 Send(new ViewHostMsg_SendSerializedHtmlData(routing_id_,
2885 frame_url, data, static_cast<int32>(status)));
2886}
2887
[email protected]04b4a6c2008-08-02 00:44:472888void RenderView::OnMsgShouldClose() {
initial.commit09911bf2008-07-26 23:55:292889 bool should_close = webview()->ShouldClose();
[email protected]04b4a6c2008-08-02 00:44:472890 Send(new ViewHostMsg_ShouldClose_ACK(routing_id_, should_close));
initial.commit09911bf2008-07-26 23:55:292891}
2892
[email protected]eb6b87a2009-07-24 15:57:392893void RenderView::OnClosePage(const ViewMsg_ClosePage_Params& params) {
initial.commit09911bf2008-07-26 23:55:292894 // TODO(creis): We'd rather use webview()->Close() here, but that currently
2895 // sets the WebView's delegate_ to NULL, preventing any JavaScript dialogs
2896 // in the onunload handler from appearing. For now, we're bypassing that and
2897 // calling the FrameLoader's CloseURL method directly. This should be
2898 // revisited to avoid having two ways to close a page. Having a single way
2899 // to close that can run onunload is also useful for fixing
2900 // http://b/issue?id=753080.
2901 WebFrame* main_frame = webview()->GetMainFrame();
[email protected]7a9b51f2009-06-29 21:28:292902 if (main_frame) {
[email protected]dd7daa82009-08-10 05:46:452903 const GURL& url = main_frame->url();
[email protected]7a9b51f2009-06-29 21:28:292904 // TODO(davemoore) this code should be removed once WillCloseFrame() gets
2905 // called when a page is destroyed. DumpLoadHistograms() is safe to call
2906 // multiple times for the same frame, but it will simplify things.
[email protected]dd7daa82009-08-10 05:46:452907 if (url.SchemeIs(chrome::kHttpScheme) ||
2908 url.SchemeIs(chrome::kHttpsScheme))
[email protected]7a9b51f2009-06-29 21:28:292909 DumpLoadHistograms();
[email protected]7a9b51f2009-06-29 21:28:292910 }
[email protected]e6fae1b2009-08-06 23:20:352911 webview()->ClosePage();
initial.commit09911bf2008-07-26 23:55:292912
[email protected]eb6b87a2009-07-24 15:57:392913 // Just echo back the params in the ACK.
2914 Send(new ViewHostMsg_ClosePage_ACK(routing_id_, params));
initial.commit09911bf2008-07-26 23:55:292915}
2916
2917void RenderView::OnThemeChanged() {
[email protected]6c8afae52009-01-22 02:24:572918#if defined(OS_WIN)
initial.commit09911bf2008-07-26 23:55:292919 gfx::NativeTheme::instance()->CloseHandles();
2920 gfx::Rect view_rect(0, 0, size_.width(), size_.height());
[email protected]4873c7d2009-07-16 06:36:282921 didInvalidateRect(view_rect);
[email protected]6c8afae52009-01-22 02:24:572922#else // defined(OS_WIN)
2923 // TODO(port): we don't support theming on non-Windows platforms yet
2924 NOTIMPLEMENTED();
2925#endif
initial.commit09911bf2008-07-26 23:55:292926}
2927
[email protected]f46aff62008-10-16 07:58:052928void RenderView::DidAddHistoryItem() {
[email protected]f8901082008-10-31 23:34:032929 // We don't want to update the history length for the start page
2930 // navigation.
2931 WebFrame* main_frame = webview()->GetMainFrame();
2932 DCHECK(main_frame != NULL);
2933
[email protected]dd7daa82009-08-10 05:46:452934 WebDataSource* ds = main_frame->dataSource();
[email protected]f8901082008-10-31 23:34:032935 DCHECK(ds != NULL);
2936
[email protected]daa8c58e2009-06-15 17:21:102937 NavigationState* navigation_state = NavigationState::FromDataSource(ds);
[email protected]78a3a6f2009-07-02 16:15:012938 DCHECK(navigation_state);
[email protected]daa8c58e2009-06-15 17:21:102939 if (navigation_state->transition_type() == PageTransition::START_PAGE)
[email protected]f8901082008-10-31 23:34:032940 return;
2941
[email protected]f46aff62008-10-16 07:58:052942 history_back_list_count_++;
2943 history_forward_list_count_ = 0;
2944}
2945
[email protected]28790922009-03-09 19:48:372946void RenderView::OnMessageFromExternalHost(const std::string& message,
2947 const std::string& origin,
2948 const std::string& target) {
[email protected]3ac14a052008-08-15 21:22:152949 if (message.empty())
2950 return;
2951
[email protected]28790922009-03-09 19:48:372952 external_host_bindings_.ForwardMessageFromExternalHost(message, origin,
2953 target);
[email protected]3ac14a052008-08-15 21:22:152954}
2955
[email protected]0aa55312008-10-17 21:53:082956void RenderView::OnDisassociateFromPopupCount() {
2957 if (decrement_shared_popup_at_destruction_)
2958 shared_popup_counter_->data--;
2959 shared_popup_counter_ = new SharedRenderViewCounter(0);
2960 decrement_shared_popup_at_destruction_ = false;
2961}
2962
[email protected]15d79e12009-08-02 19:23:452963bool RenderView::MaybeLoadAlternateErrorPage(WebFrame* frame,
2964 const WebURLError& error,
2965 bool replace) {
2966 // We only show alternate error pages in the main frame. They are
2967 // intended to assist the user when navigating, so there is not much
2968 // value in showing them for failed subframes. Ideally, we would be
2969 // able to use the TYPED transition type for this, but that flag is
2970 // not preserved across page reloads.
[email protected]dd7daa82009-08-10 05:46:452971 if (frame->parent())
[email protected]15d79e12009-08-02 19:23:452972 return false;
2973
2974 // Use the alternate error page service if this is a DNS failure or
[email protected]c53976d52009-08-07 18:58:372975 // connection failure.
[email protected]15d79e12009-08-02 19:23:452976 int ec = error.reason;
2977 if (ec != net::ERR_NAME_NOT_RESOLVED &&
2978 ec != net::ERR_CONNECTION_FAILED &&
2979 ec != net::ERR_CONNECTION_REFUSED &&
2980 ec != net::ERR_ADDRESS_UNREACHABLE &&
[email protected]c53976d52009-08-07 18:58:372981 ec != net::ERR_CONNECTION_TIMED_OUT)
[email protected]15d79e12009-08-02 19:23:452982 return false;
2983
2984 const GURL& error_page_url = GetAlternateErrorPageURL(error.unreachableURL,
[email protected]7ccddb8c2009-08-04 17:36:552985 ec == net::ERR_NAME_NOT_RESOLVED ? DNS_ERROR : CONNECTION_ERROR);
[email protected]15d79e12009-08-02 19:23:452986 if (!error_page_url.is_valid())
2987 return false;
2988
2989 // Load an empty page first so there is an immediate response to the error,
2990 // and then kick off a request for the alternate error page.
[email protected]dd7daa82009-08-10 05:46:452991 frame->loadHTMLString(std::string(),
[email protected]15d79e12009-08-02 19:23:452992 GURL(kUnreachableWebDataURL),
2993 error.unreachableURL,
2994 replace);
2995
2996 // Now, create a fetcher for the error page and associate it with the data
2997 // source we just created via the LoadHTMLString call. That way if another
2998 // navigation occurs, the fetcher will get destroyed.
2999 NavigationState* navigation_state =
[email protected]dd7daa82009-08-10 05:46:453000 NavigationState::FromDataSource(frame->provisionalDataSource());
[email protected]15d79e12009-08-02 19:23:453001 navigation_state->set_alt_error_page_fetcher(
3002 new AltErrorPageResourceFetcher(
3003 error_page_url, frame, error,
3004 NewCallback(this, &RenderView::AltErrorPageFinished)));
3005 return true;
3006}
3007
initial.commit09911bf2008-07-26 23:55:293008std::string RenderView::GetAltHTMLForTemplate(
3009 const DictionaryValue& error_strings, int template_resource_id) const {
3010 const StringPiece template_html(
3011 ResourceBundle::GetSharedInstance().GetRawDataResource(
3012 template_resource_id));
3013
3014 if (template_html.empty()) {
3015 NOTREACHED() << "unable to load template. ID: " << template_resource_id;
3016 return "";
3017 }
[email protected]7cd22a52009-07-14 00:40:253018
initial.commit09911bf2008-07-26 23:55:293019 // "t" is the id of the templates root node.
[email protected]7cd22a52009-07-14 00:40:253020 return jstemplate_builder::GetTemplatesHtml(
initial.commit09911bf2008-07-26 23:55:293021 template_html, &error_strings, "t");
3022}
[email protected]0e79b9e2009-02-13 04:20:483023
[email protected]15d79e12009-08-02 19:23:453024void RenderView::AltErrorPageFinished(WebFrame* frame,
3025 const WebURLError& original_error,
3026 const std::string& html) {
3027 // Here, we replace the blank page we loaded previously.
[email protected]7ccddb8c2009-08-04 17:36:553028
3029 // If we failed to download the alternate error page, fall back to the
3030 // original error page if present. Otherwise, LoadNavigationErrorPage
3031 // will simply display a default error page.
3032 const std::string* html_to_load = &html;
3033 if (html.empty()) {
3034 NavigationState* navigation_state =
[email protected]dd7daa82009-08-10 05:46:453035 NavigationState::FromDataSource(frame->dataSource());
[email protected]7ccddb8c2009-08-04 17:36:553036 html_to_load = &navigation_state->postponed_data();
3037 }
3038 LoadNavigationErrorPage(
3039 frame, WebURLRequest(), original_error, *html_to_load, true);
[email protected]15d79e12009-08-02 19:23:453040}
3041
[email protected]30f75e62009-02-25 22:01:003042void RenderView::OnMoveOrResizeStarted() {
3043 if (webview())
3044 webview()->HideAutofillPopup();
3045}
3046
[email protected]30f75e62009-02-25 22:01:003047void RenderView::OnResize(const gfx::Size& new_size,
3048 const gfx::Rect& resizer_rect) {
3049 if (webview())
3050 webview()->HideAutofillPopup();
3051 RenderWidget::OnResize(new_size, resizer_rect);
3052}
[email protected]0aa477bd2009-03-23 22:21:433053
[email protected]05d478752009-04-08 23:38:163054void RenderView::OnClearFocusedNode() {
3055 if (webview())
3056 webview()->ClearFocusedNode();
3057}
3058
[email protected]699ab0d2009-04-23 23:19:143059void RenderView::OnSetBackground(const SkBitmap& background) {
3060 if (webview())
3061 webview()->SetIsTransparent(!background.empty());
3062
3063 SetBackground(background);
3064}
3065
[email protected]8c66c5a2009-07-22 17:26:343066void RenderView::OnSetActive(bool active) {
3067 if (webview())
3068 webview()->SetActive(active);
3069}
3070
[email protected]309d7a282009-03-24 09:18:273071void RenderView::SendExtensionRequest(const std::string& name,
3072 const std::string& args,
[email protected]c6619182009-05-12 14:59:323073 int request_id,
[email protected]2f25d7b92009-06-10 00:06:473074 bool has_callback) {
[email protected]c6619182009-05-12 14:59:323075 Send(new ViewHostMsg_ExtensionRequest(routing_id_, name, args, request_id,
[email protected]2f25d7b92009-06-10 00:06:473076 has_callback));
[email protected]309d7a282009-03-24 09:18:273077}
3078
[email protected]c6619182009-05-12 14:59:323079void RenderView::OnExtensionResponse(int request_id,
3080 bool success,
3081 const std::string& response,
3082 const std::string& error) {
[email protected]0f6053962009-07-09 19:26:353083 ExtensionProcessBindings::HandleResponse(
3084 request_id, success, response, error);
[email protected]309d7a282009-03-24 09:18:273085}
[email protected]c20210e62009-04-03 21:39:263086
[email protected]7120f132009-07-20 21:05:373087void RenderView::OnExtensionMessageInvoke(const std::string& function_name,
3088 const ListValue& args) {
3089 RendererExtensionBindings::Invoke(function_name, args, this);
3090}
3091
[email protected]e7e4f3c2009-04-21 15:24:083092// Dump all load time histograms.
[email protected]c20210e62009-04-03 21:39:263093//
[email protected]7a9b51f2009-06-29 21:28:293094// There are 13 histograms measuring various times.
[email protected]c20210e62009-04-03 21:39:263095// The time points we keep are
3096// request: time document was requested by user
3097// start: time load of document started
[email protected]a2f6bc112009-06-27 16:27:253098// commit: time load of document started
[email protected]7a9b51f2009-06-29 21:28:293099// finish_document: main document loaded, before onload()
[email protected]c20210e62009-04-03 21:39:263100// finish: after onload() and all resources are loaded
[email protected]7a9b51f2009-06-29 21:28:293101// first_paint: first paint performed
3102// first_paint_after_load: first paint performed after load is finished
3103// begin: request if it was user requested, start otherwise
3104//
[email protected]c20210e62009-04-03 21:39:263105// The times that we histogram are
[email protected]a2f6bc112009-06-27 16:27:253106// request->start,
[email protected]7a9b51f2009-06-29 21:28:293107// start->commit,
3108// commit->finish_document,
3109// finish_document->finish,
3110// begin->commit,
3111// begin->finishDoc,
3112// begin->finish,
3113// begin->first_paint,
3114// begin->first_paint_after_load
3115// commit->finishDoc,
3116// commit->first_paint,
3117// commit->first_paint_after_load,
3118// finish->first_paint_after_load,
[email protected]c20210e62009-04-03 21:39:263119//
[email protected]e7e4f3c2009-04-21 15:24:083120// It's possible for the request time not to be set, if a client
3121// redirect had been done (the user never requested the page)
3122// Also, it's possible to load a page without ever laying it out
[email protected]7a9b51f2009-06-29 21:28:293123// so first_paint and first_paint_after_load can be 0.
[email protected]c20210e62009-04-03 21:39:263124void RenderView::DumpLoadHistograms() const {
3125 WebFrame* main_frame = webview()->GetMainFrame();
[email protected]ed3fb032009-06-16 19:50:563126 NavigationState* navigation_state =
[email protected]dd7daa82009-08-10 05:46:453127 NavigationState::FromDataSource(main_frame->dataSource());
[email protected]7a9b51f2009-06-29 21:28:293128 Time finish = navigation_state->finish_load_time();
[email protected]ed3fb032009-06-16 19:50:563129
[email protected]7a9b51f2009-06-29 21:28:293130 // If we've already dumped or we haven't finished loading, do nothing.
3131 if (navigation_state->load_histograms_recorded() || finish.is_null())
3132 return;
[email protected]ed3fb032009-06-16 19:50:563133
[email protected]7a9b51f2009-06-29 21:28:293134 Time request = navigation_state->request_time();
3135 Time start = navigation_state->start_load_time();
3136 Time commit = navigation_state->commit_load_time();
3137 Time finish_doc = navigation_state->finish_document_load_time();
3138 Time first_paint = navigation_state->first_paint_time();
3139 Time first_paint_after_load =
3140 navigation_state->first_paint_after_load_time();
[email protected]c20210e62009-04-03 21:39:263141
[email protected]7a9b51f2009-06-29 21:28:293142 Time begin;
3143 // Client side redirects will have no request time.
3144 if (request.is_null()) {
3145 begin = start;
3146 } else {
3147 begin = request;
3148 UMA_HISTOGRAM_MEDIUM_TIMES("Renderer4.RequestToStart", start - request);
[email protected]e7e4f3c2009-04-21 15:24:083149 }
[email protected]7a9b51f2009-06-29 21:28:293150 UMA_HISTOGRAM_MEDIUM_TIMES("Renderer4.StartToCommit", commit - start);
3151 UMA_HISTOGRAM_MEDIUM_TIMES(
3152 "Renderer4.CommitToFinishDoc", finish_doc - commit);
3153 UMA_HISTOGRAM_MEDIUM_TIMES(
3154 "Renderer4.FinishDocToFinish", finish - finish_doc);
3155
3156 UMA_HISTOGRAM_MEDIUM_TIMES("Renderer4.BeginToCommit", commit - begin);
3157 UMA_HISTOGRAM_MEDIUM_TIMES("Renderer4.BeginToFinishDoc", finish_doc - begin);
[email protected]e695fbd62009-06-30 16:31:543158
3159 static const TimeDelta kBeginToFinishMin(TimeDelta::FromMilliseconds(10));
3160 static const TimeDelta kBeginToFinishMax(TimeDelta::FromMinutes(10));
3161 static const size_t kBeginToFinishBucketCount(100);
3162
3163 UMA_HISTOGRAM_CUSTOM_TIMES("Renderer4.BeginToFinish",
3164 finish - begin, kBeginToFinishMin,
3165 kBeginToFinishMax, kBeginToFinishBucketCount);
[email protected]0a32257a2009-07-09 18:10:413166 UMA_HISTOGRAM_CUSTOM_TIMES("Renderer4.StartToFinish",
3167 finish - start, kBeginToFinishMin,
3168 kBeginToFinishMax, kBeginToFinishBucketCount);
3169 if (!request.is_null())
3170 UMA_HISTOGRAM_CUSTOM_TIMES("Renderer4.RequestToFinish",
3171 finish - request, kBeginToFinishMin,
3172 kBeginToFinishMax, kBeginToFinishBucketCount);
[email protected]e695fbd62009-06-30 16:31:543173
[email protected]36285b52009-06-30 19:10:003174 static bool use_dns_histogram(FieldTrialList::Find("DnsImpact") &&
3175 !FieldTrialList::Find("DnsImpact")->group_name().empty());
[email protected]0a32257a2009-07-09 18:10:413176 if (use_dns_histogram) {
[email protected]36285b52009-06-30 19:10:003177 UMA_HISTOGRAM_CUSTOM_TIMES(
3178 FieldTrial::MakeName("Renderer4.BeginToFinish", "DnsImpact").data(),
3179 finish - begin, kBeginToFinishMin,
3180 kBeginToFinishMax, kBeginToFinishBucketCount);
[email protected]0a32257a2009-07-09 18:10:413181 UMA_HISTOGRAM_CUSTOM_TIMES(
3182 FieldTrial::MakeName("Renderer4.StartToFinish", "DnsImpact").data(),
3183 finish - start, kBeginToFinishMin,
3184 kBeginToFinishMax, kBeginToFinishBucketCount);
3185 if (!request.is_null())
3186 UMA_HISTOGRAM_CUSTOM_TIMES(
3187 FieldTrial::MakeName("Renderer4.RequestToFinish", "DnsImpact").data(),
3188 finish - request, kBeginToFinishMin,
3189 kBeginToFinishMax, kBeginToFinishBucketCount);
3190 }
[email protected]e695fbd62009-06-30 16:31:543191
[email protected]36285b52009-06-30 19:10:003192 static bool use_sdch_histogram(FieldTrialList::Find("GlobalSdch") &&
3193 !FieldTrialList::Find("GlobalSdch")->group_name().empty());
[email protected]0a32257a2009-07-09 18:10:413194 if (use_sdch_histogram) {
[email protected]36285b52009-06-30 19:10:003195 UMA_HISTOGRAM_CUSTOM_TIMES(
3196 FieldTrial::MakeName("Renderer4.BeginToFinish", "GlobalSdch").data(),
3197 finish - begin, kBeginToFinishMin,
3198 kBeginToFinishMax, kBeginToFinishBucketCount);
[email protected]0a32257a2009-07-09 18:10:413199 UMA_HISTOGRAM_CUSTOM_TIMES(
3200 FieldTrial::MakeName("Renderer4.StartToFinish", "GlobalSdch").data(),
3201 finish - start, kBeginToFinishMin,
3202 kBeginToFinishMax, kBeginToFinishBucketCount);
3203 if (!request.is_null())
3204 UMA_HISTOGRAM_CUSTOM_TIMES(
3205 FieldTrial::MakeName("Renderer4.RequestToFinish",
3206 "GlobalSdch").data(),
3207 finish - request, kBeginToFinishMin,
3208 kBeginToFinishMax, kBeginToFinishBucketCount);
3209 }
[email protected]7a9b51f2009-06-29 21:28:293210
[email protected]5fff93f2009-08-02 04:27:343211 static bool use_socket_late_binding_histogram =
3212 FieldTrialList::Find("SocketLateBinding") &&
3213 !FieldTrialList::Find("SocketLateBinding")->group_name().empty();
3214 if (use_socket_late_binding_histogram) {
3215 UMA_HISTOGRAM_CUSTOM_TIMES(
3216 FieldTrial::MakeName("Renderer4.BeginToFinish",
3217 "SocketLateBinding").data(),
3218 finish - begin, kBeginToFinishMin,
3219 kBeginToFinishMax, kBeginToFinishBucketCount);
3220 UMA_HISTOGRAM_CUSTOM_TIMES(
3221 FieldTrial::MakeName("Renderer4.StartToFinish",
3222 "SocketLateBinding").data(),
3223 finish - start, kBeginToFinishMin,
3224 kBeginToFinishMax, kBeginToFinishBucketCount);
3225 if (!request.is_null())
3226 UMA_HISTOGRAM_CUSTOM_TIMES(
3227 FieldTrial::MakeName("Renderer4.RequestToFinish",
3228 "SocketLateBinding").data(),
3229 finish - request, kBeginToFinishMin,
3230 kBeginToFinishMax, kBeginToFinishBucketCount);
3231 }
3232
[email protected]7e05f6c42009-07-11 01:50:483233 static bool use_cache_histogram1(FieldTrialList::Find("CacheSize") &&
3234 !FieldTrialList::Find("CacheSize")->group_name().empty());
3235 if (use_cache_histogram1)
3236 UMA_HISTOGRAM_CUSTOM_TIMES(
3237 FieldTrial::MakeName("Renderer4.StartToFinish", "CacheSize").data(),
3238 finish - start, kBeginToFinishMin,
3239 kBeginToFinishMax, kBeginToFinishBucketCount);
3240
3241 static bool use_cache_histogram2(FieldTrialList::Find("NewEviction") &&
3242 !FieldTrialList::Find("NewEviction")->group_name().empty());
3243 if (use_cache_histogram2)
3244 UMA_HISTOGRAM_CUSTOM_TIMES(
3245 FieldTrial::MakeName("Renderer4.StartToFinish", "NewEviction").data(),
3246 finish - start, kBeginToFinishMin,
3247 kBeginToFinishMax, kBeginToFinishBucketCount);
3248
[email protected]7a9b51f2009-06-29 21:28:293249 UMA_HISTOGRAM_MEDIUM_TIMES("Renderer4.CommitToFinish", finish - commit);
3250
3251 if (!first_paint.is_null()) {
3252 UMA_HISTOGRAM_MEDIUM_TIMES(
3253 "Renderer4.BeginToFirstPaint", first_paint - begin);
3254 UMA_HISTOGRAM_MEDIUM_TIMES(
3255 "Renderer4.CommitToFirstPaint", first_paint - commit);
[email protected]c20210e62009-04-03 21:39:263256 }
[email protected]7a9b51f2009-06-29 21:28:293257
3258 if (!first_paint_after_load.is_null()) {
3259 UMA_HISTOGRAM_MEDIUM_TIMES(
3260 "Renderer4.BeginToFirstPaintAfterLoad", first_paint_after_load - begin);
3261 UMA_HISTOGRAM_MEDIUM_TIMES(
3262 "Renderer4.CommitToFirstPaintAfterLoad",
3263 first_paint_after_load - commit);
3264 UMA_HISTOGRAM_MEDIUM_TIMES(
3265 "Renderer4.FinishToFirstPaintAfterLoad",
3266 first_paint_after_load - finish);
3267 }
3268
3269 navigation_state->set_load_histograms_recorded(true);
[email protected]c20210e62009-04-03 21:39:263270}
[email protected]e846d0d2009-05-20 00:53:063271
3272void RenderView::FocusAccessibilityObject(
3273 WebCore::AccessibilityObject* acc_obj) {
3274#if defined(OS_WIN)
3275 if (!web_accessibility_manager_.get()) {
3276 web_accessibility_manager_.reset(
3277 webkit_glue::WebAccessibilityManager::Create());
3278 }
3279
3280 // Retrieve the accessibility object id of the AccessibilityObject.
3281 int acc_obj_id = web_accessibility_manager_->FocusAccObj(acc_obj);
3282
3283 // If id is valid, alert the browser side that an accessibility focus change
3284 // occurred.
3285 if (acc_obj_id >= 0)
3286 Send(new ViewHostMsg_AccessibilityFocusChange(routing_id_, acc_obj_id));
3287
3288#else // defined(OS_WIN)
3289 // TODO(port): accessibility not yet implemented
3290 NOTIMPLEMENTED();
3291#endif
3292}
[email protected]daa8c58e2009-06-15 17:21:103293
[email protected]4873c7d2009-07-16 06:36:283294void RenderView::DidMovePlugin(const WebPluginGeometry& move) {
3295 SchedulePluginMove(move);
3296}
3297
[email protected]268654772009-08-06 23:02:043298void RenderView::WillDestroyPluginWindow(gfx::PluginWindowHandle window) {
3299 CleanupWindowInPluginMoves(window);
3300}
3301
[email protected]daa8c58e2009-06-15 17:21:103302void RenderView::SendPasswordForms(WebFrame* frame) {
[email protected]dd7daa82009-08-10 05:46:453303 WebVector<WebForm> forms;
3304 frame->forms(forms);
[email protected]daa8c58e2009-06-15 17:21:103305
3306 std::vector<PasswordForm> password_forms;
3307 for (size_t i = 0; i < forms.size(); ++i) {
3308 const WebForm& form = forms[i];
3309
3310 // Respect autocomplete=off.
3311 if (form.isAutoCompleteEnabled()) {
3312 scoped_ptr<PasswordForm> password_form(
3313 PasswordFormDomManager::CreatePasswordForm(form));
3314 if (password_form.get())
3315 password_forms.push_back(*password_form);
3316 }
3317 }
3318
3319 if (!password_forms.empty())
3320 Send(new ViewHostMsg_PasswordFormsSeen(routing_id_, password_forms));
3321}
[email protected]0fda7272009-06-26 15:49:333322
3323void RenderView::Print(WebFrame* frame, bool script_initiated) {
3324 DCHECK(frame);
3325 if (print_helper_.get() == NULL) {
3326 print_helper_.reset(new PrintWebViewHelper(this));
3327 }
3328 print_helper_->Print(frame, script_initiated);
3329}