blob: ce9870fdfffd85bcb546fd3aa1cca7435f4fbbd7 [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"
initial.commit09911bf2008-07-26 23:55:2922#include "base/string_piece.h"
23#include "base/string_util.h"
[email protected]6c8afae52009-01-22 02:24:5724#include "build/build_config.h"
[email protected]81e63782009-02-27 19:35:0925#include "chrome/common/bindings_policy.h"
[email protected]ef916272009-07-08 21:40:5526#include "chrome/common/child_process_logging.h"
initial.commit09911bf2008-07-26 23:55:2927#include "chrome/common/chrome_switches.h"
[email protected]f0af6a72009-05-30 05:25:1728#include "chrome/common/chrome_constants.h"
initial.commit09911bf2008-07-26 23:55:2929#include "chrome/common/jstemplate_builder.h"
[email protected]630e26b2008-10-14 22:55:1730#include "chrome/common/page_zoom.h"
[email protected]e09ba552009-02-05 03:26:2931#include "chrome/common/render_messages.h"
[email protected]9b6f40e2009-06-11 15:54:2632#include "chrome/common/renderer_preferences.h"
initial.commit09911bf2008-07-26 23:55:2933#include "chrome/common/thumbnail_score.h"
[email protected]6de74452009-02-25 18:04:5934#include "chrome/common/url_constants.h"
initial.commit09911bf2008-07-26 23:55:2935#include "chrome/renderer/about_handler.h"
[email protected]5fb88962009-04-16 19:03:2536#include "chrome/renderer/audio_message_filter.h"
[email protected]e4ac5df2009-03-17 15:33:1137#include "chrome/renderer/devtools_agent.h"
38#include "chrome/renderer/devtools_client.h"
[email protected]f816c012009-06-26 21:48:3239#include "chrome/renderer/extensions/event_bindings.h"
[email protected]0f6053962009-07-09 19:26:3540#include "chrome/renderer/extensions/extension_process_bindings.h"
[email protected]7120f132009-07-20 21:05:3741#include "chrome/renderer/extensions/renderer_extension_bindings.h"
initial.commit09911bf2008-07-26 23:55:2942#include "chrome/renderer/localized_error.h"
[email protected]6f56d482009-02-20 05:02:5643#include "chrome/renderer/media/audio_renderer_impl.h"
[email protected]ed3fb032009-06-16 19:50:5644#include "chrome/renderer/navigation_state.h"
[email protected]d81c1e52009-06-03 22:09:5045#include "chrome/renderer/print_web_view_helper.h"
[email protected]39008c02009-02-11 23:59:2546#include "chrome/renderer/render_process.h"
[email protected]0938d3c2009-01-09 20:37:3547#include "chrome/renderer/user_script_slave.h"
initial.commit09911bf2008-07-26 23:55:2948#include "chrome/renderer/visitedlink_slave.h"
[email protected]ba4b17f2009-02-11 21:32:2949#include "chrome/renderer/webplugin_delegate_proxy.h"
[email protected]eb47a132009-03-04 00:39:5650#include "chrome/renderer/webworker_proxy.h"
[email protected]34ac8f32009-02-22 23:03:2751#include "grit/generated_resources.h"
52#include "grit/renderer_resources.h"
[email protected]f11ca0732009-04-11 00:09:3453#include "net/base/data_url.h"
initial.commit09911bf2008-07-26 23:55:2954#include "net/base/escape.h"
55#include "net/base/net_errors.h"
[email protected]c399a8a2008-11-22 19:38:0056#include "skia/ext/bitmap_platform_device.h"
[email protected]83c9e6552008-12-03 16:22:1057#include "skia/ext/image_operations.h"
[email protected]726985e22009-06-18 21:09:2858#include "webkit/api/public/WebDataSource.h"
[email protected]afdcf5c2009-05-10 20:30:4159#include "webkit/api/public/WebDragData.h"
[email protected]daa8c58e2009-06-15 17:21:1060#include "webkit/api/public/WebForm.h"
[email protected]dd7daa82009-08-10 05:46:4561#include "webkit/api/public/WebFrame.h"
[email protected]ca948a22009-06-25 19:36:1762#include "webkit/api/public/WebHistoryItem.h"
[email protected]581b87eb2009-07-23 23:06:5663#include "webkit/api/public/WebNode.h"
[email protected]afdcf5c2009-05-10 20:30:4164#include "webkit/api/public/WebPoint.h"
65#include "webkit/api/public/WebRect.h"
66#include "webkit/api/public/WebScriptSource.h"
67#include "webkit/api/public/WebSize.h"
[email protected]726985e22009-06-18 21:09:2868#include "webkit/api/public/WebURL.h"
69#include "webkit/api/public/WebURLError.h"
70#include "webkit/api/public/WebURLRequest.h"
71#include "webkit/api/public/WebURLResponse.h"
72#include "webkit/api/public/WebVector.h"
[email protected]ba4b17f2009-02-11 21:32:2973#include "webkit/default_plugin/default_plugin_shared.h"
[email protected]ca948a22009-06-25 19:36:1774#include "webkit/glue/glue_serialize.h"
initial.commit09911bf2008-07-26 23:55:2975#include "webkit/glue/dom_operations.h"
76#include "webkit/glue/dom_serializer.h"
[email protected]f11ca0732009-04-11 00:09:3477#include "webkit/glue/image_decoder.h"
[email protected]8e296bbd2009-07-22 21:37:1778#include "webkit/glue/media/buffered_data_source.h"
[email protected]8380c092009-06-25 17:45:5179#include "webkit/glue/media/simple_data_source.h"
initial.commit09911bf2008-07-26 23:55:2980#include "webkit/glue/password_form.h"
[email protected]ba4b17f2009-02-11 21:32:2981#include "webkit/glue/plugins/plugin_list.h"
initial.commit09911bf2008-07-26 23:55:2982#include "webkit/glue/searchable_form_data.h"
[email protected]6a983b42009-03-20 20:12:2583#include "webkit/glue/webaccessibilitymanager_impl.h"
[email protected]611cad42009-03-16 18:51:3484#include "webkit/glue/webdevtoolsagent_delegate.h"
initial.commit09911bf2008-07-26 23:55:2985#include "webkit/glue/webdropdata.h"
initial.commit09911bf2008-07-26 23:55:2986#include "webkit/glue/webkit_glue.h"
[email protected]add51772009-06-11 18:25:1787#include "webkit/glue/webmediaplayer_impl.h"
initial.commit09911bf2008-07-26 23:55:2988#include "webkit/glue/webpreferences.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]8649fb32009-06-26 17:51:02117using WebKit::WebSize;
[email protected]726985e22009-06-18 21:09:28118using WebKit::WebString;
[email protected]de570ef2009-07-29 18:27:52119using WebKit::WebTextDirection;
[email protected]726985e22009-06-18 21:09:28120using WebKit::WebURL;
121using WebKit::WebURLError;
122using WebKit::WebURLRequest;
123using WebKit::WebURLResponse;
[email protected]4873c7d2009-07-16 06:36:28124using WebKit::WebVector;
125using WebKit::WebWidget;
[email protected]27ba8532009-04-24 20:22:43126using WebKit::WebWorker;
127using WebKit::WebWorkerClient;
[email protected]e1acf6f2008-10-27 20:43:33128
initial.commit09911bf2008-07-26 23:55:29129//-----------------------------------------------------------------------------
130
131// define to write the time necessary for thumbnail/DOM text retrieval,
132// respectively, into the system debug log
133// #define TIME_BITMAP_RETRIEVAL
134// #define TIME_TEXT_RETRIEVAL
135
136// maximum number of characters in the document to index, any text beyond this
137// point will be clipped
[email protected]6c8afae52009-01-22 02:24:57138static const size_t kMaxIndexChars = 65535;
initial.commit09911bf2008-07-26 23:55:29139
140// Size of the thumbnails that we'll generate
141static const int kThumbnailWidth = 196;
142static const int kThumbnailHeight = 136;
143
144// Delay in milliseconds that we'll wait before capturing the page contents
145// and thumbnail.
146static const int kDelayForCaptureMs = 500;
147
148// Typically, we capture the page data once the page is loaded.
149// Sometimes, the page never finishes to load, preventing the page capture
150// To workaround this problem, we always perform a capture after the following
151// delay.
152static const int kDelayForForcedCaptureMs = 6000;
153
[email protected]81a34412009-01-05 19:17:24154// The default value for RenderView.delay_seconds_for_form_state_sync_, see
155// that variable for more.
156const int kDefaultDelaySecondsForFormStateSync = 5;
initial.commit09911bf2008-07-26 23:55:29157
158// The next available page ID to use. This ensures that the page IDs are
159// globally unique in the renderer.
160static int32 next_page_id_ = 1;
161
[email protected]0aa55312008-10-17 21:53:08162// The maximum number of popups that can be spawned from one page.
163static const int kMaximumNumberOfUnacknowledgedPopups = 25;
164
initial.commit09911bf2008-07-26 23:55:29165static const char* const kUnreachableWebDataURL =
[email protected]60e448982009-05-06 04:21:16166 "chrome://chromewebdata/";
initial.commit09911bf2008-07-26 23:55:29167
[email protected]50b691c2008-10-31 19:08:35168static const char* const kBackForwardNavigationScheme = "history";
169
[email protected]726985e22009-06-18 21:09:28170static void GetRedirectChain(WebDataSource* ds, std::vector<GURL>* result) {
171 WebVector<WebURL> urls;
172 ds->redirectChain(urls);
173 result->reserve(urls.size());
174 for (size_t i = 0; i < urls.size(); ++i)
175 result->push_back(urls[i]);
176}
177
initial.commit09911bf2008-07-26 23:55:29178///////////////////////////////////////////////////////////////////////////////
179
[email protected]81a34412009-01-05 19:17:24180RenderView::RenderView(RenderThreadBase* render_thread)
181 : RenderWidget(render_thread, true),
[email protected]81e63782009-02-27 19:35:09182 enabled_bindings_(0),
[email protected]e75cb49e2009-01-05 23:13:21183 target_url_status_(TARGET_NONE),
[email protected]81a34412009-01-05 19:17:24184 is_loading_(false),
[email protected]e75cb49e2009-01-05 23:13:21185 navigation_gesture_(NavigationGestureUnknown),
[email protected]81a34412009-01-05 19:17:24186 page_id_(-1),
187 last_page_id_sent_to_browser_(-1),
188 last_indexed_page_id_(-1),
[email protected]81a34412009-01-05 19:17:24189 opened_by_user_gesture_(true),
[email protected]bb063b72009-03-27 23:18:50190 ALLOW_THIS_IN_INITIALIZER_LIST(method_factory_(this)),
[email protected]81a34412009-01-05 19:17:24191 first_default_plugin_(NULL),
[email protected]e4ac5df2009-03-17 15:33:11192 devtools_agent_(NULL),
193 devtools_client_(NULL),
[email protected]81a34412009-01-05 19:17:24194 history_back_list_count_(0),
195 history_forward_list_count_(0),
[email protected]81a34412009-01-05 19:17:24196 has_unload_listener_(false),
197 decrement_shared_popup_at_destruction_(false),
[email protected]81a34412009-01-05 19:17:24198 form_field_autofill_request_id_(0),
199 popup_notification_visible_(false),
[email protected]0666aef2009-05-13 19:48:08200 delay_seconds_for_form_state_sync_(kDefaultDelaySecondsForFormStateSync),
201 preferred_width_(0),
[email protected]5c4266922009-07-10 16:41:27202 send_preferred_width_changes_(false),
[email protected]5f450e52009-07-28 13:28:11203 determine_page_text_after_loading_stops_(false),
204 last_top_level_navigation_page_id_(-1) {
initial.commit09911bf2008-07-26 23:55:29205}
206
207RenderView::~RenderView() {
[email protected]0aa55312008-10-17 21:53:08208 if (decrement_shared_popup_at_destruction_)
209 shared_popup_counter_->data--;
210
initial.commit09911bf2008-07-26 23:55:29211 // Clear any back-pointers that might still be held by plugins.
212 PluginDelegateList::iterator it = plugin_delegates_.begin();
213 while (it != plugin_delegates_.end()) {
214 (*it)->DropRenderView();
215 it = plugin_delegates_.erase(it);
216 }
217
[email protected]5fb88962009-04-16 19:03:25218 render_thread_->RemoveFilter(audio_message_filter_);
initial.commit09911bf2008-07-26 23:55:29219}
220
221/*static*/
[email protected]0aa55312008-10-17 21:53:08222RenderView* RenderView::Create(
[email protected]81a34412009-01-05 19:17:24223 RenderThreadBase* render_thread,
[email protected]18bcc3c2009-01-27 21:39:15224 gfx::NativeViewId parent_hwnd,
[email protected]1c4947f2009-01-15 22:25:11225 base::WaitableEvent* modal_dialog_event,
[email protected]0aa55312008-10-17 21:53:08226 int32 opener_id,
[email protected]80d96fa2009-06-10 22:34:51227 const RendererPreferences& renderer_prefs,
[email protected]0aa55312008-10-17 21:53:08228 const WebPreferences& webkit_prefs,
229 SharedRenderViewCounter* counter,
230 int32 routing_id) {
initial.commit09911bf2008-07-26 23:55:29231 DCHECK(routing_id != MSG_ROUTING_NONE);
[email protected]81a34412009-01-05 19:17:24232 scoped_refptr<RenderView> view = new RenderView(render_thread);
initial.commit09911bf2008-07-26 23:55:29233 view->Init(parent_hwnd,
234 modal_dialog_event,
235 opener_id,
[email protected]80d96fa2009-06-10 22:34:51236 renderer_prefs,
initial.commit09911bf2008-07-26 23:55:29237 webkit_prefs,
[email protected]0aa55312008-10-17 21:53:08238 counter,
initial.commit09911bf2008-07-26 23:55:29239 routing_id); // adds reference
240 return view;
241}
242
243/*static*/
244void RenderView::SetNextPageID(int32 next_page_id) {
245 // This method should only be called during process startup, and the given
246 // page id had better not exceed our current next page id!
[email protected]4646f292009-05-20 03:49:05247 DCHECK_EQ(next_page_id_, 1);
initial.commit09911bf2008-07-26 23:55:29248 DCHECK(next_page_id >= next_page_id_);
249 next_page_id_ = next_page_id;
250}
251
252void RenderView::PluginDestroyed(WebPluginDelegateProxy* proxy) {
253 PluginDelegateList::iterator it =
254 std::find(plugin_delegates_.begin(), plugin_delegates_.end(), proxy);
255 DCHECK(it != plugin_delegates_.end());
256 plugin_delegates_.erase(it);
257 // If the plugin is deleted, we need to clear our reference in case user
258 // clicks the info bar to install. Unfortunately we are getting
259 // PluginDestroyed in single process mode. However, that is not a huge
260 // concern.
261 if (proxy == first_default_plugin_)
262 first_default_plugin_ = NULL;
263}
264
[email protected]fb466342009-07-15 00:43:08265void RenderView::PluginCrashed(base::ProcessId pid,
266 const FilePath& plugin_path) {
267 Send(new ViewHostMsg_CrashedPlugin(routing_id_, pid, plugin_path));
initial.commit09911bf2008-07-26 23:55:29268}
269
270
271void RenderView::JSOutOfMemory() {
272 Send(new ViewHostMsg_JSOutOfMemory(routing_id_));
273}
274
[email protected]18bcc3c2009-01-27 21:39:15275void RenderView::Init(gfx::NativeViewId parent_hwnd,
[email protected]1c4947f2009-01-15 22:25:11276 base::WaitableEvent* modal_dialog_event,
initial.commit09911bf2008-07-26 23:55:29277 int32 opener_id,
[email protected]80d96fa2009-06-10 22:34:51278 const RendererPreferences& renderer_prefs,
initial.commit09911bf2008-07-26 23:55:29279 const WebPreferences& webkit_prefs,
[email protected]0aa55312008-10-17 21:53:08280 SharedRenderViewCounter* counter,
initial.commit09911bf2008-07-26 23:55:29281 int32 routing_id) {
282 DCHECK(!webview());
283
284 if (opener_id != MSG_ROUTING_NONE)
285 opener_id_ = opener_id;
286
[email protected]0aa55312008-10-17 21:53:08287 if (counter) {
288 shared_popup_counter_ = counter;
289 shared_popup_counter_->data++;
290 decrement_shared_popup_at_destruction_ = true;
291 } else {
292 shared_popup_counter_ = new SharedRenderViewCounter(0);
293 decrement_shared_popup_at_destruction_ = false;
294 }
295
[email protected]80d96fa2009-06-10 22:34:51296 OnSetRendererPrefs(renderer_prefs);
297
[email protected]58bfc6b2009-06-24 09:45:02298 devtools_agent_.reset(new DevToolsAgent(routing_id, this));
[email protected]9b9d7282009-04-08 14:13:04299
[email protected]c5b3b5e2009-02-13 06:41:11300 webwidget_ = WebView::Create(this, webkit_prefs);
initial.commit09911bf2008-07-26 23:55:29301
[email protected]2e417c82009-04-02 22:30:26302#if defined(OS_LINUX)
303 // We have to enable ourselves as the editor delegate on linux so we can copy
304 // text selections to the X clipboard.
305 webview()->SetUseEditorDelegate(true);
306#endif
307
initial.commit09911bf2008-07-26 23:55:29308 // Don't let WebCore keep a B/F list - we have our own.
309 // We let it keep 1 entry because FrameLoader::goToItem expects an item in the
310 // backForwardList, which is used only in ASSERTs.
311 webview()->SetBackForwardListSize(1);
312
313 routing_id_ = routing_id;
[email protected]81a34412009-01-05 19:17:24314 render_thread_->AddRoute(routing_id_, this);
initial.commit09911bf2008-07-26 23:55:29315 // Take a reference on behalf of the RenderThread. This will be balanced
316 // when we receive ViewMsg_Close.
317 AddRef();
318
319 // If this is a popup, we must wait for the CreatingNew_ACK message before
320 // completing initialization. Otherwise, we can finish it now.
321 if (opener_id == MSG_ROUTING_NONE) {
322 did_show_ = true;
323 CompleteInit(parent_hwnd);
324 }
325
326 host_window_ = parent_hwnd;
[email protected]1c4947f2009-01-15 22:25:11327 modal_dialog_event_.reset(modal_dialog_event);
initial.commit09911bf2008-07-26 23:55:29328
[email protected]58bfc6b2009-06-24 09:45:02329 const CommandLine& command_line = *CommandLine::ForCurrentProcess();
[email protected]81e63782009-02-27 19:35:09330 if (command_line.HasSwitch(switches::kDomAutomationController))
331 enabled_bindings_ |= BindingsPolicy::DOM_AUTOMATION;
initial.commit09911bf2008-07-26 23:55:29332
[email protected]5fb88962009-04-16 19:03:25333 audio_message_filter_ = new AudioMessageFilter(routing_id_);
334 render_thread_->AddFilter(audio_message_filter_);
initial.commit09911bf2008-07-26 23:55:29335}
336
337void RenderView::OnMessageReceived(const IPC::Message& message) {
[email protected]f8b6b6f2009-03-10 16:48:26338 WebFrame* main_frame = webview() ? webview()->GetMainFrame() : NULL;
[email protected]ef916272009-07-08 21:40:55339 child_process_logging::ScopedActiveURLSetter url_setter(
[email protected]dd7daa82009-08-10 05:46:45340 main_frame ? main_frame->url() : WebURL());
[email protected]f8b6b6f2009-03-10 16:48:26341
[email protected]b2abac72009-02-26 12:39:28342 // If this is developer tools renderer intercept tools messages first.
[email protected]e4ac5df2009-03-17 15:33:11343 if (devtools_client_.get() && devtools_client_->OnMessageReceived(message))
[email protected]b2abac72009-02-26 12:39:28344 return;
[email protected]b4b967e2009-04-22 11:33:05345 if (devtools_agent_.get() && devtools_agent_->OnMessageReceived(message))
346 return;
[email protected]b2abac72009-02-26 12:39:28347
initial.commit09911bf2008-07-26 23:55:29348 IPC_BEGIN_MESSAGE_MAP(RenderView, message)
initial.commit09911bf2008-07-26 23:55:29349 IPC_MESSAGE_HANDLER(ViewMsg_CaptureThumbnail, SendThumbnail)
initial.commit09911bf2008-07-26 23:55:29350 IPC_MESSAGE_HANDLER(ViewMsg_PrintPages, OnPrintPages)
[email protected]82270452009-06-19 15:58:01351 IPC_MESSAGE_HANDLER(ViewMsg_PrintingDone, OnPrintingDone)
initial.commit09911bf2008-07-26 23:55:29352 IPC_MESSAGE_HANDLER(ViewMsg_Navigate, OnNavigate)
353 IPC_MESSAGE_HANDLER(ViewMsg_Stop, OnStop)
354 IPC_MESSAGE_HANDLER(ViewMsg_LoadAlternateHTMLText, OnLoadAlternateHTMLText)
355 IPC_MESSAGE_HANDLER(ViewMsg_StopFinding, OnStopFinding)
356 IPC_MESSAGE_HANDLER(ViewMsg_Undo, OnUndo)
357 IPC_MESSAGE_HANDLER(ViewMsg_Redo, OnRedo)
358 IPC_MESSAGE_HANDLER(ViewMsg_Cut, OnCut)
359 IPC_MESSAGE_HANDLER(ViewMsg_Copy, OnCopy)
360 IPC_MESSAGE_HANDLER(ViewMsg_Paste, OnPaste)
361 IPC_MESSAGE_HANDLER(ViewMsg_Replace, OnReplace)
[email protected]bbbd545c2008-12-15 20:18:04362 IPC_MESSAGE_HANDLER(ViewMsg_ToggleSpellCheck, OnToggleSpellCheck)
initial.commit09911bf2008-07-26 23:55:29363 IPC_MESSAGE_HANDLER(ViewMsg_Delete, OnDelete)
364 IPC_MESSAGE_HANDLER(ViewMsg_SelectAll, OnSelectAll)
365 IPC_MESSAGE_HANDLER(ViewMsg_CopyImageAt, OnCopyImageAt)
[email protected]4b59ae602009-06-23 20:58:15366 IPC_MESSAGE_HANDLER(ViewMsg_ExecuteEditCommand, OnExecuteEditCommand)
initial.commit09911bf2008-07-26 23:55:29367 IPC_MESSAGE_HANDLER(ViewMsg_Find, OnFind)
[email protected]5c4266922009-07-10 16:41:27368 IPC_MESSAGE_HANDLER(ViewMsg_DeterminePageText, OnDeterminePageText)
[email protected]630e26b2008-10-14 22:55:17369 IPC_MESSAGE_HANDLER(ViewMsg_Zoom, OnZoom)
[email protected]ea8c7452009-04-02 20:47:06370 IPC_MESSAGE_HANDLER(ViewMsg_InsertText, OnInsertText)
initial.commit09911bf2008-07-26 23:55:29371 IPC_MESSAGE_HANDLER(ViewMsg_SetPageEncoding, OnSetPageEncoding)
[email protected]b2abac72009-02-26 12:39:28372 IPC_MESSAGE_HANDLER(ViewMsg_SetupDevToolsClient, OnSetupDevToolsClient)
[email protected]bf5c2ff392009-07-08 16:24:33373 IPC_MESSAGE_HANDLER(ViewMsg_DownloadFavIcon, OnDownloadFavIcon)
initial.commit09911bf2008-07-26 23:55:29374 IPC_MESSAGE_HANDLER(ViewMsg_ScriptEvalRequest, OnScriptEvalRequest)
[email protected]1810e132009-03-24 23:35:48375 IPC_MESSAGE_HANDLER(ViewMsg_CSSInsertRequest, OnCSSInsertRequest)
initial.commit09911bf2008-07-26 23:55:29376 IPC_MESSAGE_HANDLER(ViewMsg_AddMessageToConsole, OnAddMessageToConsole)
initial.commit09911bf2008-07-26 23:55:29377 IPC_MESSAGE_HANDLER(ViewMsg_ReservePageIDRange, OnReservePageIDRange)
378 IPC_MESSAGE_HANDLER(ViewMsg_UploadFile, OnUploadFileRequest)
379 IPC_MESSAGE_HANDLER(ViewMsg_FormFill, OnFormFill)
380 IPC_MESSAGE_HANDLER(ViewMsg_FillPasswordForm, OnFillPasswordForm)
381 IPC_MESSAGE_HANDLER(ViewMsg_DragTargetDragEnter, OnDragTargetDragEnter)
382 IPC_MESSAGE_HANDLER(ViewMsg_DragTargetDragOver, OnDragTargetDragOver)
383 IPC_MESSAGE_HANDLER(ViewMsg_DragTargetDragLeave, OnDragTargetDragLeave)
384 IPC_MESSAGE_HANDLER(ViewMsg_DragTargetDrop, OnDragTargetDrop)
[email protected]18cb2572008-08-21 20:34:45385 IPC_MESSAGE_HANDLER(ViewMsg_AllowBindings, OnAllowBindings)
initial.commit09911bf2008-07-26 23:55:29386 IPC_MESSAGE_HANDLER(ViewMsg_SetDOMUIProperty, OnSetDOMUIProperty)
[email protected]266eb6f2008-09-30 23:56:50387 IPC_MESSAGE_HANDLER(ViewMsg_DragSourceEndedOrMoved,
388 OnDragSourceEndedOrMoved)
initial.commit09911bf2008-07-26 23:55:29389 IPC_MESSAGE_HANDLER(ViewMsg_DragSourceSystemDragEnded,
390 OnDragSourceSystemDragEnded)
391 IPC_MESSAGE_HANDLER(ViewMsg_SetInitialFocus, OnSetInitialFocus)
392 IPC_MESSAGE_HANDLER(ViewMsg_FindReplyACK, OnFindReplyAck)
393 IPC_MESSAGE_HANDLER(ViewMsg_UpdateTargetURL_ACK, OnUpdateTargetURLAck)
394 IPC_MESSAGE_HANDLER(ViewMsg_UpdateWebPreferences, OnUpdateWebPreferences)
395 IPC_MESSAGE_HANDLER(ViewMsg_SetAltErrorPageURL, OnSetAltErrorPageURL)
396 IPC_MESSAGE_HANDLER(ViewMsg_InstallMissingPlugin, OnInstallMissingPlugin)
397 IPC_MESSAGE_HANDLER(ViewMsg_RunFileChooserResponse, OnFileChooserResponse)
398 IPC_MESSAGE_HANDLER(ViewMsg_EnableViewSourceMode, OnEnableViewSourceMode)
399 IPC_MESSAGE_HANDLER(ViewMsg_UpdateBackForwardListCount,
400 OnUpdateBackForwardListCount)
401 IPC_MESSAGE_HANDLER(ViewMsg_GetAllSavableResourceLinksForCurrentPage,
402 OnGetAllSavableResourceLinksForCurrentPage)
[email protected]f09c7182009-03-10 12:54:04403 IPC_MESSAGE_HANDLER(
404 ViewMsg_GetSerializedHtmlDataForCurrentPageWithLocalLinks,
405 OnGetSerializedHtmlDataForCurrentPageWithLocalLinks)
initial.commit09911bf2008-07-26 23:55:29406 IPC_MESSAGE_HANDLER(ViewMsg_GetApplicationInfo, OnGetApplicationInfo)
[email protected]266eb6f2008-09-30 23:56:50407 IPC_MESSAGE_HANDLER(ViewMsg_GetAccessibilityInfo, OnGetAccessibilityInfo)
408 IPC_MESSAGE_HANDLER(ViewMsg_ClearAccessibilityInfo,
409 OnClearAccessibilityInfo)
initial.commit09911bf2008-07-26 23:55:29410 IPC_MESSAGE_HANDLER(ViewMsg_ShouldClose, OnMsgShouldClose)
411 IPC_MESSAGE_HANDLER(ViewMsg_ClosePage, OnClosePage)
412 IPC_MESSAGE_HANDLER(ViewMsg_ThemeChanged, OnThemeChanged)
[email protected]18cb2572008-08-21 20:34:45413 IPC_MESSAGE_HANDLER(ViewMsg_HandleMessageFromExternalHost,
414 OnMessageFromExternalHost)
[email protected]0aa55312008-10-17 21:53:08415 IPC_MESSAGE_HANDLER(ViewMsg_DisassociateFromPopupCount,
416 OnDisassociateFromPopupCount)
[email protected]0ebf3872008-11-07 21:35:03417 IPC_MESSAGE_HANDLER(ViewMsg_AutofillSuggestions,
418 OnReceivedAutofillSuggestions)
[email protected]2c4410d2009-05-06 23:46:22419 IPC_MESSAGE_HANDLER(ViewMsg_PopupNotificationVisibilityChanged,
420 OnPopupNotificationVisibilityChanged)
[email protected]30f75e62009-02-25 22:01:00421 IPC_MESSAGE_HANDLER(ViewMsg_MoveOrResizeStarted, OnMoveOrResizeStarted)
[email protected]309d7a282009-03-24 09:18:27422 IPC_MESSAGE_HANDLER(ViewMsg_ExtensionResponse, OnExtensionResponse)
[email protected]7120f132009-07-20 21:05:37423 IPC_MESSAGE_HANDLER(ViewMsg_ExtensionMessageInvoke,
424 OnExtensionMessageInvoke)
[email protected]05d478752009-04-08 23:38:16425 IPC_MESSAGE_HANDLER(ViewMsg_ClearFocusedNode, OnClearFocusedNode)
[email protected]699ab0d2009-04-23 23:19:14426 IPC_MESSAGE_HANDLER(ViewMsg_SetBackground, OnSetBackground)
[email protected]0666aef2009-05-13 19:48:08427 IPC_MESSAGE_HANDLER(ViewMsg_EnableIntrinsicWidthChangedMode,
428 OnEnableIntrinsicWidthChangedMode)
[email protected]80d96fa2009-06-10 22:34:51429 IPC_MESSAGE_HANDLER(ViewMsg_SetRendererPrefs, OnSetRendererPrefs)
[email protected]581b87eb2009-07-23 23:06:56430 IPC_MESSAGE_HANDLER(ViewMsg_MediaPlayerActionAt, OnMediaPlayerActionAt)
[email protected]8c66c5a2009-07-22 17:26:34431 IPC_MESSAGE_HANDLER(ViewMsg_SetActive, OnSetActive)
[email protected]634a6f92008-12-01 21:39:31432
initial.commit09911bf2008-07-26 23:55:29433 // Have the super handle all other messages.
434 IPC_MESSAGE_UNHANDLED(RenderWidget::OnMessageReceived(message))
435 IPC_END_MESSAGE_MAP()
436}
437
initial.commit09911bf2008-07-26 23:55:29438void RenderView::SendThumbnail() {
439 WebFrame* main_frame = webview()->GetMainFrame();
440 if (!main_frame)
441 return;
442
443 // get the URL for this page
[email protected]dd7daa82009-08-10 05:46:45444 GURL url(main_frame->url());
initial.commit09911bf2008-07-26 23:55:29445 if (url.is_empty())
446 return;
447
448 if (size_.IsEmpty())
449 return; // Don't create an empty thumbnail!
450
451 ThumbnailScore score;
452 SkBitmap thumbnail;
[email protected]8649fb32009-06-26 17:51:02453 if (!CaptureThumbnail(webview(), kThumbnailWidth, kThumbnailHeight,
[email protected]b6e4bec2008-11-12 01:17:15454 &thumbnail, &score))
455 return;
456
initial.commit09911bf2008-07-26 23:55:29457 // send the thumbnail message to the browser process
[email protected]674741932009-02-04 23:44:46458 Send(new ViewHostMsg_Thumbnail(routing_id_, url, score, thumbnail));
initial.commit09911bf2008-07-26 23:55:29459}
460
[email protected]068637222009-01-29 16:58:07461void RenderView::OnPrintPages() {
initial.commit09911bf2008-07-26 23:55:29462 DCHECK(webview());
[email protected]aa82249f2009-07-16 17:23:58463 if (webview()) {
464 // If the user has selected text in the currently focused frame we print
465 // only that frame (this makes print selection work for multiple frames).
[email protected]dd7daa82009-08-10 05:46:45466 if (webview()->GetFocusedFrame()->hasSelection())
[email protected]aa82249f2009-07-16 17:23:58467 Print(webview()->GetFocusedFrame(), false);
468 else
469 Print(webview()->GetMainFrame(), false);
470 }
initial.commit09911bf2008-07-26 23:55:29471}
472
[email protected]82270452009-06-19 15:58:01473void RenderView::OnPrintingDone(int document_cookie, bool success) {
474 // Ignoring document cookie here since only one print job can be outstanding
475 // per renderer and document_cookie is 0 when printing is successful.
476 DCHECK(print_helper_.get());
477 if (print_helper_.get() != NULL) {
478 print_helper_->DidFinishPrinting(success);
479 }
480}
481
initial.commit09911bf2008-07-26 23:55:29482void RenderView::CapturePageInfo(int load_id, bool preliminary_capture) {
483 if (load_id != page_id_)
484 return; // this capture call is no longer relevant due to navigation
485 if (load_id == last_indexed_page_id_)
486 return; // we already indexed this page
487
488 if (!webview())
489 return;
490
491 WebFrame* main_frame = webview()->GetMainFrame();
492 if (!main_frame)
493 return;
494
495 // Don't index/capture pages that are in view source mode.
[email protected]dd7daa82009-08-10 05:46:45496 if (main_frame->isViewSourceModeEnabled())
initial.commit09911bf2008-07-26 23:55:29497 return;
498
499 // Don't index/capture pages that failed to load. This only checks the top
500 // level frame so the thumbnail may contain a frame that failed to load.
[email protected]dd7daa82009-08-10 05:46:45501 WebDataSource* ds = main_frame->dataSource();
[email protected]726985e22009-06-18 21:09:28502 if (ds && ds->hasUnreachableURL())
initial.commit09911bf2008-07-26 23:55:29503 return;
504
505 if (!preliminary_capture)
506 last_indexed_page_id_ = load_id;
507
508 // get the URL for this page
[email protected]dd7daa82009-08-10 05:46:45509 GURL url(main_frame->url());
initial.commit09911bf2008-07-26 23:55:29510 if (url.is_empty())
511 return;
512
513 // full text
514 std::wstring contents;
515 CaptureText(main_frame, &contents);
516 if (contents.size()) {
517 // Send the text to the browser for indexing.
518 Send(new ViewHostMsg_PageContents(url, load_id, contents));
519 }
520
[email protected]5c4266922009-07-10 16:41:27521 // Send over text content of this page to the browser.
522 if (determine_page_text_after_loading_stops_) {
523 determine_page_text_after_loading_stops_ = false;
524 Send(new ViewMsg_DeterminePageText_Reply(routing_id_, contents));
525 }
526
initial.commit09911bf2008-07-26 23:55:29527 // thumbnail
528 SendThumbnail();
529}
530
531void RenderView::CaptureText(WebFrame* frame, std::wstring* contents) {
532 contents->clear();
533 if (!frame)
534 return;
535
[email protected]0faf0bd92008-09-09 20:53:27536 // Don't index any https pages. People generally don't want their bank
537 // accounts, etc. indexed on their computer, especially since some of these
538 // things are not marked cachable.
539 // TODO(brettw) we may want to consider more elaborate heuristics such as
540 // the cachability of the page. We may also want to consider subframes (this
541 // test will still index subframes if the subframe is SSL).
[email protected]dd7daa82009-08-10 05:46:45542 if (GURL(frame->url()).SchemeIsSecure())
[email protected]0faf0bd92008-09-09 20:53:27543 return;
544
initial.commit09911bf2008-07-26 23:55:29545#ifdef TIME_TEXT_RETRIEVAL
546 double begin = time_util::GetHighResolutionTimeNow();
547#endif
548
549 // get the contents of the frame
[email protected]dd7daa82009-08-10 05:46:45550 *contents = UTF16ToWideHack(frame->contentAsText(kMaxIndexChars));
initial.commit09911bf2008-07-26 23:55:29551
552#ifdef TIME_TEXT_RETRIEVAL
553 double end = time_util::GetHighResolutionTimeNow();
554 char buf[128];
555 sprintf_s(buf, "%d chars retrieved for indexing in %gms\n",
556 contents.size(), (end - begin)*1000);
557 OutputDebugStringA(buf);
558#endif
559
560 // When the contents are clipped to the maximum, we don't want to have a
561 // partial word indexed at the end that might have been clipped. Therefore,
562 // terminate the string at the last space to ensure no words are clipped.
563 if (contents->size() == kMaxIndexChars) {
564 size_t last_space_index = contents->find_last_of(kWhitespaceWide);
565 if (last_space_index == std::wstring::npos)
566 return; // don't index if we got a huge block of text with no spaces
567 contents->resize(last_space_index);
568 }
569}
570
[email protected]8649fb32009-06-26 17:51:02571bool RenderView::CaptureThumbnail(WebView* view,
initial.commit09911bf2008-07-26 23:55:29572 int w,
573 int h,
574 SkBitmap* thumbnail,
575 ThumbnailScore* score) {
576#ifdef TIME_BITMAP_RETRIEVAL
577 double begin = time_util::GetHighResolutionTimeNow();
578#endif
579
[email protected]4873c7d2009-07-16 06:36:28580 view->layout();
581 const WebSize& size = view->size();
[email protected]b6e4bec2008-11-12 01:17:15582
[email protected]8649fb32009-06-26 17:51:02583 skia::PlatformCanvas canvas;
584 if (!canvas.initialize(size.width, size.height, true))
585 return false;
[email protected]4873c7d2009-07-16 06:36:28586 view->paint(&canvas, WebRect(0, 0, size.width, size.height));
[email protected]8649fb32009-06-26 17:51:02587
588 skia::BitmapPlatformDevice& device =
589 static_cast<skia::BitmapPlatformDevice&>(canvas.getTopPlatformDevice());
590
591 const SkBitmap& src_bmp = device.accessBitmap(false);
initial.commit09911bf2008-07-26 23:55:29592
593 SkRect dest_rect;
594 dest_rect.set(0, 0, SkIntToScalar(w), SkIntToScalar(h));
595 float dest_aspect = dest_rect.width() / dest_rect.height();
596
597 // Get the src rect so that we can preserve the aspect ratio while filling
598 // the destination.
599 SkIRect src_rect;
600 if (src_bmp.width() < dest_rect.width() ||
601 src_bmp.height() < dest_rect.height()) {
602 // Source image is smaller: we clip the part of source image within the
603 // dest rect, and then stretch it to fill the dest rect. We don't respect
604 // the aspect ratio in this case.
605 src_rect.set(0, 0, static_cast<S16CPU>(dest_rect.width()),
606 static_cast<S16CPU>(dest_rect.height()));
607 score->good_clipping = false;
608 } else {
609 float src_aspect = static_cast<float>(src_bmp.width()) / src_bmp.height();
610 if (src_aspect > dest_aspect) {
611 // Wider than tall, clip horizontally: we center the smaller thumbnail in
612 // the wider screen.
613 S16CPU new_width = static_cast<S16CPU>(src_bmp.height() * dest_aspect);
614 S16CPU x_offset = (src_bmp.width() - new_width) / 2;
615 src_rect.set(x_offset, 0, new_width + x_offset, src_bmp.height());
616 score->good_clipping = false;
617 } else {
618 src_rect.set(0, 0, src_bmp.width(),
619 static_cast<S16CPU>(src_bmp.width() / dest_aspect));
620 score->good_clipping = true;
621 }
622 }
623
[email protected]dd7daa82009-08-10 05:46:45624 score->at_top = (view->GetMainFrame()->scrollOffset().height == 0);
initial.commit09911bf2008-07-26 23:55:29625
626 SkBitmap subset;
[email protected]8649fb32009-06-26 17:51:02627 device.accessBitmap(false).extractSubset(&subset, src_rect);
initial.commit09911bf2008-07-26 23:55:29628
629 // Resample the subset that we want to get it the right size.
[email protected]465b34b72008-12-12 20:19:14630 *thumbnail = skia::ImageOperations::Resize(
631 subset, skia::ImageOperations::RESIZE_LANCZOS3, w, h);
initial.commit09911bf2008-07-26 23:55:29632
633 score->boring_score = CalculateBoringScore(thumbnail);
634
635#ifdef TIME_BITMAP_RETRIEVAL
636 double end = time_util::GetHighResolutionTimeNow();
637 char buf[128];
638 sprintf_s(buf, "thumbnail in %gms\n", (end - begin) * 1000);
639 OutputDebugStringA(buf);
640#endif
[email protected]b6e4bec2008-11-12 01:17:15641 return true;
initial.commit09911bf2008-07-26 23:55:29642}
643
644double RenderView::CalculateBoringScore(SkBitmap* bitmap) {
645 int histogram[256] = {0};
646 color_utils::BuildLumaHistogram(bitmap, histogram);
647
648 int color_count = *std::max_element(histogram, histogram + 256);
649 int pixel_count = bitmap->width() * bitmap->height();
650 return static_cast<double>(color_count) / pixel_count;
651}
652
653void RenderView::OnNavigate(const ViewMsg_Navigate_Params& params) {
654 if (!webview())
655 return;
656
[email protected]8c785c62009-07-13 14:20:15657 if (devtools_agent_.get())
658 devtools_agent_->OnNavigate();
659
[email protected]ef916272009-07-08 21:40:55660 child_process_logging::ScopedActiveURLSetter url_setter(params.url);
[email protected]f8b6b6f2009-03-10 16:48:26661
initial.commit09911bf2008-07-26 23:55:29662 AboutHandler::MaybeHandle(params.url);
663
664 bool is_reload = params.reload;
665
666 WebFrame* main_frame = webview()->GetMainFrame();
[email protected]dd7daa82009-08-10 05:46:45667 if (is_reload && main_frame->currentHistoryItem().isNull()) {
initial.commit09911bf2008-07-26 23:55:29668 // We cannot reload if we do not have any history state. This happens, for
669 // example, when recovering from a crash. Our workaround here is a bit of
670 // a hack since it means that reload after a crashed tab does not cause an
671 // end-to-end cache validation.
672 is_reload = false;
673 }
674
[email protected]77f17a82009-05-21 04:42:54675 // A navigation resulting from loading a javascript URL should not be treated
676 // as a browser initiated event. Instead, we want it to look as if the page
677 // initiated any load resulting from JS execution.
678 if (!params.url.SchemeIs(chrome::kJavaScriptScheme)) {
[email protected]daa8c58e2009-06-15 17:21:10679 pending_navigation_state_.reset(NavigationState::CreateBrowserInitiated(
[email protected]77f17a82009-05-21 04:42:54680 params.page_id, params.transition, params.request_time));
681 }
initial.commit09911bf2008-07-26 23:55:29682
[email protected]04d3c6e2009-05-22 17:00:13683 // If we are reloading, then WebKit will use the history state of the current
684 // page, so we should just ignore any given history state. Otherwise, if we
685 // have history state, then we need to navigate to it, which corresponds to a
686 // back/forward navigation event.
[email protected]e6f546c32009-07-01 17:12:55687 if (is_reload) {
[email protected]dd7daa82009-08-10 05:46:45688 main_frame->reload();
[email protected]e6f546c32009-07-01 17:12:55689 } else if (!params.state.empty()) {
[email protected]04d3c6e2009-05-22 17:00:13690 // We must know the page ID of the page we are navigating back to.
[email protected]f929f2f22009-06-12 16:56:58691 DCHECK_NE(params.page_id, -1);
[email protected]dd7daa82009-08-10 05:46:45692 main_frame->loadHistoryItem(
[email protected]ca948a22009-06-25 19:36:17693 webkit_glue::HistoryItemFromString(params.state));
[email protected]04d3c6e2009-05-22 17:00:13694 } else {
695 // Navigate to the given URL.
[email protected]726985e22009-06-18 21:09:28696 WebURLRequest request(params.url);
initial.commit09911bf2008-07-26 23:55:29697
[email protected]e6f546c32009-07-01 17:12:55698 // A session history navigation should have been accompanied by state.
699 DCHECK_EQ(params.page_id, -1);
[email protected]04d3c6e2009-05-22 17:00:13700
[email protected]dd7daa82009-08-10 05:46:45701 if (main_frame->isViewSourceModeEnabled())
[email protected]e6f546c32009-07-01 17:12:55702 request.setCachePolicy(WebURLRequest::ReturnCacheDataElseLoad);
[email protected]04d3c6e2009-05-22 17:00:13703
[email protected]726985e22009-06-18 21:09:28704 if (params.referrer.is_valid()) {
705 request.setHTTPHeaderField(WebString::fromUTF8("Referer"),
706 WebString::fromUTF8(params.referrer.spec()));
707 }
[email protected]04d3c6e2009-05-22 17:00:13708
[email protected]dd7daa82009-08-10 05:46:45709 main_frame->loadRequest(request);
[email protected]c0588052008-10-27 23:01:50710 }
711
[email protected]77f17a82009-05-21 04:42:54712 // In case LoadRequest failed before DidCreateDataSource was called.
713 pending_navigation_state_.reset();
initial.commit09911bf2008-07-26 23:55:29714}
715
716// Stop loading the current page
717void RenderView::OnStop() {
718 if (webview())
719 webview()->StopLoading();
720}
721
[email protected]e6f546c32009-07-01 17:12:55722void RenderView::OnLoadAlternateHTMLText(const std::string& html,
initial.commit09911bf2008-07-26 23:55:29723 bool new_navigation,
724 const GURL& display_url,
725 const std::string& security_info) {
726 if (!webview())
727 return;
728
[email protected]e6f546c32009-07-01 17:12:55729 pending_navigation_state_.reset(NavigationState::CreateBrowserInitiated(
730 new_navigation ? -1 : page_id_, PageTransition::LINK, Time::Now()));
731 pending_navigation_state_->set_security_info(security_info);
initial.commit09911bf2008-07-26 23:55:29732
[email protected]dd7daa82009-08-10 05:46:45733 webview()->GetMainFrame()->loadHTMLString(html,
[email protected]e6f546c32009-07-01 17:12:55734 GURL(kUnreachableWebDataURL),
735 display_url,
736 !new_navigation);
737
738 pending_navigation_state_.reset();
initial.commit09911bf2008-07-26 23:55:29739}
740
741void RenderView::OnCopyImageAt(int x, int y) {
742 webview()->CopyImageAt(x, y);
743}
744
[email protected]68b1e922009-06-23 16:00:25745void RenderView::OnExecuteEditCommand(const std::string& name,
746 const std::string& value) {
747 if (!webview() || !webview()->GetFocusedFrame())
748 return;
749
[email protected]dd7daa82009-08-10 05:46:45750 webview()->GetFocusedFrame()->executeCommand(
751 WebString::fromUTF8(name), WebString::fromUTF8(value));
[email protected]68b1e922009-06-23 16:00:25752}
753
[email protected]b2abac72009-02-26 12:39:28754void RenderView::OnSetupDevToolsClient() {
[email protected]e4ac5df2009-03-17 15:33:11755 DCHECK(!devtools_client_.get());
756 devtools_client_.reset(new DevToolsClient(this));
[email protected]b2abac72009-02-26 12:39:28757}
758
initial.commit09911bf2008-07-26 23:55:29759void RenderView::OnStopFinding(bool clear_selection) {
760 WebView* view = webview();
761 if (!view)
762 return;
763
764 if (clear_selection)
[email protected]dd7daa82009-08-10 05:46:45765 view->GetFocusedFrame()->clearSelection();
initial.commit09911bf2008-07-26 23:55:29766
767 WebFrame* frame = view->GetMainFrame();
768 while (frame) {
[email protected]dd7daa82009-08-10 05:46:45769 frame->stopFinding(clear_selection);
initial.commit09911bf2008-07-26 23:55:29770 frame = view->GetNextFrameAfter(frame, false);
771 }
772}
773
774void RenderView::OnFindReplyAck() {
775 // Check if there is any queued up request waiting to be sent.
776 if (queued_find_reply_message_.get()) {
777 // Send the search result over to the browser process.
778 Send(queued_find_reply_message_.get());
779 queued_find_reply_message_.release();
780 }
781}
782
783void RenderView::OnUpdateTargetURLAck() {
784 // Check if there is a targeturl waiting to be sent.
785 if (target_url_status_ == TARGET_PENDING) {
786 Send(new ViewHostMsg_UpdateTargetURL(routing_id_, page_id_,
787 pending_target_url_));
788 }
789
790 target_url_status_ = TARGET_NONE;
791}
792
793void RenderView::OnUndo() {
794 if (!webview())
795 return;
796
[email protected]dd7daa82009-08-10 05:46:45797 webview()->GetFocusedFrame()->executeCommand(WebString::fromUTF8("Undo"));
798 UserMetricsRecordAction(L"Undo");
initial.commit09911bf2008-07-26 23:55:29799}
800
801void RenderView::OnRedo() {
802 if (!webview())
803 return;
804
[email protected]dd7daa82009-08-10 05:46:45805 webview()->GetFocusedFrame()->executeCommand(WebString::fromUTF8("Redo"));
806 UserMetricsRecordAction(L"Redo");
initial.commit09911bf2008-07-26 23:55:29807}
808
809void RenderView::OnCut() {
810 if (!webview())
811 return;
812
[email protected]dd7daa82009-08-10 05:46:45813 webview()->GetFocusedFrame()->executeCommand(WebString::fromUTF8("Cut"));
814 UserMetricsRecordAction(L"Cut");
initial.commit09911bf2008-07-26 23:55:29815}
816
817void RenderView::OnCopy() {
818 if (!webview())
819 return;
820
[email protected]dd7daa82009-08-10 05:46:45821 webview()->GetFocusedFrame()->executeCommand(WebString::fromUTF8("Copy"));
822 UserMetricsRecordAction(L"Copy");
initial.commit09911bf2008-07-26 23:55:29823}
824
825void RenderView::OnPaste() {
826 if (!webview())
827 return;
828
[email protected]dd7daa82009-08-10 05:46:45829 webview()->GetFocusedFrame()->executeCommand(WebString::fromUTF8("Paste"));
830 UserMetricsRecordAction(L"Paste");
initial.commit09911bf2008-07-26 23:55:29831}
832
833void RenderView::OnReplace(const std::wstring& text) {
834 if (!webview())
835 return;
836
[email protected]dd7daa82009-08-10 05:46:45837 webview()->GetFocusedFrame()->replaceSelection(WideToUTF16Hack(text));
initial.commit09911bf2008-07-26 23:55:29838}
839
[email protected]bbbd545c2008-12-15 20:18:04840void RenderView::OnToggleSpellCheck() {
841 if (!webview())
842 return;
843
[email protected]dd7daa82009-08-10 05:46:45844 WebFrame* frame = webview()->GetFocusedFrame();
845 frame->enableContinuousSpellChecking(
846 !frame->isContinuousSpellCheckingEnabled());
[email protected]bbbd545c2008-12-15 20:18:04847}
848
initial.commit09911bf2008-07-26 23:55:29849void RenderView::OnDelete() {
850 if (!webview())
851 return;
852
[email protected]dd7daa82009-08-10 05:46:45853 webview()->GetFocusedFrame()->executeCommand(WebString::fromUTF8("Delete"));
854 UserMetricsRecordAction(L"DeleteSelection");
initial.commit09911bf2008-07-26 23:55:29855}
856
857void RenderView::OnSelectAll() {
858 if (!webview())
859 return;
860
[email protected]dd7daa82009-08-10 05:46:45861 webview()->GetFocusedFrame()->selectAll();
initial.commit09911bf2008-07-26 23:55:29862}
863
864void RenderView::OnSetInitialFocus(bool reverse) {
865 if (!webview())
866 return;
867 webview()->SetInitialFocus(reverse);
868}
869
870///////////////////////////////////////////////////////////////////////////////
871
872// Tell the embedding application that the URL of the active page has changed
873void RenderView::UpdateURL(WebFrame* frame) {
[email protected]dd7daa82009-08-10 05:46:45874 WebDataSource* ds = frame->dataSource();
initial.commit09911bf2008-07-26 23:55:29875 DCHECK(ds);
876
[email protected]726985e22009-06-18 21:09:28877 const WebURLRequest& request = ds->request();
878 const WebURLRequest& original_request = ds->originalRequest();
879 const WebURLResponse& response = ds->response();
initial.commit09911bf2008-07-26 23:55:29880
[email protected]daa8c58e2009-06-15 17:21:10881 NavigationState* navigation_state = NavigationState::FromDataSource(ds);
882 DCHECK(navigation_state);
initial.commit09911bf2008-07-26 23:55:29883
884 ViewHostMsg_FrameNavigate_Params params;
[email protected]726985e22009-06-18 21:09:28885 params.http_status_code = response.httpStatusCode();
initial.commit09911bf2008-07-26 23:55:29886 params.is_post = false;
887 params.page_id = page_id_;
[email protected]726985e22009-06-18 21:09:28888 params.is_content_filtered = response.isContentFiltered();
[email protected]e6f546c32009-07-01 17:12:55889 if (!navigation_state->security_info().empty()) {
initial.commit09911bf2008-07-26 23:55:29890 // SSL state specified in the request takes precedence over the one in the
891 // response.
892 // So far this is only intended for error pages that are not expected to be
893 // over ssl, so we should not get any clash.
[email protected]726985e22009-06-18 21:09:28894 DCHECK(response.securityInfo().isEmpty());
[email protected]e6f546c32009-07-01 17:12:55895 params.security_info = navigation_state->security_info();
initial.commit09911bf2008-07-26 23:55:29896 } else {
[email protected]726985e22009-06-18 21:09:28897 params.security_info = response.securityInfo();
initial.commit09911bf2008-07-26 23:55:29898 }
899
900 // Set the URL to be displayed in the browser UI to the user.
[email protected]726985e22009-06-18 21:09:28901 if (ds->hasUnreachableURL()) {
902 params.url = ds->unreachableURL();
initial.commit09911bf2008-07-26 23:55:29903 } else {
[email protected]726985e22009-06-18 21:09:28904 params.url = request.url();
initial.commit09911bf2008-07-26 23:55:29905 }
906
[email protected]726985e22009-06-18 21:09:28907 GetRedirectChain(ds, &params.redirects);
908 params.should_update_history = !ds->hasUnreachableURL();
initial.commit09911bf2008-07-26 23:55:29909
910 const SearchableFormData* searchable_form_data =
[email protected]daa8c58e2009-06-15 17:21:10911 navigation_state->searchable_form_data();
initial.commit09911bf2008-07-26 23:55:29912 if (searchable_form_data) {
913 params.searchable_form_url = searchable_form_data->url();
914 params.searchable_form_element_name = searchable_form_data->element_name();
915 params.searchable_form_encoding = searchable_form_data->encoding();
916 }
917
918 const PasswordForm* password_form_data =
[email protected]daa8c58e2009-06-15 17:21:10919 navigation_state->password_form_data();
initial.commit09911bf2008-07-26 23:55:29920 if (password_form_data)
921 params.password_form = *password_form_data;
922
923 params.gesture = navigation_gesture_;
924 navigation_gesture_ = NavigationGestureUnknown;
925
[email protected]dd7daa82009-08-10 05:46:45926 if (!frame->parent()) {
initial.commit09911bf2008-07-26 23:55:29927 // Top-level navigation.
928
929 // Update contents MIME type for main frame.
[email protected]9c5645b2009-08-11 03:37:55930 params.contents_mime_type = ds->response().mimeType().utf8();
initial.commit09911bf2008-07-26 23:55:29931
[email protected]daa8c58e2009-06-15 17:21:10932 params.transition = navigation_state->transition_type();
initial.commit09911bf2008-07-26 23:55:29933 if (!PageTransition::IsMainFrame(params.transition)) {
934 // If the main frame does a load, it should not be reported as a subframe
935 // navigation. This can occur in the following case:
936 // 1. You're on a site with frames.
937 // 2. You do a subframe navigation. This is stored with transition type
938 // MANUAL_SUBFRAME.
939 // 3. You navigate to some non-frame site, say, google.com.
940 // 4. You navigate back to the page from step 2. Since it was initially
941 // MANUAL_SUBFRAME, it will be that same transition type here.
942 // We don't want that, because any navigation that changes the toplevel
943 // frame should be tracked as a toplevel navigation (this allows us to
944 // update the URL bar, etc).
945 params.transition = PageTransition::LINK;
946 }
947
initial.commit09911bf2008-07-26 23:55:29948 // If we have a valid consumed client redirect source,
949 // the page contained a client redirect (meta refresh, document.loc...),
950 // so we set the referrer and transition to match.
951 if (completed_client_redirect_src_.is_valid()) {
[email protected]77e09a92008-08-01 18:11:04952 DCHECK(completed_client_redirect_src_ == params.redirects[0]);
initial.commit09911bf2008-07-26 23:55:29953 params.referrer = completed_client_redirect_src_;
954 params.transition = static_cast<PageTransition::Type>(
955 params.transition | PageTransition::CLIENT_REDIRECT);
956 } else {
957 // Bug 654101: the referrer will be empty on https->http transitions. It
958 // would be nice if we could get the real referrer from somewhere.
[email protected]726985e22009-06-18 21:09:28959 params.referrer = GURL(
960 original_request.httpHeaderField(WebString::fromUTF8("Referer")));
initial.commit09911bf2008-07-26 23:55:29961 }
962
[email protected]726985e22009-06-18 21:09:28963 string16 method = request.httpMethod();
964 if (EqualsASCII(method, "POST"))
initial.commit09911bf2008-07-26 23:55:29965 params.is_post = true;
966
967 Send(new ViewHostMsg_FrameNavigate(routing_id_, params));
968 } else {
969 // Subframe navigation: the type depends on whether this navigation
970 // generated a new session history entry. When they do generate a session
971 // history entry, it means the user initiated the navigation and we should
972 // mark it as such. This test checks if this is the first time UpdateURL
973 // has been called since WillNavigateToURL was called to initiate the load.
974 if (page_id_ > last_page_id_sent_to_browser_)
975 params.transition = PageTransition::MANUAL_SUBFRAME;
976 else
977 params.transition = PageTransition::AUTO_SUBFRAME;
978
initial.commit09911bf2008-07-26 23:55:29979 Send(new ViewHostMsg_FrameNavigate(routing_id_, params));
980 }
981
982 last_page_id_sent_to_browser_ =
983 std::max(last_page_id_sent_to_browser_, page_id_);
984
985 // If we end up reusing this WebRequest (for example, due to a #ref click),
[email protected]daa8c58e2009-06-15 17:21:10986 // we don't want the transition type to persist. Just clear it.
987 navigation_state->set_transition_type(PageTransition::LINK);
[email protected]266eb6f2008-09-30 23:56:50988
[email protected]6c8afae52009-01-22 02:24:57989#if defined(OS_WIN)
[email protected]6a983b42009-03-20 20:12:25990 if (web_accessibility_manager_.get()) {
[email protected]be645db2009-02-06 20:36:33991 // Clear accessibility info cache.
[email protected]6a983b42009-03-20 20:12:25992 web_accessibility_manager_->ClearAccObjMap(-1, true);
[email protected]266eb6f2008-09-30 23:56:50993 }
[email protected]6c8afae52009-01-22 02:24:57994#else
[email protected]7d926f92009-03-03 14:26:54995 // TODO(port): accessibility not yet implemented. See http://crbug.com/8288.
[email protected]6c8afae52009-01-22 02:24:57996#endif
initial.commit09911bf2008-07-26 23:55:29997}
998
999// Tell the embedding application that the title of the active page has changed
1000void RenderView::UpdateTitle(WebFrame* frame, const std::wstring& title) {
1001 // Ignore all but top level navigations...
[email protected]f0af6a72009-05-30 05:25:171002 if (webview()->GetMainFrame() == frame) {
1003 Send(new ViewHostMsg_UpdateTitle(
1004 routing_id_,
1005 page_id_,
1006 title.length() > chrome::kMaxTitleChars ?
1007 title.substr(0, chrome::kMaxTitleChars) : title));
1008 }
initial.commit09911bf2008-07-26 23:55:291009}
1010
1011void RenderView::UpdateEncoding(WebFrame* frame,
[email protected]e38f40152008-09-12 23:08:301012 const std::wstring& encoding_name) {
initial.commit09911bf2008-07-26 23:55:291013 // Only update main frame's encoding_name.
1014 if (webview()->GetMainFrame() == frame &&
1015 last_encoding_name_ != encoding_name) {
[email protected]e38f40152008-09-12 23:08:301016 // Save the encoding name for later comparing.
initial.commit09911bf2008-07-26 23:55:291017 last_encoding_name_ = encoding_name;
1018
[email protected]e38f40152008-09-12 23:08:301019 Send(new ViewHostMsg_UpdateEncoding(routing_id_, last_encoding_name_));
initial.commit09911bf2008-07-26 23:55:291020 }
1021}
1022
[email protected]f4d34b52008-11-24 23:05:011023// Sends the previous session history state to the browser so it will be saved
1024// before we navigate to a new page. This must be called *before* the page ID
1025// has been updated so we know what it was.
initial.commit09911bf2008-07-26 23:55:291026void RenderView::UpdateSessionHistory(WebFrame* frame) {
1027 // If we have a valid page ID at this point, then it corresponds to the page
1028 // we are navigating away from. Otherwise, this is the first navigation, so
1029 // there is no past session history to record.
1030 if (page_id_ == -1)
1031 return;
1032
[email protected]ca948a22009-06-25 19:36:171033 const WebHistoryItem& item =
[email protected]dd7daa82009-08-10 05:46:451034 webview()->GetMainFrame()->previousHistoryItem();
[email protected]ca948a22009-06-25 19:36:171035 if (item.isNull())
initial.commit09911bf2008-07-26 23:55:291036 return;
[email protected]ca948a22009-06-25 19:36:171037
1038 Send(new ViewHostMsg_UpdateState(
1039 routing_id_, page_id_, webkit_glue::HistoryItemToString(item)));
initial.commit09911bf2008-07-26 23:55:291040}
1041
1042///////////////////////////////////////////////////////////////////////////////
1043// WebViewDelegate
1044
[email protected]80d96fa2009-06-10 22:34:511045bool RenderView::CanAcceptLoadDrops() const {
1046 return renderer_preferences_.can_accept_load_drops;
1047}
1048
initial.commit09911bf2008-07-26 23:55:291049void RenderView::DidStartLoading(WebView* webview) {
1050 if (is_loading_) {
1051 DLOG(WARNING) << "DidStartLoading called while loading";
1052 return;
1053 }
1054
1055 is_loading_ = true;
1056 // Clear the pointer so that we can assign it only when there is an unknown
1057 // plugin on a page.
1058 first_default_plugin_ = NULL;
1059
[email protected]329581b2009-04-28 06:52:351060 Send(new ViewHostMsg_DidStartLoading(routing_id_));
initial.commit09911bf2008-07-26 23:55:291061}
1062
1063void RenderView::DidStopLoading(WebView* webview) {
1064 if (!is_loading_) {
1065 DLOG(WARNING) << "DidStopLoading called while not loading";
1066 return;
1067 }
1068
1069 is_loading_ = false;
1070
1071 // NOTE: For now we're doing the safest thing, and sending out notification
1072 // when done loading. This currently isn't an issue as the favicon is only
1073 // displayed when done loading. Ideally we would send notification when
1074 // finished parsing the head, but webkit doesn't support that yet.
1075 // The feed discovery code would also benefit from access to the head.
[email protected]dd7daa82009-08-10 05:46:451076 GURL favicon_url(webview->GetMainFrame()->favIconURL());
initial.commit09911bf2008-07-26 23:55:291077 if (!favicon_url.is_empty())
1078 Send(new ViewHostMsg_UpdateFavIconURL(routing_id_, page_id_, favicon_url));
1079
[email protected]dd7daa82009-08-10 05:46:451080 AddGURLSearchProvider(webview->GetMainFrame()->openSearchDescriptionURL(),
initial.commit09911bf2008-07-26 23:55:291081 true); // autodetected
1082
[email protected]329581b2009-04-28 06:52:351083 Send(new ViewHostMsg_DidStopLoading(routing_id_));
initial.commit09911bf2008-07-26 23:55:291084
1085 MessageLoop::current()->PostDelayedTask(FROM_HERE,
1086 method_factory_.NewRunnableMethod(&RenderView::CapturePageInfo, page_id_,
1087 false),
1088 kDelayForCaptureMs);
1089
1090 // The page is loaded. Try to process the file we need to upload if any.
1091 ProcessPendingUpload();
1092
1093 // Since the page is done loading, we are sure we don't need to try
1094 // again.
1095 ResetPendingUpload();
1096}
1097
[email protected]77f17a82009-05-21 04:42:541098void RenderView::DidCreateDataSource(WebFrame* frame, WebDataSource* ds) {
[email protected]daa8c58e2009-06-15 17:21:101099 // The rest of RenderView assumes that a WebDataSource will always have a
1100 // non-null NavigationState.
1101 if (pending_navigation_state_.get()) {
[email protected]726985e22009-06-18 21:09:281102 ds->setExtraData(pending_navigation_state_.release());
[email protected]daa8c58e2009-06-15 17:21:101103 } else {
[email protected]726985e22009-06-18 21:09:281104 ds->setExtraData(NavigationState::CreateContentInitiated());
[email protected]daa8c58e2009-06-15 17:21:101105 }
[email protected]77f17a82009-05-21 04:42:541106}
1107
[email protected]a2f6bc112009-06-27 16:27:251108void RenderView::DidPaint() {
1109 WebFrame* main_frame = webview()->GetMainFrame();
1110
[email protected]dd7daa82009-08-10 05:46:451111 if (main_frame->provisionalDataSource()) {
[email protected]a2f6bc112009-06-27 16:27:251112 // If we have a provisional frame we are between the start
1113 // and commit stages of loading...ignore this paint.
1114 return;
1115 }
1116
[email protected]dd7daa82009-08-10 05:46:451117 WebDataSource* ds = main_frame->dataSource();
[email protected]a2f6bc112009-06-27 16:27:251118 NavigationState* navigation_state = NavigationState::FromDataSource(ds);
[email protected]78a3a6f2009-07-02 16:15:011119 DCHECK(navigation_state);
1120
1121 Time now = Time::Now();
1122 if (navigation_state->first_paint_time().is_null()) {
1123 navigation_state->set_first_paint_time(now);
1124 }
1125 if (navigation_state->first_paint_after_load_time().is_null() &&
1126 !navigation_state->finish_load_time().is_null()) {
1127 navigation_state->set_first_paint_after_load_time(now);
[email protected]a2f6bc112009-06-27 16:27:251128 }
1129}
1130
initial.commit09911bf2008-07-26 23:55:291131void RenderView::DidStartProvisionalLoadForFrame(
1132 WebView* webview,
1133 WebFrame* frame,
1134 NavigationGesture gesture) {
[email protected]dd7daa82009-08-10 05:46:451135 WebDataSource* ds = frame->provisionalDataSource();
[email protected]ed3fb032009-06-16 19:50:561136 NavigationState* navigation_state = NavigationState::FromDataSource(ds);
1137
1138 navigation_state->set_start_load_time(Time::Now());
1139
1140 // Update the request time if WebKit has better knowledge of it.
1141 if (navigation_state->request_time().is_null()) {
[email protected]726985e22009-06-18 21:09:281142 double event_time = ds->triggeringEventTime();
[email protected]ed3fb032009-06-16 19:50:561143 if (event_time != 0.0)
1144 navigation_state->set_request_time(Time::FromDoubleT(event_time));
1145 }
1146
[email protected]dd7daa82009-08-10 05:46:451147 bool is_top_most = !frame->parent();
[email protected]ed3fb032009-06-16 19:50:561148 if (is_top_most) {
initial.commit09911bf2008-07-26 23:55:291149 navigation_gesture_ = gesture;
[email protected]266eb6f2008-09-30 23:56:501150
[email protected]77e09a92008-08-01 18:11:041151 // Make sure redirect tracking state is clear for the new load.
1152 completed_client_redirect_src_ = GURL();
[email protected]dd7daa82009-08-10 05:46:451153 } else if (frame->parent()->isLoading()) {
[email protected]15d79e12009-08-02 19:23:451154 // Take note of AUTO_SUBFRAME loads here, so that we can know how to
1155 // load an error page. See DidFailProvisionalLoadWithError.
1156 navigation_state->set_transition_type(PageTransition::AUTO_SUBFRAME);
[email protected]77e09a92008-08-01 18:11:041157 }
initial.commit09911bf2008-07-26 23:55:291158
1159 Send(new ViewHostMsg_DidStartProvisionalLoadForFrame(
[email protected]726985e22009-06-18 21:09:281160 routing_id_, is_top_most, ds->request().url()));
initial.commit09911bf2008-07-26 23:55:291161}
1162
1163bool RenderView::DidLoadResourceFromMemoryCache(WebView* webview,
[email protected]726985e22009-06-18 21:09:281164 const WebURLRequest& request,
1165 const WebURLResponse& response,
initial.commit09911bf2008-07-26 23:55:291166 WebFrame* frame) {
1167 // Let the browser know we loaded a resource from the memory cache. This
1168 // message is needed to display the correct SSL indicators.
[email protected]dd7daa82009-08-10 05:46:451169 Send(new ViewHostMsg_DidLoadResourceFromMemoryCache(
1170 routing_id_,
1171 request.url(),
1172 frame->securityOrigin().utf8(),
1173 frame->top()->securityOrigin().utf8(),
[email protected]726985e22009-06-18 21:09:281174 response.securityInfo()));
initial.commit09911bf2008-07-26 23:55:291175
1176 return false;
1177}
1178
1179void RenderView::DidReceiveProvisionalLoadServerRedirect(WebView* webview,
1180 WebFrame* frame) {
1181 if (frame == webview->GetMainFrame()) {
1182 // Received a redirect on the main frame.
1183 WebDataSource* data_source =
[email protected]dd7daa82009-08-10 05:46:451184 webview->GetMainFrame()->provisionalDataSource();
initial.commit09911bf2008-07-26 23:55:291185 if (!data_source) {
1186 // Should only be invoked when we have a data source.
1187 NOTREACHED();
1188 return;
1189 }
[email protected]726985e22009-06-18 21:09:281190 std::vector<GURL> redirects;
1191 GetRedirectChain(data_source, &redirects);
initial.commit09911bf2008-07-26 23:55:291192 if (redirects.size() >= 2) {
1193 Send(new ViewHostMsg_DidRedirectProvisionalLoad(
1194 routing_id_, page_id_, redirects[redirects.size() - 2],
1195 redirects[redirects.size() - 1]));
1196 }
1197 }
1198}
1199
1200void RenderView::DidFailProvisionalLoadWithError(WebView* webview,
[email protected]726985e22009-06-18 21:09:281201 const WebURLError& error,
initial.commit09911bf2008-07-26 23:55:291202 WebFrame* frame) {
1203 // Notify the browser that we failed a provisional load with an error.
1204 //
1205 // Note: It is important this notification occur before DidStopLoading so the
1206 // SSL manager can react to the provisional load failure before being
1207 // notified the load stopped.
1208 //
[email protected]dd7daa82009-08-10 05:46:451209 WebDataSource* ds = frame->provisionalDataSource();
initial.commit09911bf2008-07-26 23:55:291210 DCHECK(ds);
1211
[email protected]726985e22009-06-18 21:09:281212 const WebURLRequest& failed_request = ds->request();
initial.commit09911bf2008-07-26 23:55:291213
1214 bool show_repost_interstitial =
[email protected]726985e22009-06-18 21:09:281215 (error.reason == net::ERR_CACHE_MISS &&
1216 EqualsASCII(failed_request.httpMethod(), "POST"));
initial.commit09911bf2008-07-26 23:55:291217 Send(new ViewHostMsg_DidFailProvisionalLoadWithError(
[email protected]dd7daa82009-08-10 05:46:451218 routing_id_, !frame->parent(), error.reason, error.unreachableURL,
initial.commit09911bf2008-07-26 23:55:291219 show_repost_interstitial));
1220
initial.commit09911bf2008-07-26 23:55:291221 // Don't display an error page if this is simply a cancelled load. Aside
1222 // from being dumb, WebCore doesn't expect it and it will cause a crash.
[email protected]726985e22009-06-18 21:09:281223 if (error.reason == net::ERR_ABORTED)
initial.commit09911bf2008-07-26 23:55:291224 return;
1225
[email protected]546ddd172009-06-25 00:25:011226 // Make sure we never show errors in view source mode.
[email protected]dd7daa82009-08-10 05:46:451227 frame->enableViewSourceMode(false);
[email protected]546ddd172009-06-25 00:25:011228
[email protected]15d79e12009-08-02 19:23:451229 NavigationState* navigation_state = NavigationState::FromDataSource(ds);
1230
initial.commit09911bf2008-07-26 23:55:291231 // If this is a failed back/forward/reload navigation, then we need to do a
1232 // 'replace' load. This is necessary to avoid messing up session history.
1233 // Otherwise, we do a normal load, which simulates a 'go' navigation as far
1234 // as session history is concerned.
[email protected]15d79e12009-08-02 19:23:451235 //
1236 // AUTO_SUBFRAME loads should always be treated as loads that do not advance
1237 // the page id.
1238 //
1239 bool replace =
1240 navigation_state->pending_page_id() != -1 ||
1241 navigation_state->transition_type() == PageTransition::AUTO_SUBFRAME;
initial.commit09911bf2008-07-26 23:55:291242
[email protected]15d79e12009-08-02 19:23:451243 // If we failed on a browser initiated request, then make sure that our error
1244 // page load is regarded as the same browser initiated request.
1245 if (!navigation_state->is_content_initiated()) {
1246 pending_navigation_state_.reset(NavigationState::CreateBrowserInitiated(
1247 navigation_state->pending_page_id(),
1248 navigation_state->transition_type(),
1249 navigation_state->request_time()));
initial.commit09911bf2008-07-26 23:55:291250 }
[email protected]5df266ac2008-10-15 19:50:131251
[email protected]15d79e12009-08-02 19:23:451252 // Provide the user with a more helpful error page?
1253 if (MaybeLoadAlternateErrorPage(frame, error, replace))
1254 return;
1255
[email protected]be645db2009-02-06 20:36:331256 // Fallback to a local error page.
[email protected]726985e22009-06-18 21:09:281257 LoadNavigationErrorPage(frame, failed_request, error, std::string(),
[email protected]5df266ac2008-10-15 19:50:131258 replace);
initial.commit09911bf2008-07-26 23:55:291259}
1260
1261void RenderView::LoadNavigationErrorPage(WebFrame* frame,
[email protected]726985e22009-06-18 21:09:281262 const WebURLRequest& failed_request,
1263 const WebURLError& error,
initial.commit09911bf2008-07-26 23:55:291264 const std::string& html,
1265 bool replace) {
[email protected]726985e22009-06-18 21:09:281266 GURL failed_url = error.unreachableURL;
initial.commit09911bf2008-07-26 23:55:291267
1268 std::string alt_html;
1269 if (html.empty()) {
1270 // Use a local error page.
1271 int resource_id;
1272 DictionaryValue error_strings;
[email protected]726985e22009-06-18 21:09:281273 if (error.reason == net::ERR_CACHE_MISS &&
1274 EqualsASCII(failed_request.httpMethod(), "POST")) {
initial.commit09911bf2008-07-26 23:55:291275 GetFormRepostErrorValues(failed_url, &error_strings);
1276 resource_id = IDR_ERROR_NO_DETAILS_HTML;
1277 } else {
1278 GetLocalizedErrorValues(error, &error_strings);
1279 resource_id = IDR_NET_ERROR_HTML;
1280 }
[email protected]8e50b602009-03-03 22:59:431281 error_strings.SetString(L"textdirection",
1282 (l10n_util::GetTextDirection() == l10n_util::RIGHT_TO_LEFT) ?
1283 L"rtl" : L"ltr");
initial.commit09911bf2008-07-26 23:55:291284
1285 alt_html = GetAltHTMLForTemplate(error_strings, resource_id);
1286 } else {
1287 alt_html = html;
1288 }
1289
[email protected]dd7daa82009-08-10 05:46:451290 frame->loadHTMLString(alt_html,
[email protected]e6f546c32009-07-01 17:12:551291 GURL(kUnreachableWebDataURL),
1292 failed_url,
1293 replace);
initial.commit09911bf2008-07-26 23:55:291294}
1295
[email protected]7ccddb8c2009-08-04 17:36:551296void RenderView::DidReceiveDocumentData(WebFrame* frame, const char* data,
1297 size_t data_len) {
1298 NavigationState* navigation_state =
[email protected]dd7daa82009-08-10 05:46:451299 NavigationState::FromDataSource(frame->dataSource());
[email protected]7ccddb8c2009-08-04 17:36:551300 if (!navigation_state->postpone_loading_data()) {
[email protected]dd7daa82009-08-10 05:46:451301 frame->commitDocumentData(data, data_len);
[email protected]7ccddb8c2009-08-04 17:36:551302 return;
1303 }
1304
1305 // Continue buffering the response data for the original 404 page. If it
1306 // grows too large, then we'll just let it through.
1307 navigation_state->append_postponed_data(data, data_len);
1308 if (navigation_state->postponed_data().size() >= 512) {
1309 navigation_state->set_postpone_loading_data(false);
[email protected]dd7daa82009-08-10 05:46:451310 frame->commitDocumentData(navigation_state->postponed_data().data(),
[email protected]7ccddb8c2009-08-04 17:36:551311 navigation_state->postponed_data().size());
1312 navigation_state->clear_postponed_data();
1313 }
1314}
1315
initial.commit09911bf2008-07-26 23:55:291316void RenderView::DidCommitLoadForFrame(WebView *webview, WebFrame* frame,
1317 bool is_new_navigation) {
[email protected]daa8c58e2009-06-15 17:21:101318 NavigationState* navigation_state =
[email protected]dd7daa82009-08-10 05:46:451319 NavigationState::FromDataSource(frame->dataSource());
initial.commit09911bf2008-07-26 23:55:291320
[email protected]a2f6bc112009-06-27 16:27:251321 navigation_state->set_commit_load_time(Time::Now());
initial.commit09911bf2008-07-26 23:55:291322 if (is_new_navigation) {
1323 // When we perform a new navigation, we need to update the previous session
1324 // history entry with state for the page we are leaving.
1325 UpdateSessionHistory(frame);
1326
1327 // We bump our Page ID to correspond with the new session history entry.
1328 page_id_ = next_page_id_++;
1329
1330 MessageLoop::current()->PostDelayedTask(FROM_HERE,
1331 method_factory_.NewRunnableMethod(&RenderView::CapturePageInfo,
1332 page_id_, true),
1333 kDelayForForcedCaptureMs);
1334 } else {
[email protected]15d79e12009-08-02 19:23:451335 // Inspect the navigation_state on this frame to see if the navigation
1336 // corresponds to a session history navigation... Note: |frame| may or
1337 // may not be the toplevel frame, but for the case of capturing session
1338 // history, the first committed frame suffices. We keep track of whether
1339 // we've seen this commit before so that only capture session history once
1340 // per navigation.
[email protected]f4d34b52008-11-24 23:05:011341 //
1342 // Note that we need to check if the page ID changed. In the case of a
1343 // reload, the page ID doesn't change, and UpdateSessionHistory gets the
1344 // previous URL and the current page ID, which would be wrong.
[email protected]15d79e12009-08-02 19:23:451345 if (navigation_state->pending_page_id() != -1 &&
1346 navigation_state->pending_page_id() != page_id_ &&
1347 !navigation_state->request_committed()) {
initial.commit09911bf2008-07-26 23:55:291348 // This is a successful session history navigation!
1349 UpdateSessionHistory(frame);
[email protected]77f17a82009-05-21 04:42:541350 page_id_ = navigation_state->pending_page_id();
initial.commit09911bf2008-07-26 23:55:291351 }
1352 }
1353
1354 // Remember that we've already processed this request, so we don't update
1355 // the session history again. We do this regardless of whether this is
1356 // a session history navigation, because if we attempted a session history
1357 // navigation without valid HistoryItem state, WebCore will think it is a
1358 // new navigation.
[email protected]daa8c58e2009-06-15 17:21:101359 navigation_state->set_request_committed(true);
initial.commit09911bf2008-07-26 23:55:291360
1361 UpdateURL(frame);
1362
1363 // If this committed load was initiated by a client redirect, we're
1364 // at the last stop now, so clear it.
1365 completed_client_redirect_src_ = GURL();
1366
1367 // Check whether we have new encoding name.
1368 UpdateEncoding(frame, webview->GetMainFrameEncodingName());
1369}
1370
1371void RenderView::DidReceiveTitle(WebView* webview,
1372 const std::wstring& title,
1373 WebFrame* frame) {
1374 UpdateTitle(frame, title);
1375
1376 // Also check whether we have new encoding name.
1377 UpdateEncoding(frame, webview->GetMainFrameEncodingName());
1378}
1379
1380void RenderView::DidFinishLoadForFrame(WebView* webview, WebFrame* frame) {
[email protected]dd7daa82009-08-10 05:46:451381 WebDataSource* ds = frame->dataSource();
[email protected]a2f6bc112009-06-27 16:27:251382 NavigationState* navigation_state = NavigationState::FromDataSource(ds);
[email protected]78a3a6f2009-07-02 16:15:011383 DCHECK(navigation_state);
1384 navigation_state->set_finish_load_time(Time::Now());
initial.commit09911bf2008-07-26 23:55:291385}
1386
1387void RenderView::DidFailLoadWithError(WebView* webview,
[email protected]726985e22009-06-18 21:09:281388 const WebURLError& error,
initial.commit09911bf2008-07-26 23:55:291389 WebFrame* frame) {
[email protected]546ddd172009-06-25 00:25:011390 // Currently this function is empty. When you implement something here and it
1391 // will display any error messages in HTML, please make sure to call
1392 // frame->SetInViewSourceMode(false) not to show them in view source mode.
initial.commit09911bf2008-07-26 23:55:291393}
1394
1395void RenderView::DidFinishDocumentLoadForFrame(WebView* webview,
1396 WebFrame* frame) {
[email protected]dd7daa82009-08-10 05:46:451397 WebDataSource* ds = frame->dataSource();
[email protected]a2f6bc112009-06-27 16:27:251398 NavigationState* navigation_state = NavigationState::FromDataSource(ds);
[email protected]78a3a6f2009-07-02 16:15:011399 DCHECK(navigation_state);
1400 navigation_state->set_finish_document_load_time(Time::Now());
[email protected]a2f6bc112009-06-27 16:27:251401
[email protected]09b8f82f2009-06-16 20:22:111402 Send(new ViewHostMsg_DocumentLoadedInFrame(routing_id_));
1403
[email protected]daa8c58e2009-06-15 17:21:101404 // The document has now been fully loaded. Scan for password forms to be
1405 // sent up to the browser.
1406 SendPasswordForms(frame);
1407
initial.commit09911bf2008-07-26 23:55:291408 // Check whether we have new encoding name.
1409 UpdateEncoding(frame, webview->GetMainFrameEncodingName());
[email protected]1e0f70402008-10-16 23:57:471410
[email protected]8930d472009-02-21 08:05:281411 if (RenderThread::current()) // Will be NULL during unit tests.
1412 RenderThread::current()->user_script_slave()->InjectScripts(
[email protected]0afe8272009-02-14 04:15:161413 frame, UserScript::DOCUMENT_END);
initial.commit09911bf2008-07-26 23:55:291414}
1415
1416void RenderView::DidHandleOnloadEventsForFrame(WebView* webview,
1417 WebFrame* frame) {
1418}
1419
1420void RenderView::DidChangeLocationWithinPageForFrame(WebView* webview,
1421 WebFrame* frame,
1422 bool is_new_navigation) {
[email protected]77f17a82009-05-21 04:42:541423 // If this was a reference fragment navigation that we initiated, then we
1424 // could end up having a non-null pending navigation state. We just need to
1425 // update the ExtraData on the datasource so that others who read the
1426 // ExtraData will get the new NavigationState. Similarly, if we did not
[email protected]daa8c58e2009-06-15 17:21:101427 // initiate this navigation, then we need to take care to reset any pre-
1428 // existing navigation state to a content-initiated navigation state.
1429 // DidCreateDataSource conveniently takes care of this for us.
[email protected]dd7daa82009-08-10 05:46:451430 DidCreateDataSource(frame, frame->dataSource());
[email protected]77f17a82009-05-21 04:42:541431
initial.commit09911bf2008-07-26 23:55:291432 DidCommitLoadForFrame(webview, frame, is_new_navigation);
[email protected]77f17a82009-05-21 04:42:541433
[email protected]9d806f52009-03-12 22:50:541434 const string16& title =
[email protected]dd7daa82009-08-10 05:46:451435 webview->GetMainFrame()->dataSource()->pageTitle();
[email protected]9d806f52009-03-12 22:50:541436 UpdateTitle(frame, UTF16ToWideHack(title));
initial.commit09911bf2008-07-26 23:55:291437}
1438
initial.commit09911bf2008-07-26 23:55:291439void RenderView::DidCompleteClientRedirect(WebView* webview,
1440 WebFrame* frame,
1441 const GURL& source) {
1442 if (webview->GetMainFrame() == frame)
1443 completed_client_redirect_src_ = source;
1444}
1445
[email protected]7a9b51f2009-06-29 21:28:291446void RenderView::WillCloseFrame(WebView* webview, WebFrame* frame) {
[email protected]dd7daa82009-08-10 05:46:451447 if (!frame->parent()) {
1448 const GURL& url = frame->url();
[email protected]7a9b51f2009-06-29 21:28:291449 if (url.SchemeIs("http") || url.SchemeIs("https"))
1450 DumpLoadHistograms();
1451 }
1452}
1453
[email protected]daa8c58e2009-06-15 17:21:101454void RenderView::WillSubmitForm(WebView* webview, WebFrame* frame,
1455 const WebForm& form) {
1456 NavigationState* navigation_state =
[email protected]dd7daa82009-08-10 05:46:451457 NavigationState::FromDataSource(frame->provisionalDataSource());
[email protected]daa8c58e2009-06-15 17:21:101458
1459 if (navigation_state->transition_type() == PageTransition::LINK)
1460 navigation_state->set_transition_type(PageTransition::FORM_SUBMIT);
1461
1462 // Save these to be processed when the ensuing navigation is committed.
1463 navigation_state->set_searchable_form_data(
1464 SearchableFormData::Create(form));
1465 navigation_state->set_password_form_data(
1466 PasswordFormDomManager::CreatePasswordForm(form));
1467
1468 if (form.isAutoCompleteEnabled()) {
1469 scoped_ptr<AutofillForm> autofill_form(AutofillForm::Create(form));
1470 if (autofill_form.get())
1471 Send(new ViewHostMsg_AutofillFormSubmitted(routing_id_, *autofill_form));
1472 }
1473}
1474
[email protected]7ccddb8c2009-08-04 17:36:551475void RenderView::WillSendRequest(WebFrame* frame, uint32 identifier,
[email protected]a1353852009-08-06 05:34:221476 WebURLRequest* request,
1477 const WebURLResponse& redirect_response) {
[email protected]726985e22009-06-18 21:09:281478 request->setRequestorID(routing_id_);
[email protected]5b35a6b2009-03-16 19:58:081479}
1480
[email protected]7ccddb8c2009-08-04 17:36:551481void RenderView::DidReceiveResponse(WebFrame* frame, uint32 identifier,
1482 const WebURLResponse& response) {
1483 // Consider loading an alternate error page for 404 responses.
1484 if (response.httpStatusCode() != 404)
1485 return;
1486
1487 // Only do this for responses that correspond to a provisional data source
1488 // of the top-most frame. If we have a provisional data source, then we
1489 // can't have any sub-resources yet, so we know that this response must
1490 // correspond to a frame load.
[email protected]dd7daa82009-08-10 05:46:451491 if (!frame->provisionalDataSource() || frame->parent())
[email protected]7ccddb8c2009-08-04 17:36:551492 return;
1493
1494 // If we are in view source mode, then just let the user see the source of
1495 // the server's 404 error page.
[email protected]dd7daa82009-08-10 05:46:451496 if (frame->isViewSourceModeEnabled())
[email protected]7ccddb8c2009-08-04 17:36:551497 return;
1498
1499 // Can we even load an alternate error page for this URL?
1500 if (!GetAlternateErrorPageURL(response.url(), HTTP_404).is_valid())
1501 return;
1502
1503 NavigationState* navigation_state =
[email protected]dd7daa82009-08-10 05:46:451504 NavigationState::FromDataSource(frame->provisionalDataSource());
[email protected]7ccddb8c2009-08-04 17:36:551505 navigation_state->set_postpone_loading_data(true);
1506 navigation_state->clear_postponed_data();
1507}
1508
1509void RenderView::DidFinishLoading(WebFrame* frame, uint32 identifier) {
1510 NavigationState* navigation_state =
[email protected]dd7daa82009-08-10 05:46:451511 NavigationState::FromDataSource(frame->dataSource());
[email protected]7ccddb8c2009-08-04 17:36:551512 if (!navigation_state->postpone_loading_data())
1513 return;
1514
1515 // The server returned a 404 and the content was < 512 bytes (which we
1516 // suppressed). Go ahead and fetch the alternate page content.
1517
[email protected]dd7daa82009-08-10 05:46:451518 const GURL& frame_url = frame->url();
[email protected]7ccddb8c2009-08-04 17:36:551519
1520 const GURL& error_page_url = GetAlternateErrorPageURL(frame_url, HTTP_404);
1521 DCHECK(error_page_url.is_valid());
1522
1523 WebURLError original_error;
1524 original_error.unreachableURL = frame_url;
1525
1526 navigation_state->set_alt_error_page_fetcher(
1527 new AltErrorPageResourceFetcher(
1528 error_page_url, frame, original_error,
1529 NewCallback(this, &RenderView::AltErrorPageFinished)));
1530}
1531
1532void RenderView::BindDOMAutomationController(WebFrame* frame) {
initial.commit09911bf2008-07-26 23:55:291533 dom_automation_controller_.set_message_sender(this);
1534 dom_automation_controller_.set_routing_id(routing_id_);
[email protected]7ccddb8c2009-08-04 17:36:551535 dom_automation_controller_.BindToJavascript(frame,
initial.commit09911bf2008-07-26 23:55:291536 L"domAutomationController");
1537}
1538
[email protected]7ccddb8c2009-08-04 17:36:551539void RenderView::WindowObjectCleared(WebFrame* frame) {
[email protected]81e63782009-02-27 19:35:091540 if (BindingsPolicy::is_dom_automation_enabled(enabled_bindings_))
[email protected]7ccddb8c2009-08-04 17:36:551541 BindDOMAutomationController(frame);
[email protected]81e63782009-02-27 19:35:091542 if (BindingsPolicy::is_dom_ui_enabled(enabled_bindings_)) {
initial.commit09911bf2008-07-26 23:55:291543 dom_ui_bindings_.set_message_sender(this);
1544 dom_ui_bindings_.set_routing_id(routing_id_);
[email protected]7ccddb8c2009-08-04 17:36:551545 dom_ui_bindings_.BindToJavascript(frame, L"chrome");
initial.commit09911bf2008-07-26 23:55:291546 }
[email protected]81e63782009-02-27 19:35:091547 if (BindingsPolicy::is_external_host_enabled(enabled_bindings_)) {
[email protected]18cb2572008-08-21 20:34:451548 external_host_bindings_.set_message_sender(this);
1549 external_host_bindings_.set_routing_id(routing_id_);
[email protected]7ccddb8c2009-08-04 17:36:551550 external_host_bindings_.BindToJavascript(frame, L"externalHost");
[email protected]18cb2572008-08-21 20:34:451551 }
initial.commit09911bf2008-07-26 23:55:291552}
1553
[email protected]0afe8272009-02-14 04:15:161554void RenderView::DocumentElementAvailable(WebFrame* frame) {
[email protected]4b8323b2009-04-17 18:45:441555 // TODO(mpcomplete): remove this before Chrome extensions ship.
1556 // HACK. This is a temporary workaround to allow cross-origin XHR for Chrome
1557 // extensions. It grants full access to every origin, when we really want
1558 // to be able to restrict them more specifically.
[email protected]dd7daa82009-08-10 05:46:451559 GURL url = frame->url();
[email protected]e95ad332009-08-03 19:44:251560 if (url.SchemeIs(chrome::kExtensionScheme))
[email protected]dd7daa82009-08-10 05:46:451561 frame->grantUniversalAccess();
[email protected]d959ce22009-04-15 21:03:421562
[email protected]8930d472009-02-21 08:05:281563 if (RenderThread::current()) // Will be NULL during unit tests.
1564 RenderThread::current()->user_script_slave()->InjectScripts(
[email protected]0afe8272009-02-14 04:15:161565 frame, UserScript::DOCUMENT_START);
[email protected]e95ad332009-08-03 19:44:251566
1567 // Notify the browser about non-blank documents loading in the top frame.
1568 if (url.is_valid() && url.spec() != "about:blank") {
1569 if (frame == webview()->GetMainFrame())
1570 Send(new ViewHostMsg_DocumentAvailableInMainFrame(routing_id_));
1571 }
[email protected]0afe8272009-02-14 04:15:161572}
1573
[email protected]b6ce15972009-07-14 22:14:011574void RenderView::DidCreateScriptContextForFrame(WebFrame* webframe) {
[email protected]7120f132009-07-20 21:05:371575 EventBindings::HandleContextCreated(webframe, false);
[email protected]f816c012009-06-26 21:48:321576}
1577
[email protected]b6ce15972009-07-14 22:14:011578void RenderView::DidDestroyScriptContextForFrame(WebFrame* webframe) {
[email protected]f816c012009-06-26 21:48:321579 EventBindings::HandleContextDestroyed(webframe);
1580}
1581
[email protected]b6ce15972009-07-14 22:14:011582void RenderView::DidCreateIsolatedScriptContext(WebFrame* webframe) {
[email protected]7120f132009-07-20 21:05:371583 EventBindings::HandleContextCreated(webframe, true);
[email protected]b6ce15972009-07-14 22:14:011584}
1585
[email protected]4873c7d2009-07-16 06:36:281586WebNavigationPolicy RenderView::PolicyForNavigationAction(
initial.commit09911bf2008-07-26 23:55:291587 WebView* webview,
1588 WebFrame* frame,
[email protected]726985e22009-06-18 21:09:281589 const WebURLRequest& request,
initial.commit09911bf2008-07-26 23:55:291590 WebNavigationType type,
[email protected]4873c7d2009-07-16 06:36:281591 WebNavigationPolicy default_policy,
initial.commit09911bf2008-07-26 23:55:291592 bool is_redirect) {
[email protected]5f450e52009-07-28 13:28:111593 // Webkit is asking whether to navigate to a new URL.
1594 // This is fine normally, except if we're showing UI from one security
1595 // context and they're trying to navigate to a different context.
1596 const GURL& url = request.url();
1597
1598 // If the browser is interested, then give it a chance to look at top level
1599 // navigations
1600 if (renderer_preferences_.browser_handles_top_level_requests &&
1601 // Only send once.
1602 last_top_level_navigation_page_id_ != page_id_ &&
1603 // Not interested in reloads.
1604 type != WebKit::WebNavigationTypeReload &&
[email protected]87d3a2952009-08-10 18:07:371605 type != WebKit::WebNavigationTypeFormSubmitted &&
[email protected]5f450e52009-07-28 13:28:111606 // Must be a top level frame.
[email protected]dd7daa82009-08-10 05:46:451607 frame->parent() == NULL) {
[email protected]5f450e52009-07-28 13:28:111608 // Skip if navigation is on the same page (using '#').
[email protected]dd7daa82009-08-10 05:46:451609 GURL frame_origin = GURL(frame->url()).GetOrigin();
[email protected]5f450e52009-07-28 13:28:111610 if (url.GetOrigin() != frame_origin || url.ref().empty()) {
1611 last_top_level_navigation_page_id_ = page_id_;
1612 OpenURL(webview, url, GURL(), default_policy);
1613 return WebKit::WebNavigationPolicyIgnore; // Suppress the load here.
1614 }
1615 }
1616
[email protected]daa8c58e2009-06-15 17:21:101617 // A content initiated navigation may have originated from a link-click,
1618 // script, drag-n-drop operation, etc.
[email protected]77f17a82009-05-21 04:42:541619 bool is_content_initiated =
[email protected]dd7daa82009-08-10 05:46:451620 NavigationState::FromDataSource(frame->provisionalDataSource())->
[email protected]daa8c58e2009-06-15 17:21:101621 is_content_initiated();
[email protected]77f17a82009-05-21 04:42:541622
initial.commit09911bf2008-07-26 23:55:291623 // We only care about navigations that are within the current tab (as opposed
1624 // to, for example, opening a new window).
1625 // But we sometimes navigate to about:blank to clear a tab, and we want to
1626 // still allow that.
[email protected]4873c7d2009-07-16 06:36:281627 if (default_policy == WebKit::WebNavigationPolicyCurrentTab &&
[email protected]dd7daa82009-08-10 05:46:451628 is_content_initiated && frame->parent() == NULL &&
[email protected]4873c7d2009-07-16 06:36:281629 !url.SchemeIs(chrome::kAboutScheme)) {
[email protected]77f17a82009-05-21 04:42:541630 // When we received such unsolicited navigations, we sometimes want to
1631 // punt them up to the browser to handle.
1632 if (BindingsPolicy::is_dom_ui_enabled(enabled_bindings_) ||
[email protected]1e5f53a2009-06-15 23:48:041633 BindingsPolicy::is_extension_enabled(enabled_bindings_) ||
[email protected]dd7daa82009-08-10 05:46:451634 frame->isViewSourceModeEnabled() ||
[email protected]a2176742009-07-03 12:13:481635 url.SchemeIs(chrome::kViewSourceScheme) ||
1636 url.SchemeIs(chrome::kPrintScheme)) {
[email protected]4873c7d2009-07-16 06:36:281637 OpenURL(webview, url, GURL(), default_policy);
1638 return WebKit::WebNavigationPolicyIgnore; // Suppress the load here.
initial.commit09911bf2008-07-26 23:55:291639 }
1640 }
1641
1642 // Detect when a page is "forking" a new tab that can be safely rendered in
1643 // its own process. This is done by sites like Gmail that try to open links
1644 // in new windows without script connections back to the original page. We
1645 // treat such cases as browser navigations (in which we will create a new
1646 // renderer for a cross-site navigation), rather than WebKit navigations.
1647 //
1648 // We use the following heuristic to decide whether to fork a new page in its
1649 // own process:
1650 // The parent page must open a new tab to about:blank, set the new tab's
1651 // window.opener to null, and then redirect the tab to a cross-site URL using
1652 // JavaScript.
1653 bool is_fork =
1654 // Must start from a tab showing about:blank, which is later redirected.
[email protected]dd7daa82009-08-10 05:46:451655 GURL(frame->url()) == GURL("about:blank") &&
initial.commit09911bf2008-07-26 23:55:291656 // Must be the first real navigation of the tab.
1657 GetHistoryBackListCount() < 1 &&
1658 GetHistoryForwardListCount() < 1 &&
1659 // The parent page must have set the child's window.opener to null before
1660 // redirecting to the desired URL.
[email protected]dd7daa82009-08-10 05:46:451661 frame->opener() == NULL &&
initial.commit09911bf2008-07-26 23:55:291662 // Must be a top-level frame.
[email protected]dd7daa82009-08-10 05:46:451663 frame->parent() == NULL &&
[email protected]77f17a82009-05-21 04:42:541664 // Must not have issued the request from this page.
1665 is_content_initiated &&
initial.commit09911bf2008-07-26 23:55:291666 // Must be targeted at the current tab.
[email protected]4873c7d2009-07-16 06:36:281667 default_policy == WebKit::WebNavigationPolicyCurrentTab &&
initial.commit09911bf2008-07-26 23:55:291668 // Must be a JavaScript navigation, which appears as "other".
[email protected]726985e22009-06-18 21:09:281669 type == WebKit::WebNavigationTypeOther;
initial.commit09911bf2008-07-26 23:55:291670 if (is_fork) {
1671 // Open the URL via the browser, not via WebKit.
[email protected]4873c7d2009-07-16 06:36:281672 OpenURL(webview, url, GURL(), default_policy);
1673 return WebKit::WebNavigationPolicyIgnore;
initial.commit09911bf2008-07-26 23:55:291674 }
1675
[email protected]4873c7d2009-07-16 06:36:281676 return default_policy;
initial.commit09911bf2008-07-26 23:55:291677}
1678
[email protected]a455d3812009-03-05 20:18:071679void RenderView::RunJavaScriptAlert(WebFrame* webframe,
initial.commit09911bf2008-07-26 23:55:291680 const std::wstring& message) {
[email protected]478ff2ed2009-04-21 23:49:181681 RunJavaScriptMessage(MessageBoxFlags::kIsJavascriptAlert,
initial.commit09911bf2008-07-26 23:55:291682 message,
1683 std::wstring(),
[email protected]dd7daa82009-08-10 05:46:451684 webframe->url(),
initial.commit09911bf2008-07-26 23:55:291685 NULL);
1686}
1687
[email protected]a455d3812009-03-05 20:18:071688bool RenderView::RunJavaScriptConfirm(WebFrame* webframe,
initial.commit09911bf2008-07-26 23:55:291689 const std::wstring& message) {
[email protected]478ff2ed2009-04-21 23:49:181690 return RunJavaScriptMessage(MessageBoxFlags::kIsJavascriptConfirm,
initial.commit09911bf2008-07-26 23:55:291691 message,
1692 std::wstring(),
[email protected]dd7daa82009-08-10 05:46:451693 webframe->url(),
initial.commit09911bf2008-07-26 23:55:291694 NULL);
1695}
1696
[email protected]a455d3812009-03-05 20:18:071697bool RenderView::RunJavaScriptPrompt(WebFrame* webframe,
initial.commit09911bf2008-07-26 23:55:291698 const std::wstring& message,
1699 const std::wstring& default_value,
1700 std::wstring* result) {
[email protected]478ff2ed2009-04-21 23:49:181701 return RunJavaScriptMessage(MessageBoxFlags::kIsJavascriptPrompt,
initial.commit09911bf2008-07-26 23:55:291702 message,
1703 default_value,
[email protected]dd7daa82009-08-10 05:46:451704 webframe->url(),
initial.commit09911bf2008-07-26 23:55:291705 result);
1706}
1707
1708bool RenderView::RunJavaScriptMessage(int type,
1709 const std::wstring& message,
1710 const std::wstring& default_value,
[email protected]a455d3812009-03-05 20:18:071711 const GURL& frame_url,
initial.commit09911bf2008-07-26 23:55:291712 std::wstring* result) {
1713 bool success = false;
1714 std::wstring result_temp;
1715 if (!result)
1716 result = &result_temp;
1717 IPC::SyncMessage* msg = new ViewHostMsg_RunJavaScriptMessage(
[email protected]a455d3812009-03-05 20:18:071718 routing_id_, message, default_value, frame_url, type, &success, result);
initial.commit09911bf2008-07-26 23:55:291719
[email protected]1c4947f2009-01-15 22:25:111720 msg->set_pump_messages_event(modal_dialog_event_.get());
initial.commit09911bf2008-07-26 23:55:291721 Send(msg);
1722
1723 return success;
1724}
1725
1726void RenderView::AddGURLSearchProvider(const GURL& osd_url, bool autodetected) {
1727 if (!osd_url.is_empty())
1728 Send(new ViewHostMsg_PageHasOSDD(routing_id_, page_id_, osd_url,
1729 autodetected));
1730}
1731
[email protected]a455d3812009-03-05 20:18:071732bool RenderView::RunBeforeUnloadConfirm(WebFrame* webframe,
initial.commit09911bf2008-07-26 23:55:291733 const std::wstring& message) {
1734 bool success = false;
1735 // This is an ignored return value, but is included so we can accept the same
1736 // response as RunJavaScriptMessage.
1737 std::wstring ignored_result;
1738 IPC::SyncMessage* msg = new ViewHostMsg_RunBeforeUnloadConfirm(
[email protected]dd7daa82009-08-10 05:46:451739 routing_id_, webframe->url(), message, &success, &ignored_result);
initial.commit09911bf2008-07-26 23:55:291740
[email protected]1c4947f2009-01-15 22:25:111741 msg->set_pump_messages_event(modal_dialog_event_.get());
initial.commit09911bf2008-07-26 23:55:291742 Send(msg);
1743
1744 return success;
1745}
1746
[email protected]0ebf3872008-11-07 21:35:031747void RenderView::QueryFormFieldAutofill(const std::wstring& field_name,
1748 const std::wstring& text,
1749 int64 node_id) {
1750 static int message_id_counter = 0;
1751 form_field_autofill_request_id_ = message_id_counter++;
1752 Send(new ViewHostMsg_QueryFormFieldAutofill(routing_id_,
1753 field_name, text,
1754 node_id,
1755 form_field_autofill_request_id_));
1756}
1757
[email protected]4d2b6fb2009-03-20 22:28:171758void RenderView::RemoveStoredAutofillEntry(const std::wstring& name,
1759 const std::wstring& value) {
1760 Send(new ViewHostMsg_RemoveAutofillEntry(routing_id_, name, value));
1761}
1762
[email protected]0ebf3872008-11-07 21:35:031763void RenderView::OnReceivedAutofillSuggestions(
1764 int64 node_id,
1765 int request_id,
[email protected]8d0f15c2008-11-11 01:01:091766 const std::vector<std::wstring>& suggestions,
[email protected]0ebf3872008-11-07 21:35:031767 int default_suggestion_index) {
1768 if (!webview() || request_id != form_field_autofill_request_id_)
1769 return;
1770
1771 webview()->AutofillSuggestionsForNode(node_id, suggestions,
1772 default_suggestion_index);
1773}
1774
[email protected]2c4410d2009-05-06 23:46:221775void RenderView::OnPopupNotificationVisibilityChanged(bool visible) {
[email protected]634a6f92008-12-01 21:39:311776 popup_notification_visible_ = visible;
1777}
1778
initial.commit09911bf2008-07-26 23:55:291779void RenderView::ShowModalHTMLDialog(const GURL& url, int width, int height,
1780 const std::string& json_arguments,
1781 std::string* json_retval) {
1782 IPC::SyncMessage* msg = new ViewHostMsg_ShowModalHTMLDialog(
1783 routing_id_, url, width, height, json_arguments, json_retval);
1784
[email protected]1c4947f2009-01-15 22:25:111785 msg->set_pump_messages_event(modal_dialog_event_.get());
initial.commit09911bf2008-07-26 23:55:291786 Send(msg);
1787}
1788
1789uint32 RenderView::GetCPBrowsingContext() {
1790 uint32 context = 0;
1791 Send(new ViewHostMsg_GetCPBrowsingContext(&context));
1792 return context;
1793}
1794
1795// Tell the browser to display a destination link.
1796void RenderView::UpdateTargetURL(WebView* webview, const GURL& url) {
1797 if (url != target_url_) {
1798 if (target_url_status_ == TARGET_INFLIGHT ||
1799 target_url_status_ == TARGET_PENDING) {
1800 // If we have a request in-flight, save the URL to be sent when we
1801 // receive an ACK to the in-flight request. We can happily overwrite
1802 // any existing pending sends.
1803 pending_target_url_ = url;
1804 target_url_status_ = TARGET_PENDING;
1805 } else {
1806 Send(new ViewHostMsg_UpdateTargetURL(routing_id_, page_id_, url));
1807 target_url_ = url;
1808 target_url_status_ = TARGET_INFLIGHT;
1809 }
1810 }
1811}
1812
[email protected]b62d1a8c2009-01-13 23:54:571813void RenderView::RunFileChooser(bool multi_select,
[email protected]b949f1112009-04-12 20:03:081814 const string16& title,
1815 const FilePath& default_filename,
initial.commit09911bf2008-07-26 23:55:291816 WebFileChooserCallback* file_chooser) {
1817 if (file_chooser_.get()) {
1818 // TODO(brettw): bug 1235154: This should be a synchronous message to deal
1819 // with the fact that web pages can programatically trigger this. With the
1820 // asnychronous messages, we can get an additional call when one is pending,
1821 // which this test is for. For now, we just ignore the additional file
1822 // chooser request. WebKit doesn't do anything to expect the callback, so
1823 // we can just ignore calling it.
1824 delete file_chooser;
1825 return;
1826 }
1827 file_chooser_.reset(file_chooser);
[email protected]b62d1a8c2009-01-13 23:54:571828 Send(new ViewHostMsg_RunFileChooser(routing_id_, multi_select, title,
[email protected]b949f1112009-04-12 20:03:081829 default_filename));
initial.commit09911bf2008-07-26 23:55:291830}
1831
1832void RenderView::AddMessageToConsole(WebView* webview,
1833 const std::wstring& message,
1834 unsigned int line_no,
1835 const std::wstring& source_id) {
1836 Send(new ViewHostMsg_AddMessageToConsole(routing_id_, message,
1837 static_cast<int32>(line_no),
1838 source_id));
1839}
1840
1841void RenderView::AddSearchProvider(const std::string& url) {
1842 AddGURLSearchProvider(GURL(url),
1843 false); // not autodetected
1844}
1845
[email protected]c88a70fe2009-05-05 20:00:221846WebView* RenderView::CreateWebView(WebView* webview,
1847 bool user_gesture,
1848 const GURL& creator_url) {
[email protected]0aa55312008-10-17 21:53:081849 // Check to make sure we aren't overloading on popups.
1850 if (shared_popup_counter_->data > kMaximumNumberOfUnacknowledgedPopups)
1851 return NULL;
1852
[email protected]634a6f92008-12-01 21:39:311853 // This window can't be closed from a window.close() call until we receive a
1854 // message from the Browser process explicitly allowing it.
1855 popup_notification_visible_ = true;
1856
initial.commit09911bf2008-07-26 23:55:291857 int32 routing_id = MSG_ROUTING_NONE;
[email protected]6c8afae52009-01-22 02:24:571858
[email protected]18bcc3c2009-01-27 21:39:151859 ModalDialogEvent modal_dialog_event;
[email protected]6c8afae52009-01-22 02:24:571860 render_thread_->Send(
[email protected]15787f8f2008-10-17 15:29:031861 new ViewHostMsg_CreateWindow(routing_id_, user_gesture, &routing_id,
1862 &modal_dialog_event));
initial.commit09911bf2008-07-26 23:55:291863 if (routing_id == MSG_ROUTING_NONE) {
initial.commit09911bf2008-07-26 23:55:291864 return NULL;
1865 }
1866
1867 // The WebView holds a reference to this new RenderView
[email protected]80d96fa2009-06-10 22:34:511868 const WebPreferences& web_prefs = webview->GetPreferences();
[email protected]6c8afae52009-01-22 02:24:571869 base::WaitableEvent* waitable_event = new base::WaitableEvent
1870#if defined(OS_WIN)
[email protected]18bcc3c2009-01-27 21:39:151871 (modal_dialog_event.event);
[email protected]6c8afae52009-01-22 02:24:571872#else
1873 (true, false);
1874#endif
[email protected]81a34412009-01-05 19:17:241875 RenderView* view = RenderView::Create(render_thread_,
[email protected]1c4947f2009-01-15 22:25:111876 NULL, waitable_event, routing_id_,
[email protected]80d96fa2009-06-10 22:34:511877 renderer_preferences_, web_prefs,
1878 shared_popup_counter_, routing_id);
[email protected]ed4bf2d2009-05-05 00:10:061879 view->opened_by_user_gesture_ = user_gesture;
[email protected]c88a70fe2009-05-05 20:00:221880 view->creator_url_ = creator_url;
initial.commit09911bf2008-07-26 23:55:291881
1882 // Copy over the alternate error page URL so we can have alt error pages in
1883 // the new render view (we don't need the browser to send the URL back down).
1884 view->alternate_error_page_url_ = alternate_error_page_url_;
1885
1886 return view->webview();
1887}
1888
[email protected]0ebf3872008-11-07 21:35:031889WebWidget* RenderView::CreatePopupWidget(WebView* webview,
[email protected]cfd727f2009-01-09 20:21:111890 bool activatable) {
[email protected]8085dbc82008-09-26 22:53:441891 RenderWidget* widget = RenderWidget::Create(routing_id_,
[email protected]81a34412009-01-05 19:17:241892 render_thread_,
[email protected]cfd727f2009-01-09 20:21:111893 activatable);
initial.commit09911bf2008-07-26 23:55:291894 return widget->webwidget();
1895}
1896
[email protected]88efb7ec2009-07-14 16:32:591897WebWidget* RenderView::CreatePopupWidgetWithInfo(WebView* webview,
1898 const WebPopupMenuInfo& info) {
1899 RenderWidget* widget = RenderWidget::Create(routing_id_,
1900 render_thread_,
1901 true);
1902 widget->ConfigureAsExternalPopupMenu(info);
1903 return widget->webwidget();
1904}
1905
initial.commit09911bf2008-07-26 23:55:291906WebPluginDelegate* RenderView::CreatePluginDelegate(
1907 WebView* webview,
1908 const GURL& url,
1909 const std::string& mime_type,
1910 const std::string& clsid,
1911 std::string* actual_mime_type) {
[email protected]6273e2e72009-04-17 00:13:551912 if (!PluginChannelHost::IsListening())
1913 return NULL;
1914
[email protected]9dd9e8382009-06-05 18:23:211915 GURL policy_url;
1916 if (webview->GetMainFrame())
[email protected]dd7daa82009-08-10 05:46:451917 policy_url = webview->GetMainFrame()->url();
[email protected]9dd9e8382009-06-05 18:23:211918
[email protected]f5cdaff2009-05-19 21:01:471919 FilePath path;
1920 render_thread_->Send(
[email protected]9dd9e8382009-06-05 18:23:211921 new ViewHostMsg_GetPluginPath(url, policy_url, mime_type, clsid, &path,
[email protected]f5cdaff2009-05-19 21:01:471922 actual_mime_type));
1923 if (path.value().empty())
1924 return NULL;
1925
1926 std::string mime_type_to_use;
1927 if (!actual_mime_type->empty())
1928 mime_type_to_use = *actual_mime_type;
1929 else
1930 mime_type_to_use = mime_type;
1931
[email protected]88a1fb47a2009-03-13 00:18:061932 if (RenderProcess::current()->in_process_plugins()) {
[email protected]6bf1a812009-07-11 01:57:281933#if defined(OS_WIN) // In-proc plugins aren't supported on Linux or Mac.
[email protected]b94d3322009-02-12 19:49:041934 return WebPluginDelegate::Create(path,
1935 mime_type_to_use,
1936 gfx::NativeViewFromId(host_window_));
[email protected]6bf1a812009-07-11 01:57:281937#else
1938 NOTIMPLEMENTED();
1939 return NULL;
[email protected]ffeba6d2009-04-27 20:43:261940#endif
[email protected]6bf1a812009-07-11 01:57:281941 }
initial.commit09911bf2008-07-26 23:55:291942
1943 WebPluginDelegateProxy* proxy =
[email protected]f5cdaff2009-05-19 21:01:471944 WebPluginDelegateProxy::Create(url, mime_type_to_use, clsid, this);
initial.commit09911bf2008-07-26 23:55:291945 if (!proxy)
1946 return NULL;
1947
initial.commit09911bf2008-07-26 23:55:291948 plugin_delegates_.push_back(proxy);
1949
1950 return proxy;
1951}
1952
[email protected]4e6be3f2009-05-07 02:24:441953WebKit::WebMediaPlayer* RenderView::CreateWebMediaPlayer(
1954 WebKit::WebMediaPlayerClient* client) {
[email protected]add51772009-06-11 18:25:171955 scoped_refptr<media::FilterFactoryCollection> factory =
1956 new media::FilterFactoryCollection();
1957 // Add in any custom filter factories first.
1958 const CommandLine* cmd_line = CommandLine::ForCurrentProcess();
1959 if (!cmd_line->HasSwitch(switches::kDisableAudio)) {
1960 // Add the chrome specific audio renderer.
1961 factory->AddFactory(
1962 AudioRendererImpl::CreateFactory(audio_message_filter()));
1963 }
[email protected]8380c092009-06-25 17:45:511964
1965 // TODO(hclam): obtain the following parameters from |client|.
1966 webkit_glue::MediaResourceLoaderBridgeFactory* bridge_factory =
1967 new webkit_glue::MediaResourceLoaderBridgeFactory(
1968 GURL::EmptyGURL(), // referrer
1969 "null", // frame origin
1970 "null", // main_frame_origin
1971 base::GetCurrentProcId(),
1972 WebAppCacheContext::kNoAppCacheContextId,
1973 routing_id());
1974
[email protected]add51772009-06-11 18:25:171975 if (!cmd_line->HasSwitch(switches::kSimpleDataSource)) {
1976 // Add the chrome specific media data source.
[email protected]70ab61c92009-06-16 19:29:391977 factory->AddFactory(
[email protected]8e296bbd2009-07-22 21:37:171978 webkit_glue::BufferedDataSource::CreateFactory(MessageLoop::current(),
1979 bridge_factory));
[email protected]8380c092009-06-25 17:45:511980 } else {
1981 factory->AddFactory(
1982 webkit_glue::SimpleDataSource::CreateFactory(MessageLoop::current(),
1983 bridge_factory));
[email protected]add51772009-06-11 18:25:171984 }
1985 return new webkit_glue::WebMediaPlayerImpl(client, factory);
[email protected]ec9212f2008-12-18 21:40:361986}
1987
initial.commit09911bf2008-07-26 23:55:291988void RenderView::OnMissingPluginStatus(WebPluginDelegate* delegate,
1989 int status) {
[email protected]6c8afae52009-01-22 02:24:571990#if defined(OS_WIN)
initial.commit09911bf2008-07-26 23:55:291991 if (first_default_plugin_ == NULL) {
1992 // Show the InfoBar for the first available plugin.
1993 if (status == default_plugin::MISSING_PLUGIN_AVAILABLE) {
1994 first_default_plugin_ = delegate;
1995 Send(new ViewHostMsg_MissingPluginStatus(routing_id_, status));
1996 }
1997 } else {
1998 // Closes the InfoBar if user clicks on the plugin (instead of the InfoBar)
1999 // to start the download/install.
2000 if (status == default_plugin::MISSING_PLUGIN_USER_STARTED_DOWNLOAD) {
2001 Send(new ViewHostMsg_MissingPluginStatus(routing_id_, status));
2002 }
2003 }
[email protected]6c8afae52009-01-22 02:24:572004#else
2005 // TODO(port): plugins current not supported
2006 NOTIMPLEMENTED();
2007#endif
initial.commit09911bf2008-07-26 23:55:292008}
2009
[email protected]eb47a132009-03-04 00:39:562010WebWorker* RenderView::CreateWebWorker(WebWorkerClient* client) {
[email protected]ec775ef2009-05-01 21:20:472011 return new WebWorkerProxy(client, RenderThread::current(), routing_id_);
[email protected]eb47a132009-03-04 00:39:562012}
2013
initial.commit09911bf2008-07-26 23:55:292014void RenderView::OpenURL(WebView* webview, const GURL& url,
[email protected]c0588052008-10-27 23:01:502015 const GURL& referrer,
[email protected]4873c7d2009-07-16 06:36:282016 WebNavigationPolicy policy) {
2017 Send(new ViewHostMsg_OpenURL(
2018 routing_id_, url, referrer, NavigationPolicyToDisposition(policy)));
initial.commit09911bf2008-07-26 23:55:292019}
2020
[email protected]1d522202009-04-04 01:56:422021void RenderView::DidContentsSizeChange(WebWidget* webwidget,
2022 int new_width,
2023 int new_height) {
[email protected]0666aef2009-05-13 19:48:082024 // We don't always want to send the change messages over IPC, only if we've
2025 // be put in that mode by getting a |ViewMsg_EnableIntrinsicWidthChangedMode|
2026 // message.
2027 // TODO(rafaelw): Figure out where the best place to set this for extensions
2028 // is. It isn't clean to test for ExtensionView by examining the
2029 // enabled_bindings. This needs to be generalized as it becomes clear what
2030 // extension toolbars need.
2031 if (BindingsPolicy::is_extension_enabled(enabled_bindings_) ||
2032 send_preferred_width_changes_) {
2033 // WebCore likes to tell us things have changed even when they haven't, so
2034 // cache the width and only send the IPC message when we're sure the
2035 // width is different.
[email protected]dd7daa82009-08-10 05:46:452036 int width = webview()->GetMainFrame()->contentsPreferredWidth();
[email protected]0666aef2009-05-13 19:48:082037 if (width != preferred_width_) {
2038 Send(new ViewHostMsg_DidContentsPreferredWidthChange(routing_id_, width));
2039 preferred_width_ = width;
2040 }
[email protected]1d522202009-04-04 01:56:422041 }
2042}
2043
initial.commit09911bf2008-07-26 23:55:292044// We are supposed to get a single call to Show for a newly created RenderView
2045// that was created via RenderView::CreateWebView. So, we wait until this
2046// point to dispatch the ShowView message.
2047//
2048// This method provides us with the information about how to display the newly
2049// created RenderView (i.e., as a constrained popup or as a new tab).
2050//
[email protected]4873c7d2009-07-16 06:36:282051void RenderView::show(WebNavigationPolicy policy) {
initial.commit09911bf2008-07-26 23:55:292052 DCHECK(!did_show_) << "received extraneous Show call";
2053 DCHECK(opener_id_ != MSG_ROUTING_NONE);
2054
2055 if (did_show_)
2056 return;
2057 did_show_ = true;
2058
2059 // NOTE: initial_pos_ may still have its default values at this point, but
2060 // that's okay. It'll be ignored if disposition is not NEW_POPUP, or the
2061 // browser process will impose a default position otherwise.
[email protected]4873c7d2009-07-16 06:36:282062 Send(new ViewHostMsg_ShowView(opener_id_, routing_id_,
2063 NavigationPolicyToDisposition(policy), initial_pos_,
2064 opened_by_user_gesture_, creator_url_));
[email protected]2533ce12009-05-09 00:02:242065 SetPendingWindowRect(initial_pos_);
initial.commit09911bf2008-07-26 23:55:292066}
2067
[email protected]4873c7d2009-07-16 06:36:282068void RenderView::closeWidgetSoon() {
[email protected]2c4410d2009-05-06 23:46:222069 if (!popup_notification_visible_)
[email protected]4873c7d2009-07-16 06:36:282070 RenderWidget::closeWidgetSoon();
[email protected]634a6f92008-12-01 21:39:312071}
2072
[email protected]4873c7d2009-07-16 06:36:282073void RenderView::runModal() {
initial.commit09911bf2008-07-26 23:55:292074 DCHECK(did_show_) << "should already have shown the view";
2075
2076 IPC::SyncMessage* msg = new ViewHostMsg_RunModal(routing_id_);
2077
[email protected]1c4947f2009-01-15 22:25:112078 msg->set_pump_messages_event(modal_dialog_event_.get());
initial.commit09911bf2008-07-26 23:55:292079 Send(msg);
2080}
2081
2082void RenderView::SyncNavigationState() {
2083 if (!webview())
2084 return;
2085
[email protected]dd7daa82009-08-10 05:46:452086 const WebHistoryItem& item = webview()->GetMainFrame()->currentHistoryItem();
[email protected]ca948a22009-06-25 19:36:172087 if (item.isNull())
initial.commit09911bf2008-07-26 23:55:292088 return;
[email protected]ca948a22009-06-25 19:36:172089
2090 Send(new ViewHostMsg_UpdateState(
2091 routing_id_, page_id_, webkit_glue::HistoryItemToString(item)));
initial.commit09911bf2008-07-26 23:55:292092}
2093
2094void RenderView::ShowContextMenu(WebView* webview,
[email protected]581b87eb2009-07-23 23:06:562095 ContextNodeType node_type,
initial.commit09911bf2008-07-26 23:55:292096 int x,
2097 int y,
2098 const GURL& link_url,
[email protected]574a1d62009-07-17 03:23:462099 const GURL& src_url,
initial.commit09911bf2008-07-26 23:55:292100 const GURL& page_url,
2101 const GURL& frame_url,
[email protected]574a1d62009-07-17 03:23:462102 const ContextMenuMediaParams& media_params,
initial.commit09911bf2008-07-26 23:55:292103 const std::wstring& selection_text,
2104 const std::wstring& misspelled_word,
[email protected]6aa376b2008-09-23 18:49:522105 int edit_flags,
[email protected]c9825a42009-05-01 22:51:502106 const std::string& security_info,
2107 const std::string& frame_charset) {
[email protected]e09ba552009-02-05 03:26:292108 ContextMenuParams params;
[email protected]581b87eb2009-07-23 23:06:562109 params.node_type = node_type;
initial.commit09911bf2008-07-26 23:55:292110 params.x = x;
2111 params.y = y;
[email protected]574a1d62009-07-17 03:23:462112 params.src_url = src_url;
initial.commit09911bf2008-07-26 23:55:292113 params.link_url = link_url;
[email protected]e6c79812009-04-22 22:31:422114 params.unfiltered_link_url = link_url;
initial.commit09911bf2008-07-26 23:55:292115 params.page_url = page_url;
2116 params.frame_url = frame_url;
[email protected]574a1d62009-07-17 03:23:462117 params.media_params = media_params;
initial.commit09911bf2008-07-26 23:55:292118 params.selection_text = selection_text;
2119 params.misspelled_word = misspelled_word;
[email protected]be645db2009-02-06 20:36:332120 params.spellcheck_enabled =
[email protected]dd7daa82009-08-10 05:46:452121 webview->GetFocusedFrame()->isContinuousSpellCheckingEnabled();
initial.commit09911bf2008-07-26 23:55:292122 params.edit_flags = edit_flags;
[email protected]6aa376b2008-09-23 18:49:522123 params.security_info = security_info;
[email protected]c9825a42009-05-01 22:51:502124 params.frame_charset = frame_charset;
initial.commit09911bf2008-07-26 23:55:292125 Send(new ViewHostMsg_ContextMenu(routing_id_, params));
2126}
2127
[email protected]e80c73b2009-04-07 23:24:582128void RenderView::StartDragging(WebView* webview,
2129 const WebDragData& drag_data) {
2130 Send(new ViewHostMsg_StartDragging(routing_id_, WebDropData(drag_data)));
initial.commit09911bf2008-07-26 23:55:292131}
2132
2133void RenderView::TakeFocus(WebView* webview, bool reverse) {
2134 Send(new ViewHostMsg_TakeFocus(routing_id_, reverse));
2135}
2136
2137void RenderView::DidDownloadImage(int id,
2138 const GURL& image_url,
2139 bool errored,
2140 const SkBitmap& image) {
[email protected]bf5c2ff392009-07-08 16:24:332141 Send(new ViewHostMsg_DidDownloadFavIcon(routing_id_, id, image_url, errored,
2142 image));
initial.commit09911bf2008-07-26 23:55:292143}
2144
[email protected]bf5c2ff392009-07-08 16:24:332145void RenderView::OnDownloadFavIcon(int id,
2146 const GURL& image_url,
2147 int image_size) {
[email protected]f11ca0732009-04-11 00:09:342148 bool data_image_failed = false;
2149 if (image_url.SchemeIs("data")) {
2150 SkBitmap data_image = ImageFromDataUrl(image_url);
2151 data_image_failed = data_image.empty();
2152 if (!data_image_failed) {
[email protected]bf5c2ff392009-07-08 16:24:332153 Send(new ViewHostMsg_DidDownloadFavIcon(routing_id_, id, image_url, false,
2154 data_image));
[email protected]f11ca0732009-04-11 00:09:342155 }
2156 }
2157
[email protected]bf5c2ff392009-07-08 16:24:332158 if (data_image_failed ||
2159 !webview()->DownloadImage(id, image_url, image_size)) {
2160 Send(new ViewHostMsg_DidDownloadFavIcon(routing_id_, id, image_url, true,
2161 SkBitmap()));
2162 }
initial.commit09911bf2008-07-26 23:55:292163}
2164
[email protected]f11ca0732009-04-11 00:09:342165SkBitmap RenderView::ImageFromDataUrl(const GURL& url) const {
2166 std::string mime_type, char_set, data;
2167 if (net::DataURL::Parse(url, &mime_type, &char_set, &data) && !data.empty()) {
2168 // Decode the favicon using WebKit's image decoder.
2169 webkit_glue::ImageDecoder decoder(gfx::Size(kFavIconSize, kFavIconSize));
2170 const unsigned char* src_data =
2171 reinterpret_cast<const unsigned char*>(&data[0]);
2172
2173 return decoder.Decode(src_data, data.size());
2174 }
2175 return SkBitmap();
2176}
2177
initial.commit09911bf2008-07-26 23:55:292178void RenderView::OnGetApplicationInfo(int page_id) {
2179 webkit_glue::WebApplicationInfo app_info;
2180 if (page_id == page_id_)
2181 webkit_glue::GetApplicationInfo(webview(), &app_info);
2182
2183 // Prune out any data URLs in the set of icons. The browser process expects
2184 // any icon with a data URL to have originated from a favicon. We don't want
2185 // to decode arbitrary data URLs in the browser process. See
2186 // http://b/issue?id=1162972
2187 for (size_t i = 0; i < app_info.icons.size(); ++i) {
[email protected]6de74452009-02-25 18:04:592188 if (app_info.icons[i].url.SchemeIs(chrome::kDataScheme)) {
initial.commit09911bf2008-07-26 23:55:292189 app_info.icons.erase(app_info.icons.begin() + i);
2190 --i;
2191 }
2192 }
2193
2194 Send(new ViewHostMsg_DidGetApplicationInfo(routing_id_, page_id, app_info));
2195}
2196
[email protected]7ccddb8c2009-08-04 17:36:552197GURL RenderView::GetAlternateErrorPageURL(const GURL& failed_url,
initial.commit09911bf2008-07-26 23:55:292198 ErrorPageType error_type) {
[email protected]7ccddb8c2009-08-04 17:36:552199 if (failed_url.SchemeIsSecure()) {
initial.commit09911bf2008-07-26 23:55:292200 // If the URL that failed was secure, then the embedding web page was not
2201 // expecting a network attacker to be able to manipulate its contents. As
2202 // we fetch alternate error pages over HTTP, we would be allowing a network
2203 // attacker to manipulate the contents of the response if we tried to use
2204 // the link doctor here.
2205 return GURL::EmptyGURL();
2206 }
2207
2208 // Grab the base URL from the browser process.
2209 if (!alternate_error_page_url_.is_valid())
2210 return GURL::EmptyGURL();
2211
2212 // Strip query params from the failed URL.
2213 GURL::Replacements remove_params;
2214 remove_params.ClearUsername();
2215 remove_params.ClearPassword();
2216 remove_params.ClearQuery();
2217 remove_params.ClearRef();
[email protected]7ccddb8c2009-08-04 17:36:552218 const GURL url_to_send = failed_url.ReplaceComponents(remove_params);
initial.commit09911bf2008-07-26 23:55:292219
2220 // Construct the query params to send to link doctor.
2221 std::string params(alternate_error_page_url_.query());
2222 params.append("&url=");
2223 params.append(EscapeQueryParamValue(url_to_send.spec()));
2224 params.append("&sourceid=chrome");
2225 params.append("&error=");
2226 switch (error_type) {
2227 case DNS_ERROR:
2228 params.append("dnserror");
2229 break;
2230
2231 case HTTP_404:
2232 params.append("http404");
2233 break;
2234
[email protected]5df266ac2008-10-15 19:50:132235 case CONNECTION_ERROR:
[email protected]e1f934b2009-01-26 20:41:332236 params.append("connectionfailure");
[email protected]5df266ac2008-10-15 19:50:132237 break;
2238
initial.commit09911bf2008-07-26 23:55:292239 default:
2240 NOTREACHED() << "unknown ErrorPageType";
2241 }
2242
2243 // OK, build the final url to return.
2244 GURL::Replacements link_doctor_params;
2245 link_doctor_params.SetQueryStr(params);
2246 GURL url = alternate_error_page_url_.ReplaceComponents(link_doctor_params);
2247 return url;
2248}
2249
[email protected]7ea066a2009-04-06 20:21:592250void RenderView::OnFind(int request_id,
2251 const string16& search_text,
2252 const WebKit::WebFindOptions& options) {
initial.commit09911bf2008-07-26 23:55:292253 WebFrame* main_frame = webview()->GetMainFrame();
2254 WebFrame* frame_after_main = webview()->GetNextFrameAfter(main_frame, true);
2255 WebFrame* focused_frame = webview()->GetFocusedFrame();
2256 WebFrame* search_frame = focused_frame; // start searching focused frame.
2257
2258 bool multi_frame = (frame_after_main != main_frame);
2259
2260 // If we have multiple frames, we don't want to wrap the search within the
2261 // frame, so we check here if we only have main_frame in the chain.
2262 bool wrap_within_frame = !multi_frame;
2263
[email protected]b3f2b912009-04-09 16:18:522264 WebRect selection_rect;
initial.commit09911bf2008-07-26 23:55:292265 bool result = false;
2266
2267 do {
[email protected]dd7daa82009-08-10 05:46:452268 result = search_frame->find(
[email protected]7ea066a2009-04-06 20:21:592269 request_id, search_text, options, wrap_within_frame, &selection_rect);
initial.commit09911bf2008-07-26 23:55:292270
2271 if (!result) {
2272 // don't leave text selected as you move to the next frame.
[email protected]dd7daa82009-08-10 05:46:452273 search_frame->clearSelection();
initial.commit09911bf2008-07-26 23:55:292274
2275 // Find the next frame, but skip the invisible ones.
2276 do {
2277 // What is the next frame to search? (we might be going backwards). Note
2278 // that we specify wrap=true so that search_frame never becomes NULL.
[email protected]7ea066a2009-04-06 20:21:592279 search_frame = options.forward ?
initial.commit09911bf2008-07-26 23:55:292280 webview()->GetNextFrameAfter(search_frame, true) :
2281 webview()->GetPreviousFrameBefore(search_frame, true);
[email protected]dd7daa82009-08-10 05:46:452282 } while (!search_frame->hasVisibleContent() &&
2283 search_frame != focused_frame);
initial.commit09911bf2008-07-26 23:55:292284
[email protected]884db412008-11-24 23:46:502285 // Make sure selection doesn't affect the search operation in new frame.
[email protected]dd7daa82009-08-10 05:46:452286 search_frame->clearSelection();
initial.commit09911bf2008-07-26 23:55:292287
2288 // If we have multiple frames and we have wrapped back around to the
2289 // focused frame, we need to search it once more allowing wrap within
2290 // the frame, otherwise it will report 'no match' if the focused frame has
2291 // reported matches, but no frames after the focused_frame contain a
2292 // match for the search word(s).
2293 if (multi_frame && search_frame == focused_frame) {
[email protected]dd7daa82009-08-10 05:46:452294 result = search_frame->find(
[email protected]7ea066a2009-04-06 20:21:592295 request_id, search_text, options, true, // Force wrapping.
2296 &selection_rect);
initial.commit09911bf2008-07-26 23:55:292297 }
2298 }
2299
initial.commit09911bf2008-07-26 23:55:292300 webview()->SetFocusedFrame(search_frame);
2301 } while (!result && search_frame != focused_frame);
2302
[email protected]7ea066a2009-04-06 20:21:592303 if (options.findNext) {
[email protected]4f3dc372009-02-24 00:10:292304 // Force the main_frame to report the actual count.
[email protected]dd7daa82009-08-10 05:46:452305 main_frame->increaseMatchCount(0, request_id);
[email protected]4f3dc372009-02-24 00:10:292306 } else {
2307 // If nothing is found, set result to "0 of 0", otherwise, set it to
2308 // "-1 of 1" to indicate that we found at least one item, but we don't know
2309 // yet what is active.
2310 int ordinal = result ? -1 : 0; // -1 here means, we might know more later.
2311 int match_count = result ? 1 : 0; // 1 here means possibly more coming.
initial.commit09911bf2008-07-26 23:55:292312
[email protected]4f3dc372009-02-24 00:10:292313 // If we find no matches then this will be our last status update.
2314 // Otherwise the scoping effort will send more results.
2315 bool final_status_update = !result;
initial.commit09911bf2008-07-26 23:55:292316
[email protected]4f3dc372009-02-24 00:10:292317 // Send the search result over to the browser process.
[email protected]4f999132009-03-31 18:08:402318 Send(new ViewHostMsg_Find_Reply(routing_id_,
[email protected]7ea066a2009-04-06 20:21:592319 request_id,
[email protected]4f3dc372009-02-24 00:10:292320 match_count,
2321 selection_rect,
2322 ordinal,
2323 final_status_update));
initial.commit09911bf2008-07-26 23:55:292324
initial.commit09911bf2008-07-26 23:55:292325 // Scoping effort begins, starting with the mainframe.
2326 search_frame = main_frame;
2327
[email protected]dd7daa82009-08-10 05:46:452328 main_frame->resetMatchCount();
initial.commit09911bf2008-07-26 23:55:292329
2330 do {
2331 // Cancel all old scoping requests before starting a new one.
[email protected]dd7daa82009-08-10 05:46:452332 search_frame->cancelPendingScopingEffort();
initial.commit09911bf2008-07-26 23:55:292333
2334 // We don't start another scoping effort unless at least one match has
2335 // been found.
2336 if (result) {
2337 // Start new scoping request. If the scoping function determines that it
2338 // needs to scope, it will defer until later.
[email protected]dd7daa82009-08-10 05:46:452339 search_frame->scopeStringMatches(request_id,
[email protected]7ea066a2009-04-06 20:21:592340 search_text,
2341 options,
initial.commit09911bf2008-07-26 23:55:292342 true); // reset the tickmarks
2343 }
2344
2345 // Iterate to the next frame. The frame will not necessarily scope, for
2346 // example if it is not visible.
2347 search_frame = webview()->GetNextFrameAfter(search_frame, true);
2348 } while (search_frame != main_frame);
2349 }
2350}
2351
[email protected]5c4266922009-07-10 16:41:272352void RenderView::OnDeterminePageText() {
2353 if (!is_loading_) {
2354 if (!webview())
2355 return;
2356 WebFrame* main_frame = webview()->GetMainFrame();
2357 std::wstring contents;
2358 CaptureText(main_frame, &contents);
2359 Send(new ViewMsg_DeterminePageText_Reply(routing_id_, contents));
2360 determine_page_text_after_loading_stops_ = false;
2361 return;
2362 }
2363
2364 // We set |determine_page_text_after_loading_stops_| true here so that,
2365 // after page has been loaded completely, the text in the page is captured.
2366 determine_page_text_after_loading_stops_ = true;
2367}
2368
initial.commit09911bf2008-07-26 23:55:292369void RenderView::ReportFindInPageMatchCount(int count, int request_id,
2370 bool final_update) {
2371 // If we have a message that has been queued up, then we should just replace
2372 // it. The ACK from the browser will make sure it gets sent when the browser
2373 // wants it.
2374 if (queued_find_reply_message_.get()) {
2375 IPC::Message* msg = new ViewHostMsg_Find_Reply(
2376 routing_id_,
2377 request_id,
2378 count,
[email protected]b3f2b912009-04-09 16:18:522379 gfx::Rect(),
initial.commit09911bf2008-07-26 23:55:292380 -1, // Don't update active match ordinal.
2381 final_update);
2382 queued_find_reply_message_.reset(msg);
2383 } else {
2384 // Send the search result over to the browser process.
2385 Send(new ViewHostMsg_Find_Reply(
2386 routing_id_,
2387 request_id,
2388 count,
[email protected]b3f2b912009-04-09 16:18:522389 gfx::Rect(),
initial.commit09911bf2008-07-26 23:55:292390 -1, // // Don't update active match ordinal.
2391 final_update));
2392 }
2393}
2394
2395void RenderView::ReportFindInPageSelection(int request_id,
2396 int active_match_ordinal,
[email protected]b3f2b912009-04-09 16:18:522397 const WebRect& selection_rect) {
initial.commit09911bf2008-07-26 23:55:292398 // Send the search result over to the browser process.
2399 Send(new ViewHostMsg_Find_Reply(routing_id_,
2400 request_id,
2401 -1,
2402 selection_rect,
2403 active_match_ordinal,
2404 false));
2405}
2406
[email protected]ed4bf2d2009-05-05 00:10:062407bool RenderView::WasOpenedByUserGesture() const {
initial.commit09911bf2008-07-26 23:55:292408 return opened_by_user_gesture_;
2409}
2410
[email protected]7f40fc5b2009-06-12 19:23:082411void RenderView::SpellCheck(const std::wstring& word, int* misspell_location,
2412 int* misspell_length) {
2413 Send(new ViewHostMsg_SpellCheck(routing_id_, word, misspell_location,
2414 misspell_length));
initial.commit09911bf2008-07-26 23:55:292415}
2416
[email protected]26ea6c42009-06-10 22:32:212417std::wstring RenderView::GetAutoCorrectWord(
2418 const std::wstring& misspelled_word) {
2419 std::wstring autocorrect_word;
[email protected]eda2b5a2009-05-12 19:30:212420 const CommandLine& command_line = *CommandLine::ForCurrentProcess();
2421 if (command_line.HasSwitch(switches::kAutoSpellCorrect)) {
2422 Send(new ViewHostMsg_GetAutoCorrectWord(routing_id_, misspelled_word,
2423 &autocorrect_word));
2424 }
[email protected]26ea6c42009-06-10 22:32:212425
2426 return autocorrect_word;
[email protected]eda2b5a2009-05-12 19:30:212427}
2428
initial.commit09911bf2008-07-26 23:55:292429void RenderView::SetInputMethodState(bool enabled) {
2430 // Save the updated IME status and mark the input focus has been updated.
2431 // The IME status is to be sent to a browser process next time when
2432 // the input caret is rendered.
[email protected]9f23f592008-11-17 08:36:342433 if (!ime_control_busy_) {
2434 ime_control_updated_ = true;
2435 ime_control_new_state_ = enabled;
2436 }
initial.commit09911bf2008-07-26 23:55:292437}
2438
2439void RenderView::ScriptedPrint(WebFrame* frame) {
[email protected]aa82249f2009-07-16 17:23:582440 DCHECK(webview());
2441 if (webview()) {
2442 // Print the full page - not just the frame the javascript is running from.
2443 Print(webview()->GetMainFrame(), true);
2444 }
initial.commit09911bf2008-07-26 23:55:292445}
2446
initial.commit09911bf2008-07-26 23:55:292447void RenderView::UserMetricsRecordAction(const std::wstring& action) {
2448 Send(new ViewHostMsg_UserMetricsRecordAction(routing_id_, action));
2449}
2450
2451void RenderView::DnsPrefetch(const std::vector<std::string>& host_names) {
2452 Send(new ViewHostMsg_DnsPrefetch(host_names));
2453}
2454
[email protected]630e26b2008-10-14 22:55:172455void RenderView::OnZoom(int function) {
2456 static const bool kZoomIsTextOnly = false;
2457 switch (function) {
2458 case PageZoom::SMALLER:
2459 webview()->ZoomOut(kZoomIsTextOnly);
initial.commit09911bf2008-07-26 23:55:292460 break;
[email protected]630e26b2008-10-14 22:55:172461 case PageZoom::STANDARD:
2462 webview()->ResetZoom();
initial.commit09911bf2008-07-26 23:55:292463 break;
[email protected]630e26b2008-10-14 22:55:172464 case PageZoom::LARGER:
2465 webview()->ZoomIn(kZoomIsTextOnly);
initial.commit09911bf2008-07-26 23:55:292466 break;
2467 default:
2468 NOTREACHED();
2469 }
2470}
2471
[email protected]ea8c7452009-04-02 20:47:062472void RenderView::OnInsertText(const string16& text) {
[email protected]5f9e0b82009-05-08 22:13:392473 WebFrame* frame = webview()->GetFocusedFrame();
2474 if (!frame)
2475 return;
[email protected]dd7daa82009-08-10 05:46:452476 frame->insertText(text);
[email protected]ea8c7452009-04-02 20:47:062477}
2478
[email protected]e38f40152008-09-12 23:08:302479void RenderView::OnSetPageEncoding(const std::wstring& encoding_name) {
initial.commit09911bf2008-07-26 23:55:292480 webview()->SetPageEncoding(encoding_name);
2481}
2482
[email protected]f6e59a62009-05-13 21:12:032483void RenderView::NavigateBackForwardSoon(int offset) {
[email protected]f46aff62008-10-16 07:58:052484 history_back_list_count_ += offset;
2485 history_forward_list_count_ -= offset;
2486
initial.commit09911bf2008-07-26 23:55:292487 Send(new ViewHostMsg_GoToEntryAtOffset(routing_id_, offset));
2488}
2489
2490int RenderView::GetHistoryBackListCount() {
2491 return history_back_list_count_;
2492}
2493
2494int RenderView::GetHistoryForwardListCount() {
2495 return history_forward_list_count_;
2496}
2497
2498void RenderView::OnNavStateChanged(WebView* webview) {
[email protected]81a34412009-01-05 19:17:242499 if (!nav_state_sync_timer_.IsRunning()) {
2500 nav_state_sync_timer_.Start(
2501 TimeDelta::FromSeconds(delay_seconds_for_form_state_sync_), this,
2502 &RenderView::SyncNavigationState);
2503 }
initial.commit09911bf2008-07-26 23:55:292504}
2505
2506void RenderView::SetTooltipText(WebView* webview,
[email protected]de570ef2009-07-29 18:27:522507 const std::wstring& tooltip_text,
2508 WebTextDirection text_direction_hint) {
2509 Send(new ViewHostMsg_SetTooltipText(routing_id_, tooltip_text,
2510 text_direction_hint));
initial.commit09911bf2008-07-26 23:55:292511}
2512
[email protected]2e417c82009-04-02 22:30:262513void RenderView::DidChangeSelection(bool is_empty_selection) {
2514#if defined(OS_LINUX)
[email protected]d5d7b8002009-05-18 21:20:542515 // TODO(estade): investigate incremental updates to the selection so that we
2516 // don't send the entire selection over IPC every time.
[email protected]2e417c82009-04-02 22:30:262517 if (!is_empty_selection) {
[email protected]d5d7b8002009-05-18 21:20:542518 // Sometimes we get repeated DidChangeSelection calls from webkit when
2519 // the selection hasn't actually changed. We don't want to report these
2520 // because it will cause us to continually claim the X clipboard.
2521 const std::string& this_selection =
[email protected]dd7daa82009-08-10 05:46:452522 webview()->GetFocusedFrame()->selectionAsText().utf8();
[email protected]d5d7b8002009-05-18 21:20:542523 if (this_selection == last_selection_)
2524 return;
2525
[email protected]dbadbcc2009-04-09 00:57:102526 Send(new ViewHostMsg_SelectionChanged(routing_id_,
[email protected]d5d7b8002009-05-18 21:20:542527 this_selection));
2528 last_selection_ = this_selection;
[email protected]4f61a022009-06-25 23:49:012529 } else {
2530 last_selection_.clear();
[email protected]2e417c82009-04-02 22:30:262531 }
2532#endif
2533}
2534
initial.commit09911bf2008-07-26 23:55:292535void RenderView::DownloadUrl(const GURL& url, const GURL& referrer) {
2536 Send(new ViewHostMsg_DownloadUrl(routing_id_, url, referrer));
2537}
2538
[email protected]0df30122009-06-03 12:13:082539void RenderView::UpdateInspectorSettings(const std::wstring& raw_settings) {
2540 Send(new ViewHostMsg_UpdateInspectorSettings(routing_id_, raw_settings));
2541}
2542
[email protected]611cad42009-03-16 18:51:342543WebDevToolsAgentDelegate* RenderView::GetWebDevToolsAgentDelegate() {
[email protected]b75b7d072009-04-06 13:47:002544 return devtools_agent_.get();
[email protected]611cad42009-03-16 18:51:342545}
2546
[email protected]ea8c7452009-04-02 20:47:062547void RenderView::PasteFromSelectionClipboard() {
2548 Send(new ViewHostMsg_PasteFromSelectionClipboard(routing_id_));
2549}
2550
[email protected]dd7daa82009-08-10 05:46:452551WebFrame* RenderView::GetChildFrame(const std::wstring& xpath) const {
2552 if (xpath.empty())
2553 return webview()->GetMainFrame();
2554
2555 // xpath string can represent a frame deep down the tree (across multiple
2556 // frame DOMs).
2557 // Example, /html/body/table/tbody/tr/td/iframe\n/frameset/frame[0]
2558 // should break into 2 xpaths
2559 // /html/body/table/tbody/tr/td/iframe & /frameset/frame[0]
2560
2561 WebFrame* frame = webview()->GetMainFrame();
2562
2563 std::wstring xpath_remaining = xpath;
2564 while (!xpath_remaining.empty()) {
2565 std::wstring::size_type delim_pos = xpath_remaining.find_first_of(L'\n');
2566 std::wstring xpath_child;
2567 if (delim_pos != std::wstring::npos) {
2568 xpath_child = xpath_remaining.substr(0, delim_pos);
2569 xpath_remaining.erase(0, delim_pos + 1);
2570 } else {
2571 xpath_remaining.swap(xpath_child);
2572 }
2573 frame = frame->findChildByExpression(WideToUTF16Hack(xpath_child));
initial.commit09911bf2008-07-26 23:55:292574 }
2575
[email protected]dd7daa82009-08-10 05:46:452576 return frame;
initial.commit09911bf2008-07-26 23:55:292577}
2578
[email protected]f29acf52008-11-03 20:08:332579void RenderView::EvaluateScript(const std::wstring& frame_xpath,
2580 const std::wstring& script) {
initial.commit09911bf2008-07-26 23:55:292581 WebFrame* web_frame = GetChildFrame(frame_xpath);
2582 if (!web_frame)
2583 return;
2584
[email protected]dd7daa82009-08-10 05:46:452585 web_frame->executeScript(WebScriptSource(WideToUTF16Hack(script)));
initial.commit09911bf2008-07-26 23:55:292586}
2587
[email protected]1810e132009-03-24 23:35:482588void RenderView::InsertCSS(const std::wstring& frame_xpath,
2589 const std::string& css) {
2590 WebFrame* web_frame = GetChildFrame(frame_xpath);
2591 if (!web_frame)
2592 return;
2593
[email protected]dd7daa82009-08-10 05:46:452594 web_frame->insertStyleText(WebString::fromUTF8(css));
[email protected]1810e132009-03-24 23:35:482595}
2596
initial.commit09911bf2008-07-26 23:55:292597void RenderView::OnScriptEvalRequest(const std::wstring& frame_xpath,
2598 const std::wstring& jscript) {
[email protected]f29acf52008-11-03 20:08:332599 EvaluateScript(frame_xpath, jscript);
initial.commit09911bf2008-07-26 23:55:292600}
2601
[email protected]1810e132009-03-24 23:35:482602void RenderView::OnCSSInsertRequest(const std::wstring& frame_xpath,
2603 const std::string& css) {
2604 InsertCSS(frame_xpath, css);
[email protected]ae461542009-06-19 19:03:412605
2606 // Notify RenderViewHost that css has been inserted into the frame.
2607 Send(new ViewHostMsg_OnCSSInserted(routing_id_));
[email protected]1810e132009-03-24 23:35:482608}
2609
[email protected]7ea066a2009-04-06 20:21:592610void RenderView::OnAddMessageToConsole(
2611 const string16& frame_xpath,
2612 const string16& message,
2613 const WebConsoleMessage::Level& level) {
2614 WebFrame* web_frame = GetChildFrame(UTF16ToWideHack(frame_xpath));
[email protected]0dea3ea2009-03-31 23:30:592615 if (web_frame)
[email protected]dd7daa82009-08-10 05:46:452616 web_frame->addMessageToConsole(WebConsoleMessage(level, message));
initial.commit09911bf2008-07-26 23:55:292617}
2618
[email protected]81e63782009-02-27 19:35:092619void RenderView::OnAllowBindings(int enabled_bindings_flags) {
2620 enabled_bindings_ |= enabled_bindings_flags;
initial.commit09911bf2008-07-26 23:55:292621}
2622
2623void RenderView::OnSetDOMUIProperty(const std::string& name,
2624 const std::string& value) {
[email protected]81e63782009-02-27 19:35:092625 DCHECK(BindingsPolicy::is_dom_ui_enabled(enabled_bindings_));
initial.commit09911bf2008-07-26 23:55:292626 dom_ui_bindings_.SetProperty(name, value);
2627}
2628
2629void RenderView::OnReservePageIDRange(int size_of_range) {
2630 next_page_id_ += size_of_range + 1;
2631}
2632
[email protected]e80c73b2009-04-07 23:24:582633void RenderView::OnDragSourceEndedOrMoved(const gfx::Point& client_point,
2634 const gfx::Point& screen_point,
[email protected]5f9ae6c2009-07-08 02:38:032635 bool ended, bool cancelled) {
2636 if (ended) {
2637 if (cancelled)
2638 webview()->DragSourceCancelledAt(client_point, screen_point);
2639 else
2640 webview()->DragSourceEndedAt(client_point, screen_point);
2641 } else {
[email protected]e80c73b2009-04-07 23:24:582642 webview()->DragSourceMovedTo(client_point, screen_point);
[email protected]5f9ae6c2009-07-08 02:38:032643 }
initial.commit09911bf2008-07-26 23:55:292644}
2645
2646void RenderView::OnDragSourceSystemDragEnded() {
2647 webview()->DragSourceSystemDragEnded();
2648}
2649
2650void RenderView::OnUploadFileRequest(const ViewMsg_UploadFile_Params& p) {
2651 webkit_glue::FileUploadData* f = new webkit_glue::FileUploadData;
2652 f->file_path = p.file_path;
2653 f->form_name = p.form;
2654 f->file_name = p.file;
2655 f->submit_name = p.submit;
2656
2657 // Build the other form values map.
2658 if (!p.other_values.empty()) {
2659 std::vector<std::wstring> e;
2660 std::vector<std::wstring> kvp;
2661 std::vector<std::wstring>::iterator i;
2662
2663 SplitString(p.other_values, L'\n', &e);
2664 for (i = e.begin(); i != e.end(); ++i) {
2665 SplitString(*i, L'=', &kvp);
2666 if (kvp.size() == 2)
2667 f->other_form_values[kvp[0]] = kvp[1];
2668 kvp.clear();
2669 }
2670 }
2671
2672 pending_upload_data_.reset(f);
2673 ProcessPendingUpload();
2674}
2675
2676void RenderView::ProcessPendingUpload() {
2677 webkit_glue::FileUploadData* f = pending_upload_data_.get();
2678 if (f && webview() && webkit_glue::FillFormToUploadFile(webview(), *f))
2679 ResetPendingUpload();
2680}
2681
2682void RenderView::ResetPendingUpload() {
2683 pending_upload_data_.reset();
2684}
2685
2686void RenderView::OnFormFill(const FormData& form) {
2687 webkit_glue::FillForm(this->webview(), form);
2688}
2689
2690void RenderView::OnFillPasswordForm(
[email protected]daa8c58e2009-06-15 17:21:102691 const webkit_glue::PasswordFormDomManager::FillData& form_data) {
initial.commit09911bf2008-07-26 23:55:292692 webkit_glue::FillPasswordForm(this->webview(), form_data);
2693}
2694
2695void RenderView::OnDragTargetDragEnter(const WebDropData& drop_data,
[email protected]e80c73b2009-04-07 23:24:582696 const gfx::Point& client_point,
2697 const gfx::Point& screen_point) {
2698 bool is_drop_target = webview()->DragTargetDragEnter(
2699 drop_data.ToDragData(),
2700 drop_data.identity,
2701 client_point,
2702 screen_point);
initial.commit09911bf2008-07-26 23:55:292703
2704 Send(new ViewHostMsg_UpdateDragCursor(routing_id_, is_drop_target));
2705}
2706
[email protected]e80c73b2009-04-07 23:24:582707void RenderView::OnDragTargetDragOver(const gfx::Point& client_point,
2708 const gfx::Point& screen_point) {
2709 bool is_drop_target =
2710 webview()->DragTargetDragOver(client_point, screen_point);
initial.commit09911bf2008-07-26 23:55:292711
2712 Send(new ViewHostMsg_UpdateDragCursor(routing_id_, is_drop_target));
2713}
2714
2715void RenderView::OnDragTargetDragLeave() {
2716 webview()->DragTargetDragLeave();
2717}
2718
[email protected]e80c73b2009-04-07 23:24:582719void RenderView::OnDragTargetDrop(const gfx::Point& client_point,
2720 const gfx::Point& screen_point) {
2721 webview()->DragTargetDrop(client_point, screen_point);
initial.commit09911bf2008-07-26 23:55:292722}
2723
2724void RenderView::OnUpdateWebPreferences(const WebPreferences& prefs) {
2725 webview()->SetPreferences(prefs);
2726}
2727
2728void RenderView::OnSetAltErrorPageURL(const GURL& url) {
2729 alternate_error_page_url_ = url;
2730}
2731
initial.commit09911bf2008-07-26 23:55:292732void RenderView::OnInstallMissingPlugin() {
2733 // This could happen when the first default plugin is deleted.
2734 if (first_default_plugin_ == NULL)
2735 return;
2736 first_default_plugin_->InstallMissingPlugin();
2737}
2738
[email protected]b62d1a8c2009-01-13 23:54:572739void RenderView::OnFileChooserResponse(
[email protected]561abe62009-04-06 18:08:342740 const std::vector<FilePath>& file_names) {
[email protected]8029f5672009-03-20 22:33:362741 // This could happen if we navigated to a different page before the user
2742 // closed the chooser.
2743 if (!file_chooser_.get())
2744 return;
2745
[email protected]b62d1a8c2009-01-13 23:54:572746 file_chooser_->OnFileChoose(file_names);
initial.commit09911bf2008-07-26 23:55:292747 file_chooser_.reset();
2748}
2749
2750void RenderView::OnEnableViewSourceMode() {
2751 if (!webview())
2752 return;
2753 WebFrame* main_frame = webview()->GetMainFrame();
2754 if (!main_frame)
2755 return;
2756
[email protected]dd7daa82009-08-10 05:46:452757 main_frame->enableViewSourceMode(true);
initial.commit09911bf2008-07-26 23:55:292758}
2759
[email protected]0666aef2009-05-13 19:48:082760void RenderView::OnEnableIntrinsicWidthChangedMode() {
2761 send_preferred_width_changes_ = true;
2762}
2763
[email protected]80d96fa2009-06-10 22:34:512764void RenderView::OnSetRendererPrefs(const RendererPreferences& renderer_prefs) {
2765 renderer_preferences_ = renderer_prefs;
[email protected]6e282c92009-07-24 01:19:372766 UpdateFontRenderingFromRendererPrefs();
[email protected]80d96fa2009-06-10 22:34:512767}
2768
[email protected]581b87eb2009-07-23 23:06:562769void RenderView::OnMediaPlayerActionAt(int x,
2770 int y,
2771 const MediaPlayerAction& action) {
2772 if (!webview())
2773 return;
2774
2775 webview()->MediaPlayerActionAt(x, y, action);
2776}
2777
initial.commit09911bf2008-07-26 23:55:292778void RenderView::OnUpdateBackForwardListCount(int back_list_count,
2779 int forward_list_count) {
2780 history_back_list_count_ = back_list_count;
2781 history_forward_list_count_ = forward_list_count;
2782}
2783
[email protected]266eb6f2008-09-30 23:56:502784void RenderView::OnGetAccessibilityInfo(
[email protected]6a983b42009-03-20 20:12:252785 const webkit_glue::WebAccessibility::InParams& in_params,
2786 webkit_glue::WebAccessibility::OutParams* out_params) {
[email protected]6c8afae52009-01-22 02:24:572787#if defined(OS_WIN)
[email protected]6a983b42009-03-20 20:12:252788 if (!web_accessibility_manager_.get()) {
2789 web_accessibility_manager_.reset(
2790 webkit_glue::WebAccessibilityManager::Create());
2791 }
[email protected]266eb6f2008-09-30 23:56:502792
[email protected]6a983b42009-03-20 20:12:252793 if (!web_accessibility_manager_->GetAccObjInfo(webview(), in_params,
2794 out_params)) {
[email protected]266eb6f2008-09-30 23:56:502795 return;
2796 }
[email protected]6c8afae52009-01-22 02:24:572797#else // defined(OS_WIN)
2798 // TODO(port): accessibility not yet implemented
2799 NOTIMPLEMENTED();
2800#endif
[email protected]266eb6f2008-09-30 23:56:502801}
2802
[email protected]6a983b42009-03-20 20:12:252803void RenderView::OnClearAccessibilityInfo(int acc_obj_id, bool clear_all) {
[email protected]6c8afae52009-01-22 02:24:572804#if defined(OS_WIN)
[email protected]6a983b42009-03-20 20:12:252805 if (!web_accessibility_manager_.get()) {
[email protected]266eb6f2008-09-30 23:56:502806 // If accessibility is not activated, ignore clearing message.
2807 return;
2808 }
[email protected]e846d0d2009-05-20 00:53:062809
[email protected]6a983b42009-03-20 20:12:252810 if (!web_accessibility_manager_->ClearAccObjMap(acc_obj_id, clear_all))
[email protected]266eb6f2008-09-30 23:56:502811 return;
[email protected]e846d0d2009-05-20 00:53:062812
[email protected]6c8afae52009-01-22 02:24:572813#else // defined(OS_WIN)
2814 // TODO(port): accessibility not yet implemented
2815 NOTIMPLEMENTED();
2816#endif
[email protected]266eb6f2008-09-30 23:56:502817}
2818
initial.commit09911bf2008-07-26 23:55:292819void RenderView::OnGetAllSavableResourceLinksForCurrentPage(
2820 const GURL& page_url) {
2821 // Prepare list to storage all savable resource links.
2822 std::vector<GURL> resources_list;
2823 std::vector<GURL> referrers_list;
2824 std::vector<GURL> frames_list;
2825 webkit_glue::SavableResourcesResult result(&resources_list,
2826 &referrers_list,
2827 &frames_list);
2828
2829 if (!webkit_glue::GetAllSavableResourceLinksForCurrentPage(webview(),
2830 page_url,
2831 &result)) {
2832 // If something is wrong when collecting all savable resource links,
2833 // send empty list to embedder(browser) to tell it failed.
2834 referrers_list.clear();
2835 resources_list.clear();
2836 frames_list.clear();
2837 }
2838
2839 // Send result of all savable resource links to embedder.
2840 Send(new ViewHostMsg_SendCurrentPageAllSavableResourceLinks(routing_id_,
2841 resources_list,
2842 referrers_list,
2843 frames_list));
2844}
2845
2846void RenderView::OnGetSerializedHtmlDataForCurrentPageWithLocalLinks(
[email protected]f6b48532009-02-12 01:56:322847 const std::vector<GURL>& links,
[email protected]fde6714d12009-02-18 22:39:312848 const std::vector<FilePath>& local_paths,
2849 const FilePath& local_directory_name) {
initial.commit09911bf2008-07-26 23:55:292850 webkit_glue::DomSerializer dom_serializer(webview()->GetMainFrame(),
2851 true,
2852 this,
2853 links,
2854 local_paths,
2855 local_directory_name);
2856 dom_serializer.SerializeDom();
2857}
2858
2859void RenderView::DidSerializeDataForFrame(const GURL& frame_url,
2860 const std::string& data, PageSavingSerializationStatus status) {
2861 Send(new ViewHostMsg_SendSerializedHtmlData(routing_id_,
2862 frame_url, data, static_cast<int32>(status)));
2863}
2864
[email protected]04b4a6c2008-08-02 00:44:472865void RenderView::OnMsgShouldClose() {
initial.commit09911bf2008-07-26 23:55:292866 bool should_close = webview()->ShouldClose();
[email protected]04b4a6c2008-08-02 00:44:472867 Send(new ViewHostMsg_ShouldClose_ACK(routing_id_, should_close));
initial.commit09911bf2008-07-26 23:55:292868}
2869
[email protected]eb6b87a2009-07-24 15:57:392870void RenderView::OnClosePage(const ViewMsg_ClosePage_Params& params) {
initial.commit09911bf2008-07-26 23:55:292871 // TODO(creis): We'd rather use webview()->Close() here, but that currently
2872 // sets the WebView's delegate_ to NULL, preventing any JavaScript dialogs
2873 // in the onunload handler from appearing. For now, we're bypassing that and
2874 // calling the FrameLoader's CloseURL method directly. This should be
2875 // revisited to avoid having two ways to close a page. Having a single way
2876 // to close that can run onunload is also useful for fixing
2877 // http://b/issue?id=753080.
2878 WebFrame* main_frame = webview()->GetMainFrame();
[email protected]7a9b51f2009-06-29 21:28:292879 if (main_frame) {
[email protected]dd7daa82009-08-10 05:46:452880 const GURL& url = main_frame->url();
[email protected]7a9b51f2009-06-29 21:28:292881 // TODO(davemoore) this code should be removed once WillCloseFrame() gets
2882 // called when a page is destroyed. DumpLoadHistograms() is safe to call
2883 // multiple times for the same frame, but it will simplify things.
[email protected]dd7daa82009-08-10 05:46:452884 if (url.SchemeIs(chrome::kHttpScheme) ||
2885 url.SchemeIs(chrome::kHttpsScheme))
[email protected]7a9b51f2009-06-29 21:28:292886 DumpLoadHistograms();
[email protected]7a9b51f2009-06-29 21:28:292887 }
[email protected]e6fae1b2009-08-06 23:20:352888 webview()->ClosePage();
initial.commit09911bf2008-07-26 23:55:292889
[email protected]eb6b87a2009-07-24 15:57:392890 // Just echo back the params in the ACK.
2891 Send(new ViewHostMsg_ClosePage_ACK(routing_id_, params));
initial.commit09911bf2008-07-26 23:55:292892}
2893
2894void RenderView::OnThemeChanged() {
[email protected]6c8afae52009-01-22 02:24:572895#if defined(OS_WIN)
initial.commit09911bf2008-07-26 23:55:292896 gfx::NativeTheme::instance()->CloseHandles();
2897 gfx::Rect view_rect(0, 0, size_.width(), size_.height());
[email protected]4873c7d2009-07-16 06:36:282898 didInvalidateRect(view_rect);
[email protected]6c8afae52009-01-22 02:24:572899#else // defined(OS_WIN)
2900 // TODO(port): we don't support theming on non-Windows platforms yet
2901 NOTIMPLEMENTED();
2902#endif
initial.commit09911bf2008-07-26 23:55:292903}
2904
[email protected]f46aff62008-10-16 07:58:052905void RenderView::DidAddHistoryItem() {
[email protected]f8901082008-10-31 23:34:032906 // We don't want to update the history length for the start page
2907 // navigation.
2908 WebFrame* main_frame = webview()->GetMainFrame();
2909 DCHECK(main_frame != NULL);
2910
[email protected]dd7daa82009-08-10 05:46:452911 WebDataSource* ds = main_frame->dataSource();
[email protected]f8901082008-10-31 23:34:032912 DCHECK(ds != NULL);
2913
[email protected]daa8c58e2009-06-15 17:21:102914 NavigationState* navigation_state = NavigationState::FromDataSource(ds);
[email protected]78a3a6f2009-07-02 16:15:012915 DCHECK(navigation_state);
[email protected]daa8c58e2009-06-15 17:21:102916 if (navigation_state->transition_type() == PageTransition::START_PAGE)
[email protected]f8901082008-10-31 23:34:032917 return;
2918
[email protected]f46aff62008-10-16 07:58:052919 history_back_list_count_++;
2920 history_forward_list_count_ = 0;
2921}
2922
[email protected]28790922009-03-09 19:48:372923void RenderView::OnMessageFromExternalHost(const std::string& message,
2924 const std::string& origin,
2925 const std::string& target) {
[email protected]3ac14a052008-08-15 21:22:152926 if (message.empty())
2927 return;
2928
[email protected]28790922009-03-09 19:48:372929 external_host_bindings_.ForwardMessageFromExternalHost(message, origin,
2930 target);
[email protected]3ac14a052008-08-15 21:22:152931}
2932
[email protected]0aa55312008-10-17 21:53:082933void RenderView::OnDisassociateFromPopupCount() {
2934 if (decrement_shared_popup_at_destruction_)
2935 shared_popup_counter_->data--;
2936 shared_popup_counter_ = new SharedRenderViewCounter(0);
2937 decrement_shared_popup_at_destruction_ = false;
2938}
2939
[email protected]15d79e12009-08-02 19:23:452940bool RenderView::MaybeLoadAlternateErrorPage(WebFrame* frame,
2941 const WebURLError& error,
2942 bool replace) {
2943 // We only show alternate error pages in the main frame. They are
2944 // intended to assist the user when navigating, so there is not much
2945 // value in showing them for failed subframes. Ideally, we would be
2946 // able to use the TYPED transition type for this, but that flag is
2947 // not preserved across page reloads.
[email protected]dd7daa82009-08-10 05:46:452948 if (frame->parent())
[email protected]15d79e12009-08-02 19:23:452949 return false;
2950
2951 // Use the alternate error page service if this is a DNS failure or
[email protected]c53976d52009-08-07 18:58:372952 // connection failure.
[email protected]15d79e12009-08-02 19:23:452953 int ec = error.reason;
2954 if (ec != net::ERR_NAME_NOT_RESOLVED &&
2955 ec != net::ERR_CONNECTION_FAILED &&
2956 ec != net::ERR_CONNECTION_REFUSED &&
2957 ec != net::ERR_ADDRESS_UNREACHABLE &&
[email protected]c53976d52009-08-07 18:58:372958 ec != net::ERR_CONNECTION_TIMED_OUT)
[email protected]15d79e12009-08-02 19:23:452959 return false;
2960
2961 const GURL& error_page_url = GetAlternateErrorPageURL(error.unreachableURL,
[email protected]7ccddb8c2009-08-04 17:36:552962 ec == net::ERR_NAME_NOT_RESOLVED ? DNS_ERROR : CONNECTION_ERROR);
[email protected]15d79e12009-08-02 19:23:452963 if (!error_page_url.is_valid())
2964 return false;
2965
2966 // Load an empty page first so there is an immediate response to the error,
2967 // and then kick off a request for the alternate error page.
[email protected]dd7daa82009-08-10 05:46:452968 frame->loadHTMLString(std::string(),
[email protected]15d79e12009-08-02 19:23:452969 GURL(kUnreachableWebDataURL),
2970 error.unreachableURL,
2971 replace);
2972
2973 // Now, create a fetcher for the error page and associate it with the data
2974 // source we just created via the LoadHTMLString call. That way if another
2975 // navigation occurs, the fetcher will get destroyed.
2976 NavigationState* navigation_state =
[email protected]dd7daa82009-08-10 05:46:452977 NavigationState::FromDataSource(frame->provisionalDataSource());
[email protected]15d79e12009-08-02 19:23:452978 navigation_state->set_alt_error_page_fetcher(
2979 new AltErrorPageResourceFetcher(
2980 error_page_url, frame, error,
2981 NewCallback(this, &RenderView::AltErrorPageFinished)));
2982 return true;
2983}
2984
initial.commit09911bf2008-07-26 23:55:292985std::string RenderView::GetAltHTMLForTemplate(
2986 const DictionaryValue& error_strings, int template_resource_id) const {
2987 const StringPiece template_html(
2988 ResourceBundle::GetSharedInstance().GetRawDataResource(
2989 template_resource_id));
2990
2991 if (template_html.empty()) {
2992 NOTREACHED() << "unable to load template. ID: " << template_resource_id;
2993 return "";
2994 }
[email protected]7cd22a52009-07-14 00:40:252995
initial.commit09911bf2008-07-26 23:55:292996 // "t" is the id of the templates root node.
[email protected]7cd22a52009-07-14 00:40:252997 return jstemplate_builder::GetTemplatesHtml(
initial.commit09911bf2008-07-26 23:55:292998 template_html, &error_strings, "t");
2999}
[email protected]0e79b9e2009-02-13 04:20:483000
[email protected]15d79e12009-08-02 19:23:453001void RenderView::AltErrorPageFinished(WebFrame* frame,
3002 const WebURLError& original_error,
3003 const std::string& html) {
3004 // Here, we replace the blank page we loaded previously.
[email protected]7ccddb8c2009-08-04 17:36:553005
3006 // If we failed to download the alternate error page, fall back to the
3007 // original error page if present. Otherwise, LoadNavigationErrorPage
3008 // will simply display a default error page.
3009 const std::string* html_to_load = &html;
3010 if (html.empty()) {
3011 NavigationState* navigation_state =
[email protected]dd7daa82009-08-10 05:46:453012 NavigationState::FromDataSource(frame->dataSource());
[email protected]7ccddb8c2009-08-04 17:36:553013 html_to_load = &navigation_state->postponed_data();
3014 }
3015 LoadNavigationErrorPage(
3016 frame, WebURLRequest(), original_error, *html_to_load, true);
[email protected]15d79e12009-08-02 19:23:453017}
3018
[email protected]30f75e62009-02-25 22:01:003019void RenderView::OnMoveOrResizeStarted() {
3020 if (webview())
3021 webview()->HideAutofillPopup();
3022}
3023
[email protected]30f75e62009-02-25 22:01:003024void RenderView::OnResize(const gfx::Size& new_size,
3025 const gfx::Rect& resizer_rect) {
3026 if (webview())
3027 webview()->HideAutofillPopup();
3028 RenderWidget::OnResize(new_size, resizer_rect);
3029}
[email protected]0aa477bd2009-03-23 22:21:433030
[email protected]05d478752009-04-08 23:38:163031void RenderView::OnClearFocusedNode() {
3032 if (webview())
3033 webview()->ClearFocusedNode();
3034}
3035
[email protected]699ab0d2009-04-23 23:19:143036void RenderView::OnSetBackground(const SkBitmap& background) {
3037 if (webview())
3038 webview()->SetIsTransparent(!background.empty());
3039
3040 SetBackground(background);
3041}
3042
[email protected]8c66c5a2009-07-22 17:26:343043void RenderView::OnSetActive(bool active) {
3044 if (webview())
3045 webview()->SetActive(active);
3046}
3047
[email protected]309d7a282009-03-24 09:18:273048void RenderView::SendExtensionRequest(const std::string& name,
3049 const std::string& args,
[email protected]c6619182009-05-12 14:59:323050 int request_id,
[email protected]2f25d7b92009-06-10 00:06:473051 bool has_callback) {
[email protected]c6619182009-05-12 14:59:323052 Send(new ViewHostMsg_ExtensionRequest(routing_id_, name, args, request_id,
[email protected]2f25d7b92009-06-10 00:06:473053 has_callback));
[email protected]309d7a282009-03-24 09:18:273054}
3055
[email protected]c6619182009-05-12 14:59:323056void RenderView::OnExtensionResponse(int request_id,
3057 bool success,
3058 const std::string& response,
3059 const std::string& error) {
[email protected]0f6053962009-07-09 19:26:353060 ExtensionProcessBindings::HandleResponse(
3061 request_id, success, response, error);
[email protected]309d7a282009-03-24 09:18:273062}
[email protected]c20210e62009-04-03 21:39:263063
[email protected]7120f132009-07-20 21:05:373064void RenderView::OnExtensionMessageInvoke(const std::string& function_name,
3065 const ListValue& args) {
3066 RendererExtensionBindings::Invoke(function_name, args, this);
3067}
3068
[email protected]e7e4f3c2009-04-21 15:24:083069// Dump all load time histograms.
[email protected]c20210e62009-04-03 21:39:263070//
[email protected]7a9b51f2009-06-29 21:28:293071// There are 13 histograms measuring various times.
[email protected]c20210e62009-04-03 21:39:263072// The time points we keep are
3073// request: time document was requested by user
3074// start: time load of document started
[email protected]a2f6bc112009-06-27 16:27:253075// commit: time load of document started
[email protected]7a9b51f2009-06-29 21:28:293076// finish_document: main document loaded, before onload()
[email protected]c20210e62009-04-03 21:39:263077// finish: after onload() and all resources are loaded
[email protected]7a9b51f2009-06-29 21:28:293078// first_paint: first paint performed
3079// first_paint_after_load: first paint performed after load is finished
3080// begin: request if it was user requested, start otherwise
3081//
[email protected]c20210e62009-04-03 21:39:263082// The times that we histogram are
[email protected]a2f6bc112009-06-27 16:27:253083// request->start,
[email protected]7a9b51f2009-06-29 21:28:293084// start->commit,
3085// commit->finish_document,
3086// finish_document->finish,
3087// begin->commit,
3088// begin->finishDoc,
3089// begin->finish,
3090// begin->first_paint,
3091// begin->first_paint_after_load
3092// commit->finishDoc,
3093// commit->first_paint,
3094// commit->first_paint_after_load,
3095// finish->first_paint_after_load,
[email protected]c20210e62009-04-03 21:39:263096//
[email protected]e7e4f3c2009-04-21 15:24:083097// It's possible for the request time not to be set, if a client
3098// redirect had been done (the user never requested the page)
3099// Also, it's possible to load a page without ever laying it out
[email protected]7a9b51f2009-06-29 21:28:293100// so first_paint and first_paint_after_load can be 0.
[email protected]c20210e62009-04-03 21:39:263101void RenderView::DumpLoadHistograms() const {
3102 WebFrame* main_frame = webview()->GetMainFrame();
[email protected]ed3fb032009-06-16 19:50:563103 NavigationState* navigation_state =
[email protected]dd7daa82009-08-10 05:46:453104 NavigationState::FromDataSource(main_frame->dataSource());
[email protected]7a9b51f2009-06-29 21:28:293105 Time finish = navigation_state->finish_load_time();
[email protected]ed3fb032009-06-16 19:50:563106
[email protected]7a9b51f2009-06-29 21:28:293107 // If we've already dumped or we haven't finished loading, do nothing.
3108 if (navigation_state->load_histograms_recorded() || finish.is_null())
3109 return;
[email protected]ed3fb032009-06-16 19:50:563110
[email protected]7a9b51f2009-06-29 21:28:293111 Time request = navigation_state->request_time();
3112 Time start = navigation_state->start_load_time();
3113 Time commit = navigation_state->commit_load_time();
3114 Time finish_doc = navigation_state->finish_document_load_time();
3115 Time first_paint = navigation_state->first_paint_time();
3116 Time first_paint_after_load =
3117 navigation_state->first_paint_after_load_time();
[email protected]c20210e62009-04-03 21:39:263118
[email protected]7a9b51f2009-06-29 21:28:293119 Time begin;
3120 // Client side redirects will have no request time.
3121 if (request.is_null()) {
3122 begin = start;
3123 } else {
3124 begin = request;
3125 UMA_HISTOGRAM_MEDIUM_TIMES("Renderer4.RequestToStart", start - request);
[email protected]e7e4f3c2009-04-21 15:24:083126 }
[email protected]7a9b51f2009-06-29 21:28:293127 UMA_HISTOGRAM_MEDIUM_TIMES("Renderer4.StartToCommit", commit - start);
3128 UMA_HISTOGRAM_MEDIUM_TIMES(
3129 "Renderer4.CommitToFinishDoc", finish_doc - commit);
3130 UMA_HISTOGRAM_MEDIUM_TIMES(
3131 "Renderer4.FinishDocToFinish", finish - finish_doc);
3132
3133 UMA_HISTOGRAM_MEDIUM_TIMES("Renderer4.BeginToCommit", commit - begin);
3134 UMA_HISTOGRAM_MEDIUM_TIMES("Renderer4.BeginToFinishDoc", finish_doc - begin);
[email protected]e695fbd62009-06-30 16:31:543135
3136 static const TimeDelta kBeginToFinishMin(TimeDelta::FromMilliseconds(10));
3137 static const TimeDelta kBeginToFinishMax(TimeDelta::FromMinutes(10));
3138 static const size_t kBeginToFinishBucketCount(100);
3139
3140 UMA_HISTOGRAM_CUSTOM_TIMES("Renderer4.BeginToFinish",
3141 finish - begin, kBeginToFinishMin,
3142 kBeginToFinishMax, kBeginToFinishBucketCount);
[email protected]0a32257a2009-07-09 18:10:413143 UMA_HISTOGRAM_CUSTOM_TIMES("Renderer4.StartToFinish",
3144 finish - start, kBeginToFinishMin,
3145 kBeginToFinishMax, kBeginToFinishBucketCount);
3146 if (!request.is_null())
3147 UMA_HISTOGRAM_CUSTOM_TIMES("Renderer4.RequestToFinish",
3148 finish - request, kBeginToFinishMin,
3149 kBeginToFinishMax, kBeginToFinishBucketCount);
[email protected]e695fbd62009-06-30 16:31:543150
[email protected]36285b52009-06-30 19:10:003151 static bool use_dns_histogram(FieldTrialList::Find("DnsImpact") &&
3152 !FieldTrialList::Find("DnsImpact")->group_name().empty());
[email protected]0a32257a2009-07-09 18:10:413153 if (use_dns_histogram) {
[email protected]36285b52009-06-30 19:10:003154 UMA_HISTOGRAM_CUSTOM_TIMES(
3155 FieldTrial::MakeName("Renderer4.BeginToFinish", "DnsImpact").data(),
3156 finish - begin, kBeginToFinishMin,
3157 kBeginToFinishMax, kBeginToFinishBucketCount);
[email protected]0a32257a2009-07-09 18:10:413158 UMA_HISTOGRAM_CUSTOM_TIMES(
3159 FieldTrial::MakeName("Renderer4.StartToFinish", "DnsImpact").data(),
3160 finish - start, kBeginToFinishMin,
3161 kBeginToFinishMax, kBeginToFinishBucketCount);
3162 if (!request.is_null())
3163 UMA_HISTOGRAM_CUSTOM_TIMES(
3164 FieldTrial::MakeName("Renderer4.RequestToFinish", "DnsImpact").data(),
3165 finish - request, kBeginToFinishMin,
3166 kBeginToFinishMax, kBeginToFinishBucketCount);
3167 }
[email protected]e695fbd62009-06-30 16:31:543168
[email protected]36285b52009-06-30 19:10:003169 static bool use_sdch_histogram(FieldTrialList::Find("GlobalSdch") &&
3170 !FieldTrialList::Find("GlobalSdch")->group_name().empty());
[email protected]0a32257a2009-07-09 18:10:413171 if (use_sdch_histogram) {
[email protected]36285b52009-06-30 19:10:003172 UMA_HISTOGRAM_CUSTOM_TIMES(
3173 FieldTrial::MakeName("Renderer4.BeginToFinish", "GlobalSdch").data(),
3174 finish - begin, kBeginToFinishMin,
3175 kBeginToFinishMax, kBeginToFinishBucketCount);
[email protected]0a32257a2009-07-09 18:10:413176 UMA_HISTOGRAM_CUSTOM_TIMES(
3177 FieldTrial::MakeName("Renderer4.StartToFinish", "GlobalSdch").data(),
3178 finish - start, kBeginToFinishMin,
3179 kBeginToFinishMax, kBeginToFinishBucketCount);
3180 if (!request.is_null())
3181 UMA_HISTOGRAM_CUSTOM_TIMES(
3182 FieldTrial::MakeName("Renderer4.RequestToFinish",
3183 "GlobalSdch").data(),
3184 finish - request, kBeginToFinishMin,
3185 kBeginToFinishMax, kBeginToFinishBucketCount);
3186 }
[email protected]7a9b51f2009-06-29 21:28:293187
[email protected]5fff93f2009-08-02 04:27:343188 static bool use_socket_late_binding_histogram =
3189 FieldTrialList::Find("SocketLateBinding") &&
3190 !FieldTrialList::Find("SocketLateBinding")->group_name().empty();
3191 if (use_socket_late_binding_histogram) {
3192 UMA_HISTOGRAM_CUSTOM_TIMES(
3193 FieldTrial::MakeName("Renderer4.BeginToFinish",
3194 "SocketLateBinding").data(),
3195 finish - begin, kBeginToFinishMin,
3196 kBeginToFinishMax, kBeginToFinishBucketCount);
3197 UMA_HISTOGRAM_CUSTOM_TIMES(
3198 FieldTrial::MakeName("Renderer4.StartToFinish",
3199 "SocketLateBinding").data(),
3200 finish - start, kBeginToFinishMin,
3201 kBeginToFinishMax, kBeginToFinishBucketCount);
3202 if (!request.is_null())
3203 UMA_HISTOGRAM_CUSTOM_TIMES(
3204 FieldTrial::MakeName("Renderer4.RequestToFinish",
3205 "SocketLateBinding").data(),
3206 finish - request, kBeginToFinishMin,
3207 kBeginToFinishMax, kBeginToFinishBucketCount);
3208 }
3209
[email protected]7e05f6c42009-07-11 01:50:483210 static bool use_cache_histogram1(FieldTrialList::Find("CacheSize") &&
3211 !FieldTrialList::Find("CacheSize")->group_name().empty());
3212 if (use_cache_histogram1)
3213 UMA_HISTOGRAM_CUSTOM_TIMES(
3214 FieldTrial::MakeName("Renderer4.StartToFinish", "CacheSize").data(),
3215 finish - start, kBeginToFinishMin,
3216 kBeginToFinishMax, kBeginToFinishBucketCount);
3217
3218 static bool use_cache_histogram2(FieldTrialList::Find("NewEviction") &&
3219 !FieldTrialList::Find("NewEviction")->group_name().empty());
3220 if (use_cache_histogram2)
3221 UMA_HISTOGRAM_CUSTOM_TIMES(
3222 FieldTrial::MakeName("Renderer4.StartToFinish", "NewEviction").data(),
3223 finish - start, kBeginToFinishMin,
3224 kBeginToFinishMax, kBeginToFinishBucketCount);
3225
[email protected]7a9b51f2009-06-29 21:28:293226 UMA_HISTOGRAM_MEDIUM_TIMES("Renderer4.CommitToFinish", finish - commit);
3227
3228 if (!first_paint.is_null()) {
3229 UMA_HISTOGRAM_MEDIUM_TIMES(
3230 "Renderer4.BeginToFirstPaint", first_paint - begin);
3231 UMA_HISTOGRAM_MEDIUM_TIMES(
3232 "Renderer4.CommitToFirstPaint", first_paint - commit);
[email protected]c20210e62009-04-03 21:39:263233 }
[email protected]7a9b51f2009-06-29 21:28:293234
3235 if (!first_paint_after_load.is_null()) {
3236 UMA_HISTOGRAM_MEDIUM_TIMES(
3237 "Renderer4.BeginToFirstPaintAfterLoad", first_paint_after_load - begin);
3238 UMA_HISTOGRAM_MEDIUM_TIMES(
3239 "Renderer4.CommitToFirstPaintAfterLoad",
3240 first_paint_after_load - commit);
3241 UMA_HISTOGRAM_MEDIUM_TIMES(
3242 "Renderer4.FinishToFirstPaintAfterLoad",
3243 first_paint_after_load - finish);
3244 }
3245
3246 navigation_state->set_load_histograms_recorded(true);
[email protected]c20210e62009-04-03 21:39:263247}
[email protected]e846d0d2009-05-20 00:53:063248
3249void RenderView::FocusAccessibilityObject(
3250 WebCore::AccessibilityObject* acc_obj) {
3251#if defined(OS_WIN)
3252 if (!web_accessibility_manager_.get()) {
3253 web_accessibility_manager_.reset(
3254 webkit_glue::WebAccessibilityManager::Create());
3255 }
3256
3257 // Retrieve the accessibility object id of the AccessibilityObject.
3258 int acc_obj_id = web_accessibility_manager_->FocusAccObj(acc_obj);
3259
3260 // If id is valid, alert the browser side that an accessibility focus change
3261 // occurred.
3262 if (acc_obj_id >= 0)
3263 Send(new ViewHostMsg_AccessibilityFocusChange(routing_id_, acc_obj_id));
3264
3265#else // defined(OS_WIN)
3266 // TODO(port): accessibility not yet implemented
3267 NOTIMPLEMENTED();
3268#endif
3269}
[email protected]daa8c58e2009-06-15 17:21:103270
[email protected]4873c7d2009-07-16 06:36:283271void RenderView::DidMovePlugin(const WebPluginGeometry& move) {
3272 SchedulePluginMove(move);
3273}
3274
[email protected]268654772009-08-06 23:02:043275void RenderView::WillDestroyPluginWindow(gfx::PluginWindowHandle window) {
3276 CleanupWindowInPluginMoves(window);
3277}
3278
[email protected]daa8c58e2009-06-15 17:21:103279void RenderView::SendPasswordForms(WebFrame* frame) {
[email protected]dd7daa82009-08-10 05:46:453280 WebVector<WebForm> forms;
3281 frame->forms(forms);
[email protected]daa8c58e2009-06-15 17:21:103282
3283 std::vector<PasswordForm> password_forms;
3284 for (size_t i = 0; i < forms.size(); ++i) {
3285 const WebForm& form = forms[i];
3286
3287 // Respect autocomplete=off.
3288 if (form.isAutoCompleteEnabled()) {
3289 scoped_ptr<PasswordForm> password_form(
3290 PasswordFormDomManager::CreatePasswordForm(form));
3291 if (password_form.get())
3292 password_forms.push_back(*password_form);
3293 }
3294 }
3295
3296 if (!password_forms.empty())
3297 Send(new ViewHostMsg_PasswordFormsSeen(routing_id_, password_forms));
3298}
[email protected]0fda7272009-06-26 15:49:333299
3300void RenderView::Print(WebFrame* frame, bool script_initiated) {
3301 DCHECK(frame);
3302 if (print_helper_.get() == NULL) {
3303 print_helper_.reset(new PrintWebViewHelper(this));
3304 }
3305 print_helper_->Print(frame, script_initiated);
3306}