blob: ac346361bed49a33827612c236fc4bd127993025 [file] [log] [blame]
[email protected]05d478752009-04-08 23:38:161// Copyright (c) 2009 The Chromium Authors. All rights reserved.
license.botbf09a502008-08-24 00:55:552// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
initial.commit09911bf2008-07-26 23:55:294
5#include "chrome/renderer/render_view.h"
6
7#include <algorithm>
8#include <string>
9#include <vector>
10
[email protected]91e81ae2009-05-08 22:14:3811#include "app/gfx/color_utils.h"
[email protected]37126212009-05-06 02:23:3112#include "app/gfx/favicon_size.h"
[email protected]a92b8642009-05-05 23:38:5613#include "app/l10n_util.h"
[email protected]37126212009-05-06 02:23:3114#include "app/message_box_flags.h"
[email protected]9929da92009-05-05 02:05:1115#include "app/resource_bundle.h"
initial.commit09911bf2008-07-26 23:55:2916#include "base/command_line.h"
[email protected]bb063b72009-03-27 23:18:5017#include "base/compiler_specific.h"
[email protected]4646f292009-05-20 03:49:0518#include "base/field_trial.h"
initial.commit09911bf2008-07-26 23:55:2919#include "base/gfx/png_encoder.h"
[email protected]18bcc3c2009-01-27 21:39:1520#include "base/gfx/native_widget_types.h"
[email protected]8380c092009-06-25 17:45:5121#include "base/process_util.h"
[email protected]7b291f92009-08-14 05:43:5322#include "base/singleton.h"
initial.commit09911bf2008-07-26 23:55:2923#include "base/string_piece.h"
24#include "base/string_util.h"
[email protected]6c8afae52009-01-22 02:24:5725#include "build/build_config.h"
[email protected]81e63782009-02-27 19:35:0926#include "chrome/common/bindings_policy.h"
[email protected]ef916272009-07-08 21:40:5527#include "chrome/common/child_process_logging.h"
initial.commit09911bf2008-07-26 23:55:2928#include "chrome/common/chrome_switches.h"
[email protected]f0af6a72009-05-30 05:25:1729#include "chrome/common/chrome_constants.h"
initial.commit09911bf2008-07-26 23:55:2930#include "chrome/common/jstemplate_builder.h"
[email protected]630e26b2008-10-14 22:55:1731#include "chrome/common/page_zoom.h"
[email protected]8beff0762009-09-29 02:18:3032#include "chrome/common/plugin_messages.h"
[email protected]e09ba552009-02-05 03:26:2933#include "chrome/common/render_messages.h"
[email protected]9b6f40e2009-06-11 15:54:2634#include "chrome/common/renderer_preferences.h"
initial.commit09911bf2008-07-26 23:55:2935#include "chrome/common/thumbnail_score.h"
[email protected]6de74452009-02-25 18:04:5936#include "chrome/common/url_constants.h"
initial.commit09911bf2008-07-26 23:55:2937#include "chrome/renderer/about_handler.h"
[email protected]5fb88962009-04-16 19:03:2538#include "chrome/renderer/audio_message_filter.h"
[email protected]e4ac5df2009-03-17 15:33:1139#include "chrome/renderer/devtools_agent.h"
40#include "chrome/renderer/devtools_client.h"
[email protected]912256b32009-09-18 09:47:3541#include "chrome/renderer/extension_groups.h"
[email protected]f816c012009-06-26 21:48:3242#include "chrome/renderer/extensions/event_bindings.h"
[email protected]0f6053962009-07-09 19:26:3543#include "chrome/renderer/extensions/extension_process_bindings.h"
[email protected]7120f132009-07-20 21:05:3744#include "chrome/renderer/extensions/renderer_extension_bindings.h"
initial.commit09911bf2008-07-26 23:55:2945#include "chrome/renderer/localized_error.h"
[email protected]6f56d482009-02-20 05:02:5646#include "chrome/renderer/media/audio_renderer_impl.h"
[email protected]ed3fb032009-06-16 19:50:5647#include "chrome/renderer/navigation_state.h"
[email protected]8beff0762009-09-29 02:18:3048#include "chrome/renderer/plugin_channel_host.h"
[email protected]d81c1e52009-06-03 22:09:5049#include "chrome/renderer/print_web_view_helper.h"
[email protected]39008c02009-02-11 23:59:2550#include "chrome/renderer/render_process.h"
[email protected]0938d3c2009-01-09 20:37:3551#include "chrome/renderer/user_script_slave.h"
initial.commit09911bf2008-07-26 23:55:2952#include "chrome/renderer/visitedlink_slave.h"
[email protected]ba4b17f2009-02-11 21:32:2953#include "chrome/renderer/webplugin_delegate_proxy.h"
[email protected]eb47a132009-03-04 00:39:5654#include "chrome/renderer/webworker_proxy.h"
[email protected]34ac8f32009-02-22 23:03:2755#include "grit/generated_resources.h"
56#include "grit/renderer_resources.h"
[email protected]f11ca0732009-04-11 00:09:3457#include "net/base/data_url.h"
initial.commit09911bf2008-07-26 23:55:2958#include "net/base/escape.h"
59#include "net/base/net_errors.h"
[email protected]c399a8a2008-11-22 19:38:0060#include "skia/ext/bitmap_platform_device.h"
[email protected]83c9e6552008-12-03 16:22:1061#include "skia/ext/image_operations.h"
[email protected]726985e22009-06-18 21:09:2862#include "webkit/api/public/WebDataSource.h"
[email protected]afdcf5c2009-05-10 20:30:4163#include "webkit/api/public/WebDragData.h"
[email protected]daa8c58e2009-06-15 17:21:1064#include "webkit/api/public/WebForm.h"
[email protected]dd7daa82009-08-10 05:46:4565#include "webkit/api/public/WebFrame.h"
[email protected]ca948a22009-06-25 19:36:1766#include "webkit/api/public/WebHistoryItem.h"
[email protected]581b87eb2009-07-23 23:06:5667#include "webkit/api/public/WebNode.h"
[email protected]afdcf5c2009-05-10 20:30:4168#include "webkit/api/public/WebPoint.h"
69#include "webkit/api/public/WebRect.h"
70#include "webkit/api/public/WebScriptSource.h"
[email protected]91733b62009-09-18 06:21:0971#include "webkit/api/public/WebSecurityOrigin.h"
[email protected]afdcf5c2009-05-10 20:30:4172#include "webkit/api/public/WebSize.h"
[email protected]726985e22009-06-18 21:09:2873#include "webkit/api/public/WebURL.h"
74#include "webkit/api/public/WebURLError.h"
75#include "webkit/api/public/WebURLRequest.h"
76#include "webkit/api/public/WebURLResponse.h"
77#include "webkit/api/public/WebVector.h"
[email protected]f430b5712009-08-21 21:46:3178#include "webkit/appcache/appcache_interfaces.h"
[email protected]ba4b17f2009-02-11 21:32:2979#include "webkit/default_plugin/default_plugin_shared.h"
[email protected]ca948a22009-06-25 19:36:1780#include "webkit/glue/glue_serialize.h"
initial.commit09911bf2008-07-26 23:55:2981#include "webkit/glue/dom_operations.h"
82#include "webkit/glue/dom_serializer.h"
[email protected]f11ca0732009-04-11 00:09:3483#include "webkit/glue/image_decoder.h"
[email protected]8e296bbd2009-07-22 21:37:1784#include "webkit/glue/media/buffered_data_source.h"
[email protected]8380c092009-06-25 17:45:5185#include "webkit/glue/media/simple_data_source.h"
initial.commit09911bf2008-07-26 23:55:2986#include "webkit/glue/password_form.h"
[email protected]ba4b17f2009-02-11 21:32:2987#include "webkit/glue/plugins/plugin_list.h"
[email protected]8a3b7962009-09-04 05:53:2388#include "webkit/glue/plugins/webplugin_delegate_impl.h"
initial.commit09911bf2008-07-26 23:55:2989#include "webkit/glue/searchable_form_data.h"
[email protected]6a983b42009-03-20 20:12:2590#include "webkit/glue/webaccessibilitymanager_impl.h"
[email protected]611cad42009-03-16 18:51:3491#include "webkit/glue/webdevtoolsagent_delegate.h"
initial.commit09911bf2008-07-26 23:55:2992#include "webkit/glue/webdropdata.h"
initial.commit09911bf2008-07-26 23:55:2993#include "webkit/glue/webkit_glue.h"
[email protected]add51772009-06-11 18:25:1794#include "webkit/glue/webmediaplayer_impl.h"
[email protected]f103ab72009-09-02 17:10:5995#include "webkit/glue/webplugin_impl.h"
initial.commit09911bf2008-07-26 23:55:2996#include "webkit/glue/webview.h"
initial.commit09911bf2008-07-26 23:55:2997
[email protected]6c8afae52009-01-22 02:24:5798#if defined(OS_WIN)
99// TODO(port): these files are currently Windows only because they concern:
[email protected]6c8afae52009-01-22 02:24:57100// * theming
[email protected]6c8afae52009-01-22 02:24:57101#include "base/gfx/native_theme.h"
[email protected]6c8afae52009-01-22 02:24:57102#endif
103
[email protected]c20210e62009-04-03 21:39:26104using base::Time;
[email protected]e1acf6f2008-10-27 20:43:33105using base::TimeDelta;
[email protected]15d79e12009-08-02 19:23:45106using webkit_glue::AltErrorPageResourceFetcher;
[email protected]daa8c58e2009-06-15 17:21:10107using webkit_glue::AutofillForm;
[email protected]b0950a72009-09-29 23:16:17108using webkit_glue::ImageResourceFetcher;
[email protected]ed3fb032009-06-16 19:50:56109using webkit_glue::PasswordForm;
[email protected]daa8c58e2009-06-15 17:21:10110using webkit_glue::PasswordFormDomManager;
111using webkit_glue::SearchableFormData;
[email protected]1c83eb42009-09-11 21:08:41112using WebKit::WebColor;
113using WebKit::WebColorName;
[email protected]0dea3ea2009-03-31 23:30:59114using WebKit::WebConsoleMessage;
[email protected]e6f546c32009-07-01 17:12:55115using WebKit::WebData;
[email protected]726985e22009-06-18 21:09:28116using WebKit::WebDataSource;
[email protected]e80c73b2009-04-07 23:24:58117using WebKit::WebDragData;
[email protected]1d9f4132009-09-08 17:29:25118using WebKit::WebDragOperation;
119using WebKit::WebDragOperationsMask;
[email protected]79dbc662009-09-04 05:42:51120using WebKit::WebEditingAction;
[email protected]daa8c58e2009-06-15 17:21:10121using WebKit::WebForm;
[email protected]dd7daa82009-08-10 05:46:45122using WebKit::WebFrame;
[email protected]ca948a22009-06-25 19:36:17123using WebKit::WebHistoryItem;
[email protected]3d9689372009-09-10 04:29:17124using WebKit::WebMediaPlayer;
125using WebKit::WebMediaPlayerClient;
[email protected]4873c7d2009-07-16 06:36:28126using WebKit::WebNavigationPolicy;
[email protected]726985e22009-06-18 21:09:28127using WebKit::WebNavigationType;
[email protected]79dbc662009-09-04 05:42:51128using WebKit::WebNode;
[email protected]3d9689372009-09-10 04:29:17129using WebKit::WebPlugin;
130using WebKit::WebPluginParams;
[email protected]48c9cf2d2009-09-16 16:47:52131using WebKit::WebPoint;
[email protected]88efb7ec2009-07-14 16:32:59132using WebKit::WebPopupMenuInfo;
[email protected]79dbc662009-09-04 05:42:51133using WebKit::WebRange;
[email protected]b3f2b912009-04-09 16:18:52134using WebKit::WebRect;
[email protected]4f999132009-03-31 18:08:40135using WebKit::WebScriptSource;
[email protected]e3d60e5d2009-09-25 21:08:29136using WebKit::WebSecurityOrigin;
[email protected]2fab253a2009-08-17 23:00:59137using WebKit::WebSettings;
[email protected]8649fb32009-06-26 17:51:02138using WebKit::WebSize;
[email protected]726985e22009-06-18 21:09:28139using WebKit::WebString;
[email protected]79dbc662009-09-04 05:42:51140using WebKit::WebTextAffinity;
[email protected]de570ef2009-07-29 18:27:52141using WebKit::WebTextDirection;
[email protected]726985e22009-06-18 21:09:28142using WebKit::WebURL;
143using WebKit::WebURLError;
144using WebKit::WebURLRequest;
145using WebKit::WebURLResponse;
[email protected]4873c7d2009-07-16 06:36:28146using WebKit::WebVector;
147using WebKit::WebWidget;
[email protected]27ba8532009-04-24 20:22:43148using WebKit::WebWorker;
149using WebKit::WebWorkerClient;
[email protected]e1acf6f2008-10-27 20:43:33150
initial.commit09911bf2008-07-26 23:55:29151//-----------------------------------------------------------------------------
152
153// define to write the time necessary for thumbnail/DOM text retrieval,
154// respectively, into the system debug log
155// #define TIME_BITMAP_RETRIEVAL
156// #define TIME_TEXT_RETRIEVAL
157
158// maximum number of characters in the document to index, any text beyond this
159// point will be clipped
[email protected]6c8afae52009-01-22 02:24:57160static const size_t kMaxIndexChars = 65535;
initial.commit09911bf2008-07-26 23:55:29161
162// Size of the thumbnails that we'll generate
[email protected]8b4f4892009-09-04 21:52:37163static const int kThumbnailWidth = 212;
164static const int kThumbnailHeight = 132;
initial.commit09911bf2008-07-26 23:55:29165
166// Delay in milliseconds that we'll wait before capturing the page contents
167// and thumbnail.
168static const int kDelayForCaptureMs = 500;
169
170// Typically, we capture the page data once the page is loaded.
171// Sometimes, the page never finishes to load, preventing the page capture
172// To workaround this problem, we always perform a capture after the following
173// delay.
174static const int kDelayForForcedCaptureMs = 6000;
175
[email protected]81a34412009-01-05 19:17:24176// The default value for RenderView.delay_seconds_for_form_state_sync_, see
177// that variable for more.
178const int kDefaultDelaySecondsForFormStateSync = 5;
initial.commit09911bf2008-07-26 23:55:29179
180// The next available page ID to use. This ensures that the page IDs are
181// globally unique in the renderer.
182static int32 next_page_id_ = 1;
183
[email protected]0aa55312008-10-17 21:53:08184// The maximum number of popups that can be spawned from one page.
185static const int kMaximumNumberOfUnacknowledgedPopups = 25;
186
initial.commit09911bf2008-07-26 23:55:29187static const char* const kUnreachableWebDataURL =
[email protected]60e448982009-05-06 04:21:16188 "chrome://chromewebdata/";
initial.commit09911bf2008-07-26 23:55:29189
[email protected]50b691c2008-10-31 19:08:35190static const char* const kBackForwardNavigationScheme = "history";
191
[email protected]726985e22009-06-18 21:09:28192static void GetRedirectChain(WebDataSource* ds, std::vector<GURL>* result) {
193 WebVector<WebURL> urls;
194 ds->redirectChain(urls);
195 result->reserve(urls.size());
196 for (size_t i = 0; i < urls.size(); ++i)
197 result->push_back(urls[i]);
198}
199
initial.commit09911bf2008-07-26 23:55:29200///////////////////////////////////////////////////////////////////////////////
201
[email protected]2fab253a2009-08-17 23:00:59202RenderView::RenderView(RenderThreadBase* render_thread,
203 const WebPreferences& webkit_preferences)
[email protected]81a34412009-01-05 19:17:24204 : RenderWidget(render_thread, true),
[email protected]81e63782009-02-27 19:35:09205 enabled_bindings_(0),
[email protected]e75cb49e2009-01-05 23:13:21206 target_url_status_(TARGET_NONE),
[email protected]81a34412009-01-05 19:17:24207 is_loading_(false),
[email protected]e75cb49e2009-01-05 23:13:21208 navigation_gesture_(NavigationGestureUnknown),
[email protected]81a34412009-01-05 19:17:24209 page_id_(-1),
210 last_page_id_sent_to_browser_(-1),
211 last_indexed_page_id_(-1),
[email protected]81a34412009-01-05 19:17:24212 opened_by_user_gesture_(true),
[email protected]bb063b72009-03-27 23:18:50213 ALLOW_THIS_IN_INITIALIZER_LIST(method_factory_(this)),
[email protected]e4ac5df2009-03-17 15:33:11214 devtools_agent_(NULL),
215 devtools_client_(NULL),
[email protected]81a34412009-01-05 19:17:24216 history_back_list_count_(0),
217 history_forward_list_count_(0),
[email protected]81a34412009-01-05 19:17:24218 has_unload_listener_(false),
219 decrement_shared_popup_at_destruction_(false),
[email protected]81a34412009-01-05 19:17:24220 form_field_autofill_request_id_(0),
221 popup_notification_visible_(false),
[email protected]0666aef2009-05-13 19:48:08222 delay_seconds_for_form_state_sync_(kDefaultDelaySecondsForFormStateSync),
223 preferred_width_(0),
[email protected]5c4266922009-07-10 16:41:27224 send_preferred_width_changes_(false),
[email protected]5f450e52009-07-28 13:28:11225 determine_page_text_after_loading_stops_(false),
[email protected]7b291f92009-08-14 05:43:53226 view_type_(ViewType::INVALID),
227 browser_window_id_(-1),
[email protected]83dde542009-09-11 20:59:55228 last_top_level_navigation_page_id_(-1),
229#if defined(OS_MACOSX)
230 has_document_tag_(false),
231#endif
[email protected]98324892009-09-09 21:16:05232 document_tag_(0),
[email protected]2fab253a2009-08-17 23:00:59233 webkit_preferences_(webkit_preferences) {
[email protected]7b291f92009-08-14 05:43:53234 Singleton<RenderViewSet>()->render_view_set_.insert(this);
initial.commit09911bf2008-07-26 23:55:29235}
236
237RenderView::~RenderView() {
[email protected]7b291f92009-08-14 05:43:53238 Singleton<RenderViewSet>()->render_view_set_.erase(this);
[email protected]0aa55312008-10-17 21:53:08239 if (decrement_shared_popup_at_destruction_)
240 shared_popup_counter_->data--;
241
[email protected]b0950a72009-09-29 23:16:17242 // Dispose of un-disposed image fetchers.
243 for (ImageResourceFetcherSet::iterator i = image_fetchers_.begin();
244 i != image_fetchers_.end(); ++i) {
245 delete *i;
246 }
247
[email protected]83dde542009-09-11 20:59:55248#if defined(OS_MACOSX)
[email protected]98324892009-09-09 21:16:05249 // Tell the spellchecker that the document is closed.
[email protected]83dde542009-09-11 20:59:55250 if (has_document_tag_)
251 Send(new ViewHostMsg_DocumentWithTagClosed(routing_id_, document_tag_));
252#endif
[email protected]98324892009-09-09 21:16:05253
[email protected]5fb88962009-04-16 19:03:25254 render_thread_->RemoveFilter(audio_message_filter_);
initial.commit09911bf2008-07-26 23:55:29255}
256
257/*static*/
[email protected]0aa55312008-10-17 21:53:08258RenderView* RenderView::Create(
[email protected]81a34412009-01-05 19:17:24259 RenderThreadBase* render_thread,
[email protected]18bcc3c2009-01-27 21:39:15260 gfx::NativeViewId parent_hwnd,
[email protected]0aa55312008-10-17 21:53:08261 int32 opener_id,
[email protected]80d96fa2009-06-10 22:34:51262 const RendererPreferences& renderer_prefs,
[email protected]0aa55312008-10-17 21:53:08263 const WebPreferences& webkit_prefs,
264 SharedRenderViewCounter* counter,
265 int32 routing_id) {
initial.commit09911bf2008-07-26 23:55:29266 DCHECK(routing_id != MSG_ROUTING_NONE);
[email protected]2fab253a2009-08-17 23:00:59267 scoped_refptr<RenderView> view = new RenderView(render_thread, webkit_prefs);
initial.commit09911bf2008-07-26 23:55:29268 view->Init(parent_hwnd,
initial.commit09911bf2008-07-26 23:55:29269 opener_id,
[email protected]80d96fa2009-06-10 22:34:51270 renderer_prefs,
[email protected]0aa55312008-10-17 21:53:08271 counter,
initial.commit09911bf2008-07-26 23:55:29272 routing_id); // adds reference
273 return view;
274}
275
276/*static*/
277void RenderView::SetNextPageID(int32 next_page_id) {
278 // This method should only be called during process startup, and the given
279 // page id had better not exceed our current next page id!
[email protected]4646f292009-05-20 03:49:05280 DCHECK_EQ(next_page_id_, 1);
initial.commit09911bf2008-07-26 23:55:29281 DCHECK(next_page_id >= next_page_id_);
282 next_page_id_ = next_page_id;
283}
284
[email protected]1dbafaf72009-09-23 19:43:56285void RenderView::UserMetricsRecordAction(const std::wstring& action) {
286 Send(new ViewHostMsg_UserMetricsRecordAction(routing_id_, action));
287}
288
[email protected]fb466342009-07-15 00:43:08289void RenderView::PluginCrashed(base::ProcessId pid,
290 const FilePath& plugin_path) {
291 Send(new ViewHostMsg_CrashedPlugin(routing_id_, pid, plugin_path));
initial.commit09911bf2008-07-26 23:55:29292}
293
[email protected]18bcc3c2009-01-27 21:39:15294void RenderView::Init(gfx::NativeViewId parent_hwnd,
initial.commit09911bf2008-07-26 23:55:29295 int32 opener_id,
[email protected]80d96fa2009-06-10 22:34:51296 const RendererPreferences& renderer_prefs,
[email protected]0aa55312008-10-17 21:53:08297 SharedRenderViewCounter* counter,
initial.commit09911bf2008-07-26 23:55:29298 int32 routing_id) {
299 DCHECK(!webview());
300
301 if (opener_id != MSG_ROUTING_NONE)
302 opener_id_ = opener_id;
303
[email protected]0aa55312008-10-17 21:53:08304 if (counter) {
305 shared_popup_counter_ = counter;
306 shared_popup_counter_->data++;
307 decrement_shared_popup_at_destruction_ = true;
308 } else {
309 shared_popup_counter_ = new SharedRenderViewCounter(0);
310 decrement_shared_popup_at_destruction_ = false;
311 }
312
[email protected]58bfc6b2009-06-24 09:45:02313 devtools_agent_.reset(new DevToolsAgent(routing_id, this));
[email protected]9b9d7282009-04-08 14:13:04314
[email protected]04fc9482009-09-18 22:13:03315 webwidget_ = WebView::Create(this);
[email protected]2fab253a2009-08-17 23:00:59316 webkit_preferences_.Apply(webview());
[email protected]b4bb2502009-10-01 22:35:27317 webview()->initializeMainFrame(this);
initial.commit09911bf2008-07-26 23:55:29318
[email protected]d3ba77272009-09-03 00:06:09319 OnSetRendererPrefs(renderer_prefs);
320
initial.commit09911bf2008-07-26 23:55:29321 routing_id_ = routing_id;
[email protected]81a34412009-01-05 19:17:24322 render_thread_->AddRoute(routing_id_, this);
initial.commit09911bf2008-07-26 23:55:29323 // Take a reference on behalf of the RenderThread. This will be balanced
324 // when we receive ViewMsg_Close.
325 AddRef();
326
327 // If this is a popup, we must wait for the CreatingNew_ACK message before
328 // completing initialization. Otherwise, we can finish it now.
329 if (opener_id == MSG_ROUTING_NONE) {
330 did_show_ = true;
331 CompleteInit(parent_hwnd);
332 }
333
334 host_window_ = parent_hwnd;
initial.commit09911bf2008-07-26 23:55:29335
[email protected]58bfc6b2009-06-24 09:45:02336 const CommandLine& command_line = *CommandLine::ForCurrentProcess();
[email protected]81e63782009-02-27 19:35:09337 if (command_line.HasSwitch(switches::kDomAutomationController))
338 enabled_bindings_ |= BindingsPolicy::DOM_AUTOMATION;
initial.commit09911bf2008-07-26 23:55:29339
[email protected]5fb88962009-04-16 19:03:25340 audio_message_filter_ = new AudioMessageFilter(routing_id_);
341 render_thread_->AddFilter(audio_message_filter_);
initial.commit09911bf2008-07-26 23:55:29342}
343
344void RenderView::OnMessageReceived(const IPC::Message& message) {
[email protected]26aa0482009-09-30 16:55:27345 WebFrame* main_frame = webview() ? webview()->mainFrame() : NULL;
[email protected]ef916272009-07-08 21:40:55346 child_process_logging::ScopedActiveURLSetter url_setter(
[email protected]dd7daa82009-08-10 05:46:45347 main_frame ? main_frame->url() : WebURL());
[email protected]f8b6b6f2009-03-10 16:48:26348
[email protected]b2abac72009-02-26 12:39:28349 // If this is developer tools renderer intercept tools messages first.
[email protected]e4ac5df2009-03-17 15:33:11350 if (devtools_client_.get() && devtools_client_->OnMessageReceived(message))
[email protected]b2abac72009-02-26 12:39:28351 return;
[email protected]b4b967e2009-04-22 11:33:05352 if (devtools_agent_.get() && devtools_agent_->OnMessageReceived(message))
353 return;
[email protected]b2abac72009-02-26 12:39:28354
initial.commit09911bf2008-07-26 23:55:29355 IPC_BEGIN_MESSAGE_MAP(RenderView, message)
initial.commit09911bf2008-07-26 23:55:29356 IPC_MESSAGE_HANDLER(ViewMsg_CaptureThumbnail, SendThumbnail)
initial.commit09911bf2008-07-26 23:55:29357 IPC_MESSAGE_HANDLER(ViewMsg_PrintPages, OnPrintPages)
[email protected]82270452009-06-19 15:58:01358 IPC_MESSAGE_HANDLER(ViewMsg_PrintingDone, OnPrintingDone)
initial.commit09911bf2008-07-26 23:55:29359 IPC_MESSAGE_HANDLER(ViewMsg_Navigate, OnNavigate)
360 IPC_MESSAGE_HANDLER(ViewMsg_Stop, OnStop)
361 IPC_MESSAGE_HANDLER(ViewMsg_LoadAlternateHTMLText, OnLoadAlternateHTMLText)
362 IPC_MESSAGE_HANDLER(ViewMsg_StopFinding, OnStopFinding)
363 IPC_MESSAGE_HANDLER(ViewMsg_Undo, OnUndo)
364 IPC_MESSAGE_HANDLER(ViewMsg_Redo, OnRedo)
365 IPC_MESSAGE_HANDLER(ViewMsg_Cut, OnCut)
366 IPC_MESSAGE_HANDLER(ViewMsg_Copy, OnCopy)
[email protected]c0cc3092009-09-12 08:27:27367#if defined(OS_MACOSX)
[email protected]a954bf72009-09-12 07:30:35368 IPC_MESSAGE_HANDLER(ViewMsg_CopyToFindPboard, OnCopyToFindPboard)
[email protected]c0cc3092009-09-12 08:27:27369#endif
initial.commit09911bf2008-07-26 23:55:29370 IPC_MESSAGE_HANDLER(ViewMsg_Paste, OnPaste)
371 IPC_MESSAGE_HANDLER(ViewMsg_Replace, OnReplace)
[email protected]98324892009-09-09 21:16:05372 IPC_MESSAGE_HANDLER(ViewMsg_ToggleSpellPanel, OnToggleSpellPanel)
373 IPC_MESSAGE_HANDLER(ViewMsg_AdvanceToNextMisspelling,
374 OnAdvanceToNextMisspelling)
[email protected]bbbd545c2008-12-15 20:18:04375 IPC_MESSAGE_HANDLER(ViewMsg_ToggleSpellCheck, OnToggleSpellCheck)
initial.commit09911bf2008-07-26 23:55:29376 IPC_MESSAGE_HANDLER(ViewMsg_Delete, OnDelete)
377 IPC_MESSAGE_HANDLER(ViewMsg_SelectAll, OnSelectAll)
378 IPC_MESSAGE_HANDLER(ViewMsg_CopyImageAt, OnCopyImageAt)
[email protected]4b59ae602009-06-23 20:58:15379 IPC_MESSAGE_HANDLER(ViewMsg_ExecuteEditCommand, OnExecuteEditCommand)
initial.commit09911bf2008-07-26 23:55:29380 IPC_MESSAGE_HANDLER(ViewMsg_Find, OnFind)
[email protected]5c4266922009-07-10 16:41:27381 IPC_MESSAGE_HANDLER(ViewMsg_DeterminePageText, OnDeterminePageText)
[email protected]630e26b2008-10-14 22:55:17382 IPC_MESSAGE_HANDLER(ViewMsg_Zoom, OnZoom)
initial.commit09911bf2008-07-26 23:55:29383 IPC_MESSAGE_HANDLER(ViewMsg_SetPageEncoding, OnSetPageEncoding)
[email protected]a697f4c2009-09-14 22:30:18384 IPC_MESSAGE_HANDLER(ViewMsg_ResetPageEncodingToDefault,
385 OnResetPageEncodingToDefault)
[email protected]b2abac72009-02-26 12:39:28386 IPC_MESSAGE_HANDLER(ViewMsg_SetupDevToolsClient, OnSetupDevToolsClient)
[email protected]bf5c2ff392009-07-08 16:24:33387 IPC_MESSAGE_HANDLER(ViewMsg_DownloadFavIcon, OnDownloadFavIcon)
initial.commit09911bf2008-07-26 23:55:29388 IPC_MESSAGE_HANDLER(ViewMsg_ScriptEvalRequest, OnScriptEvalRequest)
[email protected]1810e132009-03-24 23:35:48389 IPC_MESSAGE_HANDLER(ViewMsg_CSSInsertRequest, OnCSSInsertRequest)
initial.commit09911bf2008-07-26 23:55:29390 IPC_MESSAGE_HANDLER(ViewMsg_AddMessageToConsole, OnAddMessageToConsole)
initial.commit09911bf2008-07-26 23:55:29391 IPC_MESSAGE_HANDLER(ViewMsg_ReservePageIDRange, OnReservePageIDRange)
392 IPC_MESSAGE_HANDLER(ViewMsg_UploadFile, OnUploadFileRequest)
393 IPC_MESSAGE_HANDLER(ViewMsg_FormFill, OnFormFill)
394 IPC_MESSAGE_HANDLER(ViewMsg_FillPasswordForm, OnFillPasswordForm)
395 IPC_MESSAGE_HANDLER(ViewMsg_DragTargetDragEnter, OnDragTargetDragEnter)
396 IPC_MESSAGE_HANDLER(ViewMsg_DragTargetDragOver, OnDragTargetDragOver)
397 IPC_MESSAGE_HANDLER(ViewMsg_DragTargetDragLeave, OnDragTargetDragLeave)
398 IPC_MESSAGE_HANDLER(ViewMsg_DragTargetDrop, OnDragTargetDrop)
[email protected]18cb2572008-08-21 20:34:45399 IPC_MESSAGE_HANDLER(ViewMsg_AllowBindings, OnAllowBindings)
initial.commit09911bf2008-07-26 23:55:29400 IPC_MESSAGE_HANDLER(ViewMsg_SetDOMUIProperty, OnSetDOMUIProperty)
[email protected]266eb6f2008-09-30 23:56:50401 IPC_MESSAGE_HANDLER(ViewMsg_DragSourceEndedOrMoved,
402 OnDragSourceEndedOrMoved)
initial.commit09911bf2008-07-26 23:55:29403 IPC_MESSAGE_HANDLER(ViewMsg_DragSourceSystemDragEnded,
404 OnDragSourceSystemDragEnded)
405 IPC_MESSAGE_HANDLER(ViewMsg_SetInitialFocus, OnSetInitialFocus)
406 IPC_MESSAGE_HANDLER(ViewMsg_FindReplyACK, OnFindReplyAck)
407 IPC_MESSAGE_HANDLER(ViewMsg_UpdateTargetURL_ACK, OnUpdateTargetURLAck)
408 IPC_MESSAGE_HANDLER(ViewMsg_UpdateWebPreferences, OnUpdateWebPreferences)
409 IPC_MESSAGE_HANDLER(ViewMsg_SetAltErrorPageURL, OnSetAltErrorPageURL)
410 IPC_MESSAGE_HANDLER(ViewMsg_InstallMissingPlugin, OnInstallMissingPlugin)
411 IPC_MESSAGE_HANDLER(ViewMsg_RunFileChooserResponse, OnFileChooserResponse)
412 IPC_MESSAGE_HANDLER(ViewMsg_EnableViewSourceMode, OnEnableViewSourceMode)
413 IPC_MESSAGE_HANDLER(ViewMsg_UpdateBackForwardListCount,
414 OnUpdateBackForwardListCount)
415 IPC_MESSAGE_HANDLER(ViewMsg_GetAllSavableResourceLinksForCurrentPage,
416 OnGetAllSavableResourceLinksForCurrentPage)
[email protected]f09c7182009-03-10 12:54:04417 IPC_MESSAGE_HANDLER(
418 ViewMsg_GetSerializedHtmlDataForCurrentPageWithLocalLinks,
419 OnGetSerializedHtmlDataForCurrentPageWithLocalLinks)
initial.commit09911bf2008-07-26 23:55:29420 IPC_MESSAGE_HANDLER(ViewMsg_GetApplicationInfo, OnGetApplicationInfo)
[email protected]266eb6f2008-09-30 23:56:50421 IPC_MESSAGE_HANDLER(ViewMsg_GetAccessibilityInfo, OnGetAccessibilityInfo)
422 IPC_MESSAGE_HANDLER(ViewMsg_ClearAccessibilityInfo,
423 OnClearAccessibilityInfo)
initial.commit09911bf2008-07-26 23:55:29424 IPC_MESSAGE_HANDLER(ViewMsg_ShouldClose, OnMsgShouldClose)
425 IPC_MESSAGE_HANDLER(ViewMsg_ClosePage, OnClosePage)
426 IPC_MESSAGE_HANDLER(ViewMsg_ThemeChanged, OnThemeChanged)
[email protected]18cb2572008-08-21 20:34:45427 IPC_MESSAGE_HANDLER(ViewMsg_HandleMessageFromExternalHost,
428 OnMessageFromExternalHost)
[email protected]0aa55312008-10-17 21:53:08429 IPC_MESSAGE_HANDLER(ViewMsg_DisassociateFromPopupCount,
430 OnDisassociateFromPopupCount)
[email protected]0ebf3872008-11-07 21:35:03431 IPC_MESSAGE_HANDLER(ViewMsg_AutofillSuggestions,
432 OnReceivedAutofillSuggestions)
[email protected]2c4410d2009-05-06 23:46:22433 IPC_MESSAGE_HANDLER(ViewMsg_PopupNotificationVisibilityChanged,
434 OnPopupNotificationVisibilityChanged)
[email protected]30f75e62009-02-25 22:01:00435 IPC_MESSAGE_HANDLER(ViewMsg_MoveOrResizeStarted, OnMoveOrResizeStarted)
[email protected]309d7a282009-03-24 09:18:27436 IPC_MESSAGE_HANDLER(ViewMsg_ExtensionResponse, OnExtensionResponse)
[email protected]7120f132009-07-20 21:05:37437 IPC_MESSAGE_HANDLER(ViewMsg_ExtensionMessageInvoke,
438 OnExtensionMessageInvoke)
[email protected]05d478752009-04-08 23:38:16439 IPC_MESSAGE_HANDLER(ViewMsg_ClearFocusedNode, OnClearFocusedNode)
[email protected]699ab0d2009-04-23 23:19:14440 IPC_MESSAGE_HANDLER(ViewMsg_SetBackground, OnSetBackground)
[email protected]0666aef2009-05-13 19:48:08441 IPC_MESSAGE_HANDLER(ViewMsg_EnableIntrinsicWidthChangedMode,
442 OnEnableIntrinsicWidthChangedMode)
[email protected]80d96fa2009-06-10 22:34:51443 IPC_MESSAGE_HANDLER(ViewMsg_SetRendererPrefs, OnSetRendererPrefs)
[email protected]7b291f92009-08-14 05:43:53444 IPC_MESSAGE_HANDLER(ViewMsg_UpdateBrowserWindowId,
445 OnUpdateBrowserWindowId)
446 IPC_MESSAGE_HANDLER(ViewMsg_NotifyRenderViewType,
447 OnNotifyRendererViewType)
[email protected]581b87eb2009-07-23 23:06:56448 IPC_MESSAGE_HANDLER(ViewMsg_MediaPlayerActionAt, OnMediaPlayerActionAt)
[email protected]8c66c5a2009-07-22 17:26:34449 IPC_MESSAGE_HANDLER(ViewMsg_SetActive, OnSetActive)
[email protected]446705872009-09-10 07:22:48450 IPC_MESSAGE_HANDLER(ViewMsg_SetEditCommandsForNextKeyEvent,
451 OnSetEditCommandsForNextKeyEvent);
[email protected]912256b32009-09-18 09:47:35452 IPC_MESSAGE_HANDLER(ViewMsg_ExecuteCode,
453 OnExecuteCode)
[email protected]634a6f92008-12-01 21:39:31454
initial.commit09911bf2008-07-26 23:55:29455 // Have the super handle all other messages.
456 IPC_MESSAGE_UNHANDLED(RenderWidget::OnMessageReceived(message))
457 IPC_END_MESSAGE_MAP()
458}
459
initial.commit09911bf2008-07-26 23:55:29460void RenderView::SendThumbnail() {
[email protected]26aa0482009-09-30 16:55:27461 WebFrame* main_frame = webview()->mainFrame();
initial.commit09911bf2008-07-26 23:55:29462 if (!main_frame)
463 return;
464
465 // get the URL for this page
[email protected]dd7daa82009-08-10 05:46:45466 GURL url(main_frame->url());
initial.commit09911bf2008-07-26 23:55:29467 if (url.is_empty())
468 return;
469
470 if (size_.IsEmpty())
471 return; // Don't create an empty thumbnail!
472
473 ThumbnailScore score;
474 SkBitmap thumbnail;
[email protected]8649fb32009-06-26 17:51:02475 if (!CaptureThumbnail(webview(), kThumbnailWidth, kThumbnailHeight,
[email protected]b6e4bec2008-11-12 01:17:15476 &thumbnail, &score))
477 return;
478
initial.commit09911bf2008-07-26 23:55:29479 // send the thumbnail message to the browser process
[email protected]674741932009-02-04 23:44:46480 Send(new ViewHostMsg_Thumbnail(routing_id_, url, score, thumbnail));
initial.commit09911bf2008-07-26 23:55:29481}
482
[email protected]068637222009-01-29 16:58:07483void RenderView::OnPrintPages() {
initial.commit09911bf2008-07-26 23:55:29484 DCHECK(webview());
[email protected]aa82249f2009-07-16 17:23:58485 if (webview()) {
486 // If the user has selected text in the currently focused frame we print
487 // only that frame (this makes print selection work for multiple frames).
[email protected]26aa0482009-09-30 16:55:27488 if (webview()->focusedFrame()->hasSelection())
489 Print(webview()->focusedFrame(), false);
[email protected]aa82249f2009-07-16 17:23:58490 else
[email protected]26aa0482009-09-30 16:55:27491 Print(webview()->mainFrame(), false);
[email protected]aa82249f2009-07-16 17:23:58492 }
initial.commit09911bf2008-07-26 23:55:29493}
494
[email protected]82270452009-06-19 15:58:01495void RenderView::OnPrintingDone(int document_cookie, bool success) {
496 // Ignoring document cookie here since only one print job can be outstanding
497 // per renderer and document_cookie is 0 when printing is successful.
498 DCHECK(print_helper_.get());
499 if (print_helper_.get() != NULL) {
500 print_helper_->DidFinishPrinting(success);
501 }
502}
503
initial.commit09911bf2008-07-26 23:55:29504void RenderView::CapturePageInfo(int load_id, bool preliminary_capture) {
505 if (load_id != page_id_)
506 return; // this capture call is no longer relevant due to navigation
507 if (load_id == last_indexed_page_id_)
508 return; // we already indexed this page
509
510 if (!webview())
511 return;
512
[email protected]26aa0482009-09-30 16:55:27513 WebFrame* main_frame = webview()->mainFrame();
initial.commit09911bf2008-07-26 23:55:29514 if (!main_frame)
515 return;
516
517 // Don't index/capture pages that are in view source mode.
[email protected]dd7daa82009-08-10 05:46:45518 if (main_frame->isViewSourceModeEnabled())
initial.commit09911bf2008-07-26 23:55:29519 return;
520
521 // Don't index/capture pages that failed to load. This only checks the top
522 // level frame so the thumbnail may contain a frame that failed to load.
[email protected]dd7daa82009-08-10 05:46:45523 WebDataSource* ds = main_frame->dataSource();
[email protected]726985e22009-06-18 21:09:28524 if (ds && ds->hasUnreachableURL())
initial.commit09911bf2008-07-26 23:55:29525 return;
526
527 if (!preliminary_capture)
528 last_indexed_page_id_ = load_id;
529
530 // get the URL for this page
[email protected]dd7daa82009-08-10 05:46:45531 GURL url(main_frame->url());
initial.commit09911bf2008-07-26 23:55:29532 if (url.is_empty())
533 return;
534
535 // full text
536 std::wstring contents;
537 CaptureText(main_frame, &contents);
538 if (contents.size()) {
539 // Send the text to the browser for indexing.
540 Send(new ViewHostMsg_PageContents(url, load_id, contents));
541 }
542
[email protected]5c4266922009-07-10 16:41:27543 // Send over text content of this page to the browser.
544 if (determine_page_text_after_loading_stops_) {
545 determine_page_text_after_loading_stops_ = false;
546 Send(new ViewMsg_DeterminePageText_Reply(routing_id_, contents));
547 }
548
initial.commit09911bf2008-07-26 23:55:29549 // thumbnail
550 SendThumbnail();
551}
552
553void RenderView::CaptureText(WebFrame* frame, std::wstring* contents) {
554 contents->clear();
555 if (!frame)
556 return;
557
[email protected]0faf0bd92008-09-09 20:53:27558 // Don't index any https pages. People generally don't want their bank
559 // accounts, etc. indexed on their computer, especially since some of these
560 // things are not marked cachable.
561 // TODO(brettw) we may want to consider more elaborate heuristics such as
562 // the cachability of the page. We may also want to consider subframes (this
563 // test will still index subframes if the subframe is SSL).
[email protected]dd7daa82009-08-10 05:46:45564 if (GURL(frame->url()).SchemeIsSecure())
[email protected]0faf0bd92008-09-09 20:53:27565 return;
566
initial.commit09911bf2008-07-26 23:55:29567#ifdef TIME_TEXT_RETRIEVAL
568 double begin = time_util::GetHighResolutionTimeNow();
569#endif
570
571 // get the contents of the frame
[email protected]dd7daa82009-08-10 05:46:45572 *contents = UTF16ToWideHack(frame->contentAsText(kMaxIndexChars));
initial.commit09911bf2008-07-26 23:55:29573
574#ifdef TIME_TEXT_RETRIEVAL
575 double end = time_util::GetHighResolutionTimeNow();
576 char buf[128];
577 sprintf_s(buf, "%d chars retrieved for indexing in %gms\n",
578 contents.size(), (end - begin)*1000);
579 OutputDebugStringA(buf);
580#endif
581
582 // When the contents are clipped to the maximum, we don't want to have a
583 // partial word indexed at the end that might have been clipped. Therefore,
584 // terminate the string at the last space to ensure no words are clipped.
585 if (contents->size() == kMaxIndexChars) {
586 size_t last_space_index = contents->find_last_of(kWhitespaceWide);
587 if (last_space_index == std::wstring::npos)
588 return; // don't index if we got a huge block of text with no spaces
589 contents->resize(last_space_index);
590 }
591}
592
[email protected]8649fb32009-06-26 17:51:02593bool RenderView::CaptureThumbnail(WebView* view,
initial.commit09911bf2008-07-26 23:55:29594 int w,
595 int h,
596 SkBitmap* thumbnail,
597 ThumbnailScore* score) {
598#ifdef TIME_BITMAP_RETRIEVAL
599 double begin = time_util::GetHighResolutionTimeNow();
600#endif
601
[email protected]4873c7d2009-07-16 06:36:28602 view->layout();
603 const WebSize& size = view->size();
[email protected]b6e4bec2008-11-12 01:17:15604
[email protected]8649fb32009-06-26 17:51:02605 skia::PlatformCanvas canvas;
606 if (!canvas.initialize(size.width, size.height, true))
607 return false;
[email protected]8c89e7792009-08-19 21:18:34608 view->paint(webkit_glue::ToWebCanvas(&canvas),
609 WebRect(0, 0, size.width, size.height));
[email protected]8649fb32009-06-26 17:51:02610
611 skia::BitmapPlatformDevice& device =
612 static_cast<skia::BitmapPlatformDevice&>(canvas.getTopPlatformDevice());
613
614 const SkBitmap& src_bmp = device.accessBitmap(false);
initial.commit09911bf2008-07-26 23:55:29615
[email protected]cab34d6a2009-09-24 01:14:52616 SkRect dest_rect = { 0, 0, SkIntToScalar(w), SkIntToScalar(h) };
initial.commit09911bf2008-07-26 23:55:29617 float dest_aspect = dest_rect.width() / dest_rect.height();
618
619 // Get the src rect so that we can preserve the aspect ratio while filling
620 // the destination.
621 SkIRect src_rect;
622 if (src_bmp.width() < dest_rect.width() ||
623 src_bmp.height() < dest_rect.height()) {
624 // Source image is smaller: we clip the part of source image within the
625 // dest rect, and then stretch it to fill the dest rect. We don't respect
626 // the aspect ratio in this case.
627 src_rect.set(0, 0, static_cast<S16CPU>(dest_rect.width()),
628 static_cast<S16CPU>(dest_rect.height()));
629 score->good_clipping = false;
630 } else {
631 float src_aspect = static_cast<float>(src_bmp.width()) / src_bmp.height();
632 if (src_aspect > dest_aspect) {
633 // Wider than tall, clip horizontally: we center the smaller thumbnail in
634 // the wider screen.
635 S16CPU new_width = static_cast<S16CPU>(src_bmp.height() * dest_aspect);
636 S16CPU x_offset = (src_bmp.width() - new_width) / 2;
637 src_rect.set(x_offset, 0, new_width + x_offset, src_bmp.height());
638 score->good_clipping = false;
639 } else {
640 src_rect.set(0, 0, src_bmp.width(),
641 static_cast<S16CPU>(src_bmp.width() / dest_aspect));
642 score->good_clipping = true;
643 }
644 }
645
[email protected]26aa0482009-09-30 16:55:27646 score->at_top = (view->mainFrame()->scrollOffset().height == 0);
initial.commit09911bf2008-07-26 23:55:29647
648 SkBitmap subset;
[email protected]8649fb32009-06-26 17:51:02649 device.accessBitmap(false).extractSubset(&subset, src_rect);
initial.commit09911bf2008-07-26 23:55:29650
651 // Resample the subset that we want to get it the right size.
[email protected]465b34b72008-12-12 20:19:14652 *thumbnail = skia::ImageOperations::Resize(
653 subset, skia::ImageOperations::RESIZE_LANCZOS3, w, h);
initial.commit09911bf2008-07-26 23:55:29654
655 score->boring_score = CalculateBoringScore(thumbnail);
656
657#ifdef TIME_BITMAP_RETRIEVAL
658 double end = time_util::GetHighResolutionTimeNow();
659 char buf[128];
660 sprintf_s(buf, "thumbnail in %gms\n", (end - begin) * 1000);
661 OutputDebugStringA(buf);
662#endif
[email protected]b6e4bec2008-11-12 01:17:15663 return true;
initial.commit09911bf2008-07-26 23:55:29664}
665
666double RenderView::CalculateBoringScore(SkBitmap* bitmap) {
667 int histogram[256] = {0};
668 color_utils::BuildLumaHistogram(bitmap, histogram);
669
670 int color_count = *std::max_element(histogram, histogram + 256);
671 int pixel_count = bitmap->width() * bitmap->height();
672 return static_cast<double>(color_count) / pixel_count;
673}
674
675void RenderView::OnNavigate(const ViewMsg_Navigate_Params& params) {
676 if (!webview())
677 return;
678
[email protected]8c785c62009-07-13 14:20:15679 if (devtools_agent_.get())
680 devtools_agent_->OnNavigate();
681
[email protected]ef916272009-07-08 21:40:55682 child_process_logging::ScopedActiveURLSetter url_setter(params.url);
[email protected]f8b6b6f2009-03-10 16:48:26683
initial.commit09911bf2008-07-26 23:55:29684 AboutHandler::MaybeHandle(params.url);
685
686 bool is_reload = params.reload;
687
[email protected]26aa0482009-09-30 16:55:27688 WebFrame* main_frame = webview()->mainFrame();
[email protected]dd7daa82009-08-10 05:46:45689 if (is_reload && main_frame->currentHistoryItem().isNull()) {
initial.commit09911bf2008-07-26 23:55:29690 // We cannot reload if we do not have any history state. This happens, for
691 // example, when recovering from a crash. Our workaround here is a bit of
692 // a hack since it means that reload after a crashed tab does not cause an
693 // end-to-end cache validation.
694 is_reload = false;
695 }
696
[email protected]77f17a82009-05-21 04:42:54697 // A navigation resulting from loading a javascript URL should not be treated
698 // as a browser initiated event. Instead, we want it to look as if the page
699 // initiated any load resulting from JS execution.
700 if (!params.url.SchemeIs(chrome::kJavaScriptScheme)) {
[email protected]daa8c58e2009-06-15 17:21:10701 pending_navigation_state_.reset(NavigationState::CreateBrowserInitiated(
[email protected]77f17a82009-05-21 04:42:54702 params.page_id, params.transition, params.request_time));
703 }
initial.commit09911bf2008-07-26 23:55:29704
[email protected]04d3c6e2009-05-22 17:00:13705 // If we are reloading, then WebKit will use the history state of the current
706 // page, so we should just ignore any given history state. Otherwise, if we
707 // have history state, then we need to navigate to it, which corresponds to a
708 // back/forward navigation event.
[email protected]e6f546c32009-07-01 17:12:55709 if (is_reload) {
[email protected]dd7daa82009-08-10 05:46:45710 main_frame->reload();
[email protected]e6f546c32009-07-01 17:12:55711 } else if (!params.state.empty()) {
[email protected]04d3c6e2009-05-22 17:00:13712 // We must know the page ID of the page we are navigating back to.
[email protected]f929f2f22009-06-12 16:56:58713 DCHECK_NE(params.page_id, -1);
[email protected]dd7daa82009-08-10 05:46:45714 main_frame->loadHistoryItem(
[email protected]ca948a22009-06-25 19:36:17715 webkit_glue::HistoryItemFromString(params.state));
[email protected]04d3c6e2009-05-22 17:00:13716 } else {
717 // Navigate to the given URL.
[email protected]726985e22009-06-18 21:09:28718 WebURLRequest request(params.url);
initial.commit09911bf2008-07-26 23:55:29719
[email protected]e6f546c32009-07-01 17:12:55720 // A session history navigation should have been accompanied by state.
721 DCHECK_EQ(params.page_id, -1);
[email protected]04d3c6e2009-05-22 17:00:13722
[email protected]dd7daa82009-08-10 05:46:45723 if (main_frame->isViewSourceModeEnabled())
[email protected]e6f546c32009-07-01 17:12:55724 request.setCachePolicy(WebURLRequest::ReturnCacheDataElseLoad);
[email protected]04d3c6e2009-05-22 17:00:13725
[email protected]726985e22009-06-18 21:09:28726 if (params.referrer.is_valid()) {
727 request.setHTTPHeaderField(WebString::fromUTF8("Referer"),
728 WebString::fromUTF8(params.referrer.spec()));
729 }
[email protected]04d3c6e2009-05-22 17:00:13730
[email protected]dd7daa82009-08-10 05:46:45731 main_frame->loadRequest(request);
[email protected]c0588052008-10-27 23:01:50732 }
733
[email protected]77f17a82009-05-21 04:42:54734 // In case LoadRequest failed before DidCreateDataSource was called.
735 pending_navigation_state_.reset();
initial.commit09911bf2008-07-26 23:55:29736}
737
738// Stop loading the current page
739void RenderView::OnStop() {
740 if (webview())
[email protected]b4bb2502009-10-01 22:35:27741 webview()->mainFrame()->stopLoading();
initial.commit09911bf2008-07-26 23:55:29742}
743
[email protected]e6f546c32009-07-01 17:12:55744void RenderView::OnLoadAlternateHTMLText(const std::string& html,
initial.commit09911bf2008-07-26 23:55:29745 bool new_navigation,
746 const GURL& display_url,
747 const std::string& security_info) {
748 if (!webview())
749 return;
750
[email protected]e6f546c32009-07-01 17:12:55751 pending_navigation_state_.reset(NavigationState::CreateBrowserInitiated(
752 new_navigation ? -1 : page_id_, PageTransition::LINK, Time::Now()));
753 pending_navigation_state_->set_security_info(security_info);
initial.commit09911bf2008-07-26 23:55:29754
[email protected]26aa0482009-09-30 16:55:27755 webview()->mainFrame()->loadHTMLString(
756 html, GURL(kUnreachableWebDataURL), display_url, !new_navigation);
[email protected]e6f546c32009-07-01 17:12:55757
758 pending_navigation_state_.reset();
initial.commit09911bf2008-07-26 23:55:29759}
760
761void RenderView::OnCopyImageAt(int x, int y) {
[email protected]26aa0482009-09-30 16:55:27762 webview()->copyImageAt(WebPoint(x, y));
initial.commit09911bf2008-07-26 23:55:29763}
764
[email protected]68b1e922009-06-23 16:00:25765void RenderView::OnExecuteEditCommand(const std::string& name,
766 const std::string& value) {
[email protected]26aa0482009-09-30 16:55:27767 if (!webview() || !webview()->focusedFrame())
[email protected]68b1e922009-06-23 16:00:25768 return;
769
[email protected]26aa0482009-09-30 16:55:27770 webview()->focusedFrame()->executeCommand(
[email protected]dd7daa82009-08-10 05:46:45771 WebString::fromUTF8(name), WebString::fromUTF8(value));
[email protected]68b1e922009-06-23 16:00:25772}
773
[email protected]b2abac72009-02-26 12:39:28774void RenderView::OnSetupDevToolsClient() {
[email protected]e4ac5df2009-03-17 15:33:11775 DCHECK(!devtools_client_.get());
776 devtools_client_.reset(new DevToolsClient(this));
[email protected]b2abac72009-02-26 12:39:28777}
778
initial.commit09911bf2008-07-26 23:55:29779void RenderView::OnStopFinding(bool clear_selection) {
780 WebView* view = webview();
781 if (!view)
782 return;
783
784 if (clear_selection)
[email protected]26aa0482009-09-30 16:55:27785 view->focusedFrame()->executeCommand(WebString::fromUTF8("Unselect"));
initial.commit09911bf2008-07-26 23:55:29786
[email protected]26aa0482009-09-30 16:55:27787 WebFrame* frame = view->mainFrame();
initial.commit09911bf2008-07-26 23:55:29788 while (frame) {
[email protected]dd7daa82009-08-10 05:46:45789 frame->stopFinding(clear_selection);
[email protected]b4bb2502009-10-01 22:35:27790 frame = frame->traverseNext(false);
initial.commit09911bf2008-07-26 23:55:29791 }
792}
793
794void RenderView::OnFindReplyAck() {
795 // Check if there is any queued up request waiting to be sent.
796 if (queued_find_reply_message_.get()) {
797 // Send the search result over to the browser process.
798 Send(queued_find_reply_message_.get());
799 queued_find_reply_message_.release();
800 }
801}
802
803void RenderView::OnUpdateTargetURLAck() {
804 // Check if there is a targeturl waiting to be sent.
805 if (target_url_status_ == TARGET_PENDING) {
806 Send(new ViewHostMsg_UpdateTargetURL(routing_id_, page_id_,
807 pending_target_url_));
808 }
809
810 target_url_status_ = TARGET_NONE;
811}
812
813void RenderView::OnUndo() {
814 if (!webview())
815 return;
816
[email protected]26aa0482009-09-30 16:55:27817 webview()->focusedFrame()->executeCommand(WebString::fromUTF8("Undo"));
[email protected]dd7daa82009-08-10 05:46:45818 UserMetricsRecordAction(L"Undo");
initial.commit09911bf2008-07-26 23:55:29819}
820
821void RenderView::OnRedo() {
822 if (!webview())
823 return;
824
[email protected]26aa0482009-09-30 16:55:27825 webview()->focusedFrame()->executeCommand(WebString::fromUTF8("Redo"));
[email protected]dd7daa82009-08-10 05:46:45826 UserMetricsRecordAction(L"Redo");
initial.commit09911bf2008-07-26 23:55:29827}
828
829void RenderView::OnCut() {
830 if (!webview())
831 return;
832
[email protected]26aa0482009-09-30 16:55:27833 webview()->focusedFrame()->executeCommand(WebString::fromUTF8("Cut"));
[email protected]dd7daa82009-08-10 05:46:45834 UserMetricsRecordAction(L"Cut");
initial.commit09911bf2008-07-26 23:55:29835}
836
837void RenderView::OnCopy() {
838 if (!webview())
839 return;
840
[email protected]26aa0482009-09-30 16:55:27841 webview()->focusedFrame()->executeCommand(WebString::fromUTF8("Copy"));
[email protected]dd7daa82009-08-10 05:46:45842 UserMetricsRecordAction(L"Copy");
initial.commit09911bf2008-07-26 23:55:29843}
844
[email protected]c0cc3092009-09-12 08:27:27845#if defined(OS_MACOSX)
[email protected]a954bf72009-09-12 07:30:35846void RenderView::OnCopyToFindPboard() {
847 if (!webview())
848 return;
849
850 // Since the find pasteboard supports only plain text, this can be simpler
851 // than the |OnCopy()| case.
[email protected]26aa0482009-09-30 16:55:27852 WebFrame* frame = webview()->focusedFrame();
[email protected]a954bf72009-09-12 07:30:35853 if (frame->hasSelection()) {
854 string16 selection = frame->selectionAsText();
855 RenderThread::current()->Send(
856 new ViewHostMsg_ClipboardFindPboardWriteStringAsync(selection));
857 }
858
859 UserMetricsRecordAction(L"CopyToFindPboard");
860}
[email protected]c0cc3092009-09-12 08:27:27861#endif
[email protected]a954bf72009-09-12 07:30:35862
initial.commit09911bf2008-07-26 23:55:29863void RenderView::OnPaste() {
864 if (!webview())
865 return;
866
[email protected]26aa0482009-09-30 16:55:27867 webview()->focusedFrame()->executeCommand(WebString::fromUTF8("Paste"));
[email protected]dd7daa82009-08-10 05:46:45868 UserMetricsRecordAction(L"Paste");
initial.commit09911bf2008-07-26 23:55:29869}
870
871void RenderView::OnReplace(const std::wstring& text) {
872 if (!webview())
873 return;
874
[email protected]26aa0482009-09-30 16:55:27875 webview()->focusedFrame()->replaceSelection(WideToUTF16Hack(text));
initial.commit09911bf2008-07-26 23:55:29876}
877
[email protected]98324892009-09-09 21:16:05878void RenderView::OnAdvanceToNextMisspelling() {
879 if (!webview())
880 return;
[email protected]26aa0482009-09-30 16:55:27881 webview()->focusedFrame()->executeCommand(
[email protected]98324892009-09-09 21:16:05882 WebString::fromUTF8("AdvanceToNextMisspelling"));
883}
884
885void RenderView::OnToggleSpellPanel(bool is_currently_visible) {
886 if (!webview())
887 return;
888 // We need to tell the webView whether the spelling panel is visible or not so
889 // that it won't need to make ipc calls later.
890 webview()->SetSpellingPanelVisibility(is_currently_visible);
[email protected]26aa0482009-09-30 16:55:27891 webview()->focusedFrame()->executeCommand(
[email protected]98324892009-09-09 21:16:05892 WebString::fromUTF8("ToggleSpellPanel"));
893}
894
[email protected]bbbd545c2008-12-15 20:18:04895void RenderView::OnToggleSpellCheck() {
896 if (!webview())
897 return;
898
[email protected]26aa0482009-09-30 16:55:27899 WebFrame* frame = webview()->focusedFrame();
[email protected]dd7daa82009-08-10 05:46:45900 frame->enableContinuousSpellChecking(
901 !frame->isContinuousSpellCheckingEnabled());
[email protected]bbbd545c2008-12-15 20:18:04902}
903
initial.commit09911bf2008-07-26 23:55:29904void RenderView::OnDelete() {
905 if (!webview())
906 return;
907
[email protected]26aa0482009-09-30 16:55:27908 webview()->focusedFrame()->executeCommand(WebString::fromUTF8("Delete"));
[email protected]dd7daa82009-08-10 05:46:45909 UserMetricsRecordAction(L"DeleteSelection");
initial.commit09911bf2008-07-26 23:55:29910}
911
912void RenderView::OnSelectAll() {
913 if (!webview())
914 return;
915
[email protected]26aa0482009-09-30 16:55:27916 webview()->focusedFrame()->executeCommand(
[email protected]a100d76bb2009-08-14 17:50:22917 WebString::fromUTF8("SelectAll"));
918 UserMetricsRecordAction(L"SelectAll");
initial.commit09911bf2008-07-26 23:55:29919}
920
921void RenderView::OnSetInitialFocus(bool reverse) {
922 if (!webview())
923 return;
[email protected]26aa0482009-09-30 16:55:27924 webview()->setInitialFocus(reverse);
initial.commit09911bf2008-07-26 23:55:29925}
926
927///////////////////////////////////////////////////////////////////////////////
928
929// Tell the embedding application that the URL of the active page has changed
930void RenderView::UpdateURL(WebFrame* frame) {
[email protected]dd7daa82009-08-10 05:46:45931 WebDataSource* ds = frame->dataSource();
initial.commit09911bf2008-07-26 23:55:29932 DCHECK(ds);
933
[email protected]726985e22009-06-18 21:09:28934 const WebURLRequest& request = ds->request();
935 const WebURLRequest& original_request = ds->originalRequest();
936 const WebURLResponse& response = ds->response();
initial.commit09911bf2008-07-26 23:55:29937
[email protected]daa8c58e2009-06-15 17:21:10938 NavigationState* navigation_state = NavigationState::FromDataSource(ds);
939 DCHECK(navigation_state);
initial.commit09911bf2008-07-26 23:55:29940
941 ViewHostMsg_FrameNavigate_Params params;
[email protected]726985e22009-06-18 21:09:28942 params.http_status_code = response.httpStatusCode();
initial.commit09911bf2008-07-26 23:55:29943 params.is_post = false;
944 params.page_id = page_id_;
[email protected]726985e22009-06-18 21:09:28945 params.is_content_filtered = response.isContentFiltered();
[email protected]e6f546c32009-07-01 17:12:55946 if (!navigation_state->security_info().empty()) {
initial.commit09911bf2008-07-26 23:55:29947 // SSL state specified in the request takes precedence over the one in the
948 // response.
949 // So far this is only intended for error pages that are not expected to be
950 // over ssl, so we should not get any clash.
[email protected]726985e22009-06-18 21:09:28951 DCHECK(response.securityInfo().isEmpty());
[email protected]e6f546c32009-07-01 17:12:55952 params.security_info = navigation_state->security_info();
initial.commit09911bf2008-07-26 23:55:29953 } else {
[email protected]726985e22009-06-18 21:09:28954 params.security_info = response.securityInfo();
initial.commit09911bf2008-07-26 23:55:29955 }
956
957 // Set the URL to be displayed in the browser UI to the user.
[email protected]726985e22009-06-18 21:09:28958 if (ds->hasUnreachableURL()) {
959 params.url = ds->unreachableURL();
initial.commit09911bf2008-07-26 23:55:29960 } else {
[email protected]726985e22009-06-18 21:09:28961 params.url = request.url();
initial.commit09911bf2008-07-26 23:55:29962 }
963
[email protected]726985e22009-06-18 21:09:28964 GetRedirectChain(ds, &params.redirects);
965 params.should_update_history = !ds->hasUnreachableURL();
initial.commit09911bf2008-07-26 23:55:29966
967 const SearchableFormData* searchable_form_data =
[email protected]daa8c58e2009-06-15 17:21:10968 navigation_state->searchable_form_data();
initial.commit09911bf2008-07-26 23:55:29969 if (searchable_form_data) {
970 params.searchable_form_url = searchable_form_data->url();
971 params.searchable_form_element_name = searchable_form_data->element_name();
972 params.searchable_form_encoding = searchable_form_data->encoding();
973 }
974
975 const PasswordForm* password_form_data =
[email protected]daa8c58e2009-06-15 17:21:10976 navigation_state->password_form_data();
initial.commit09911bf2008-07-26 23:55:29977 if (password_form_data)
978 params.password_form = *password_form_data;
979
980 params.gesture = navigation_gesture_;
981 navigation_gesture_ = NavigationGestureUnknown;
982
[email protected]dd7daa82009-08-10 05:46:45983 if (!frame->parent()) {
initial.commit09911bf2008-07-26 23:55:29984 // Top-level navigation.
985
986 // Update contents MIME type for main frame.
[email protected]9c5645b2009-08-11 03:37:55987 params.contents_mime_type = ds->response().mimeType().utf8();
initial.commit09911bf2008-07-26 23:55:29988
[email protected]daa8c58e2009-06-15 17:21:10989 params.transition = navigation_state->transition_type();
initial.commit09911bf2008-07-26 23:55:29990 if (!PageTransition::IsMainFrame(params.transition)) {
991 // If the main frame does a load, it should not be reported as a subframe
992 // navigation. This can occur in the following case:
993 // 1. You're on a site with frames.
994 // 2. You do a subframe navigation. This is stored with transition type
995 // MANUAL_SUBFRAME.
996 // 3. You navigate to some non-frame site, say, google.com.
997 // 4. You navigate back to the page from step 2. Since it was initially
998 // MANUAL_SUBFRAME, it will be that same transition type here.
999 // We don't want that, because any navigation that changes the toplevel
1000 // frame should be tracked as a toplevel navigation (this allows us to
1001 // update the URL bar, etc).
1002 params.transition = PageTransition::LINK;
1003 }
1004
initial.commit09911bf2008-07-26 23:55:291005 // If we have a valid consumed client redirect source,
1006 // the page contained a client redirect (meta refresh, document.loc...),
1007 // so we set the referrer and transition to match.
1008 if (completed_client_redirect_src_.is_valid()) {
[email protected]77e09a92008-08-01 18:11:041009 DCHECK(completed_client_redirect_src_ == params.redirects[0]);
initial.commit09911bf2008-07-26 23:55:291010 params.referrer = completed_client_redirect_src_;
1011 params.transition = static_cast<PageTransition::Type>(
1012 params.transition | PageTransition::CLIENT_REDIRECT);
1013 } else {
1014 // Bug 654101: the referrer will be empty on https->http transitions. It
1015 // would be nice if we could get the real referrer from somewhere.
[email protected]726985e22009-06-18 21:09:281016 params.referrer = GURL(
1017 original_request.httpHeaderField(WebString::fromUTF8("Referer")));
initial.commit09911bf2008-07-26 23:55:291018 }
1019
[email protected]726985e22009-06-18 21:09:281020 string16 method = request.httpMethod();
1021 if (EqualsASCII(method, "POST"))
initial.commit09911bf2008-07-26 23:55:291022 params.is_post = true;
1023
[email protected]c2a797d2009-09-21 16:46:321024 // Save some histogram data so we can compute the average memory used per
1025 // page load of the glyphs.
1026 UMA_HISTOGRAM_COUNTS_10000("Memory.GlyphPagesPerLoad",
1027 webkit_glue::GetGlyphPageCount());
1028
initial.commit09911bf2008-07-26 23:55:291029 Send(new ViewHostMsg_FrameNavigate(routing_id_, params));
1030 } else {
1031 // Subframe navigation: the type depends on whether this navigation
1032 // generated a new session history entry. When they do generate a session
1033 // history entry, it means the user initiated the navigation and we should
1034 // mark it as such. This test checks if this is the first time UpdateURL
1035 // has been called since WillNavigateToURL was called to initiate the load.
1036 if (page_id_ > last_page_id_sent_to_browser_)
1037 params.transition = PageTransition::MANUAL_SUBFRAME;
1038 else
1039 params.transition = PageTransition::AUTO_SUBFRAME;
1040
initial.commit09911bf2008-07-26 23:55:291041 Send(new ViewHostMsg_FrameNavigate(routing_id_, params));
1042 }
1043
1044 last_page_id_sent_to_browser_ =
1045 std::max(last_page_id_sent_to_browser_, page_id_);
1046
1047 // If we end up reusing this WebRequest (for example, due to a #ref click),
[email protected]daa8c58e2009-06-15 17:21:101048 // we don't want the transition type to persist. Just clear it.
1049 navigation_state->set_transition_type(PageTransition::LINK);
[email protected]266eb6f2008-09-30 23:56:501050
[email protected]6c8afae52009-01-22 02:24:571051#if defined(OS_WIN)
[email protected]6a983b42009-03-20 20:12:251052 if (web_accessibility_manager_.get()) {
[email protected]be645db2009-02-06 20:36:331053 // Clear accessibility info cache.
[email protected]6a983b42009-03-20 20:12:251054 web_accessibility_manager_->ClearAccObjMap(-1, true);
[email protected]266eb6f2008-09-30 23:56:501055 }
[email protected]6c8afae52009-01-22 02:24:571056#else
[email protected]7d926f92009-03-03 14:26:541057 // TODO(port): accessibility not yet implemented. See http://crbug.com/8288.
[email protected]6c8afae52009-01-22 02:24:571058#endif
initial.commit09911bf2008-07-26 23:55:291059}
1060
1061// Tell the embedding application that the title of the active page has changed
[email protected]3d9689372009-09-10 04:29:171062void RenderView::UpdateTitle(WebFrame* frame, const string16& title) {
initial.commit09911bf2008-07-26 23:55:291063 // Ignore all but top level navigations...
[email protected]3d9689372009-09-10 04:29:171064 if (!frame->parent()) {
[email protected]f0af6a72009-05-30 05:25:171065 Send(new ViewHostMsg_UpdateTitle(
[email protected]3d9689372009-09-10 04:29:171066 routing_id_,
1067 page_id_,
1068 UTF16ToWideHack(title.length() > chrome::kMaxTitleChars ?
1069 title.substr(0, chrome::kMaxTitleChars) : title)));
[email protected]f0af6a72009-05-30 05:25:171070 }
initial.commit09911bf2008-07-26 23:55:291071}
1072
1073void RenderView::UpdateEncoding(WebFrame* frame,
[email protected]41fc0322009-09-04 22:23:401074 const std::string& encoding_name) {
initial.commit09911bf2008-07-26 23:55:291075 // Only update main frame's encoding_name.
[email protected]26aa0482009-09-30 16:55:271076 if (webview()->mainFrame() == frame &&
initial.commit09911bf2008-07-26 23:55:291077 last_encoding_name_ != encoding_name) {
[email protected]e38f40152008-09-12 23:08:301078 // Save the encoding name for later comparing.
initial.commit09911bf2008-07-26 23:55:291079 last_encoding_name_ = encoding_name;
1080
[email protected]e38f40152008-09-12 23:08:301081 Send(new ViewHostMsg_UpdateEncoding(routing_id_, last_encoding_name_));
initial.commit09911bf2008-07-26 23:55:291082 }
1083}
1084
[email protected]f4d34b52008-11-24 23:05:011085// Sends the previous session history state to the browser so it will be saved
1086// before we navigate to a new page. This must be called *before* the page ID
1087// has been updated so we know what it was.
initial.commit09911bf2008-07-26 23:55:291088void RenderView::UpdateSessionHistory(WebFrame* frame) {
1089 // If we have a valid page ID at this point, then it corresponds to the page
1090 // we are navigating away from. Otherwise, this is the first navigation, so
1091 // there is no past session history to record.
1092 if (page_id_ == -1)
1093 return;
1094
[email protected]ca948a22009-06-25 19:36:171095 const WebHistoryItem& item =
[email protected]26aa0482009-09-30 16:55:271096 webview()->mainFrame()->previousHistoryItem();
[email protected]ca948a22009-06-25 19:36:171097 if (item.isNull())
initial.commit09911bf2008-07-26 23:55:291098 return;
[email protected]ca948a22009-06-25 19:36:171099
1100 Send(new ViewHostMsg_UpdateState(
1101 routing_id_, page_id_, webkit_glue::HistoryItemToString(item)));
initial.commit09911bf2008-07-26 23:55:291102}
1103
[email protected]3d9689372009-09-10 04:29:171104void RenderView::OpenURL(
1105 const GURL& url, const GURL& referrer, WebNavigationPolicy policy) {
1106 Send(new ViewHostMsg_OpenURL(
1107 routing_id_, url, referrer, NavigationPolicyToDisposition(policy)));
1108}
1109
[email protected]79dbc662009-09-04 05:42:511110// WebViewDelegate ------------------------------------------------------------
initial.commit09911bf2008-07-26 23:55:291111
[email protected]a2f6bc112009-06-27 16:27:251112void RenderView::DidPaint() {
[email protected]26aa0482009-09-30 16:55:271113 WebFrame* main_frame = webview()->mainFrame();
[email protected]a2f6bc112009-06-27 16:27:251114
[email protected]dd7daa82009-08-10 05:46:451115 if (main_frame->provisionalDataSource()) {
[email protected]a2f6bc112009-06-27 16:27:251116 // If we have a provisional frame we are between the start
1117 // and commit stages of loading...ignore this paint.
1118 return;
1119 }
1120
[email protected]dd7daa82009-08-10 05:46:451121 WebDataSource* ds = main_frame->dataSource();
[email protected]a2f6bc112009-06-27 16:27:251122 NavigationState* navigation_state = NavigationState::FromDataSource(ds);
[email protected]78a3a6f2009-07-02 16:15:011123 DCHECK(navigation_state);
1124
1125 Time now = Time::Now();
1126 if (navigation_state->first_paint_time().is_null()) {
1127 navigation_state->set_first_paint_time(now);
1128 }
1129 if (navigation_state->first_paint_after_load_time().is_null() &&
1130 !navigation_state->finish_load_time().is_null()) {
1131 navigation_state->set_first_paint_after_load_time(now);
[email protected]a2f6bc112009-06-27 16:27:251132 }
1133}
1134
initial.commit09911bf2008-07-26 23:55:291135void RenderView::LoadNavigationErrorPage(WebFrame* frame,
[email protected]726985e22009-06-18 21:09:281136 const WebURLRequest& failed_request,
1137 const WebURLError& error,
initial.commit09911bf2008-07-26 23:55:291138 const std::string& html,
1139 bool replace) {
[email protected]726985e22009-06-18 21:09:281140 GURL failed_url = error.unreachableURL;
initial.commit09911bf2008-07-26 23:55:291141
1142 std::string alt_html;
1143 if (html.empty()) {
1144 // Use a local error page.
1145 int resource_id;
1146 DictionaryValue error_strings;
[email protected]726985e22009-06-18 21:09:281147 if (error.reason == net::ERR_CACHE_MISS &&
1148 EqualsASCII(failed_request.httpMethod(), "POST")) {
initial.commit09911bf2008-07-26 23:55:291149 GetFormRepostErrorValues(failed_url, &error_strings);
1150 resource_id = IDR_ERROR_NO_DETAILS_HTML;
1151 } else {
1152 GetLocalizedErrorValues(error, &error_strings);
1153 resource_id = IDR_NET_ERROR_HTML;
1154 }
[email protected]8e50b602009-03-03 22:59:431155 error_strings.SetString(L"textdirection",
1156 (l10n_util::GetTextDirection() == l10n_util::RIGHT_TO_LEFT) ?
1157 L"rtl" : L"ltr");
initial.commit09911bf2008-07-26 23:55:291158
1159 alt_html = GetAltHTMLForTemplate(error_strings, resource_id);
1160 } else {
1161 alt_html = html;
1162 }
1163
[email protected]dd7daa82009-08-10 05:46:451164 frame->loadHTMLString(alt_html,
[email protected]e6f546c32009-07-01 17:12:551165 GURL(kUnreachableWebDataURL),
1166 failed_url,
1167 replace);
initial.commit09911bf2008-07-26 23:55:291168}
1169
[email protected]7ccddb8c2009-08-04 17:36:551170void RenderView::BindDOMAutomationController(WebFrame* frame) {
initial.commit09911bf2008-07-26 23:55:291171 dom_automation_controller_.set_message_sender(this);
1172 dom_automation_controller_.set_routing_id(routing_id_);
[email protected]7ccddb8c2009-08-04 17:36:551173 dom_automation_controller_.BindToJavascript(frame,
initial.commit09911bf2008-07-26 23:55:291174 L"domAutomationController");
1175}
1176
[email protected]b6ce15972009-07-14 22:14:011177void RenderView::DidCreateScriptContextForFrame(WebFrame* webframe) {
[email protected]7120f132009-07-20 21:05:371178 EventBindings::HandleContextCreated(webframe, false);
[email protected]f816c012009-06-26 21:48:321179}
1180
[email protected]b6ce15972009-07-14 22:14:011181void RenderView::DidDestroyScriptContextForFrame(WebFrame* webframe) {
[email protected]f816c012009-06-26 21:48:321182 EventBindings::HandleContextDestroyed(webframe);
1183}
1184
[email protected]b6ce15972009-07-14 22:14:011185void RenderView::DidCreateIsolatedScriptContext(WebFrame* webframe) {
[email protected]7120f132009-07-20 21:05:371186 EventBindings::HandleContextCreated(webframe, true);
[email protected]b6ce15972009-07-14 22:14:011187}
1188
initial.commit09911bf2008-07-26 23:55:291189bool RenderView::RunJavaScriptMessage(int type,
1190 const std::wstring& message,
1191 const std::wstring& default_value,
[email protected]a455d3812009-03-05 20:18:071192 const GURL& frame_url,
initial.commit09911bf2008-07-26 23:55:291193 std::wstring* result) {
1194 bool success = false;
1195 std::wstring result_temp;
1196 if (!result)
1197 result = &result_temp;
initial.commit09911bf2008-07-26 23:55:291198
[email protected]12636df2009-09-28 22:32:211199 SendAndRunNestedMessageLoop(new ViewHostMsg_RunJavaScriptMessage(
1200 routing_id_, message, default_value, frame_url, type, &success, result));
initial.commit09911bf2008-07-26 23:55:291201 return success;
1202}
1203
1204void RenderView::AddGURLSearchProvider(const GURL& osd_url, bool autodetected) {
1205 if (!osd_url.is_empty())
1206 Send(new ViewHostMsg_PageHasOSDD(routing_id_, page_id_, osd_url,
1207 autodetected));
1208}
1209
[email protected]0ebf3872008-11-07 21:35:031210void RenderView::QueryFormFieldAutofill(const std::wstring& field_name,
1211 const std::wstring& text,
1212 int64 node_id) {
1213 static int message_id_counter = 0;
1214 form_field_autofill_request_id_ = message_id_counter++;
1215 Send(new ViewHostMsg_QueryFormFieldAutofill(routing_id_,
1216 field_name, text,
1217 node_id,
1218 form_field_autofill_request_id_));
1219}
1220
[email protected]4d2b6fb2009-03-20 22:28:171221void RenderView::RemoveStoredAutofillEntry(const std::wstring& name,
1222 const std::wstring& value) {
1223 Send(new ViewHostMsg_RemoveAutofillEntry(routing_id_, name, value));
1224}
1225
[email protected]0ebf3872008-11-07 21:35:031226void RenderView::OnReceivedAutofillSuggestions(
1227 int64 node_id,
1228 int request_id,
[email protected]8d0f15c2008-11-11 01:01:091229 const std::vector<std::wstring>& suggestions,
[email protected]0ebf3872008-11-07 21:35:031230 int default_suggestion_index) {
1231 if (!webview() || request_id != form_field_autofill_request_id_)
1232 return;
1233
1234 webview()->AutofillSuggestionsForNode(node_id, suggestions,
1235 default_suggestion_index);
1236}
1237
[email protected]2c4410d2009-05-06 23:46:221238void RenderView::OnPopupNotificationVisibilityChanged(bool visible) {
[email protected]634a6f92008-12-01 21:39:311239 popup_notification_visible_ = visible;
1240}
1241
initial.commit09911bf2008-07-26 23:55:291242uint32 RenderView::GetCPBrowsingContext() {
1243 uint32 context = 0;
1244 Send(new ViewHostMsg_GetCPBrowsingContext(&context));
1245 return context;
1246}
1247
[email protected]b62d1a8c2009-01-13 23:54:571248void RenderView::RunFileChooser(bool multi_select,
[email protected]b949f1112009-04-12 20:03:081249 const string16& title,
1250 const FilePath& default_filename,
initial.commit09911bf2008-07-26 23:55:291251 WebFileChooserCallback* file_chooser) {
1252 if (file_chooser_.get()) {
1253 // TODO(brettw): bug 1235154: This should be a synchronous message to deal
1254 // with the fact that web pages can programatically trigger this. With the
1255 // asnychronous messages, we can get an additional call when one is pending,
1256 // which this test is for. For now, we just ignore the additional file
1257 // chooser request. WebKit doesn't do anything to expect the callback, so
1258 // we can just ignore calling it.
1259 delete file_chooser;
1260 return;
1261 }
1262 file_chooser_.reset(file_chooser);
[email protected]b62d1a8c2009-01-13 23:54:571263 Send(new ViewHostMsg_RunFileChooser(routing_id_, multi_select, title,
[email protected]b949f1112009-04-12 20:03:081264 default_filename));
initial.commit09911bf2008-07-26 23:55:291265}
1266
initial.commit09911bf2008-07-26 23:55:291267void RenderView::AddSearchProvider(const std::string& url) {
1268 AddGURLSearchProvider(GURL(url),
1269 false); // not autodetected
1270}
1271
[email protected]f103ab72009-09-02 17:10:591272void RenderView::OnMissingPluginStatus(
1273 WebPluginDelegateProxy* delegate,
1274 int status) {
[email protected]6c8afae52009-01-22 02:24:571275#if defined(OS_WIN)
[email protected]f103ab72009-09-02 17:10:591276 if (!first_default_plugin_) {
initial.commit09911bf2008-07-26 23:55:291277 // Show the InfoBar for the first available plugin.
1278 if (status == default_plugin::MISSING_PLUGIN_AVAILABLE) {
[email protected]f103ab72009-09-02 17:10:591279 first_default_plugin_ = delegate->AsWeakPtr();
initial.commit09911bf2008-07-26 23:55:291280 Send(new ViewHostMsg_MissingPluginStatus(routing_id_, status));
1281 }
1282 } else {
1283 // Closes the InfoBar if user clicks on the plugin (instead of the InfoBar)
1284 // to start the download/install.
1285 if (status == default_plugin::MISSING_PLUGIN_USER_STARTED_DOWNLOAD) {
1286 Send(new ViewHostMsg_MissingPluginStatus(routing_id_, status));
1287 }
1288 }
[email protected]6c8afae52009-01-22 02:24:571289#else
1290 // TODO(port): plugins current not supported
1291 NOTIMPLEMENTED();
1292#endif
initial.commit09911bf2008-07-26 23:55:291293}
1294
[email protected]48c9cf2d2009-09-16 16:47:521295// WebKit::WebViewClient ------------------------------------------------------
1296
1297WebView* RenderView::createView(WebFrame* creator) {
1298 // Check to make sure we aren't overloading on popups.
1299 if (shared_popup_counter_->data > kMaximumNumberOfUnacknowledgedPopups)
1300 return NULL;
1301
1302 // This window can't be closed from a window.close() call until we receive a
1303 // message from the Browser process explicitly allowing it.
1304 popup_notification_visible_ = true;
1305
1306 int32 routing_id = MSG_ROUTING_NONE;
1307 bool user_gesture = creator->isProcessingUserGesture();
1308
[email protected]48c9cf2d2009-09-16 16:47:521309 render_thread_->Send(
[email protected]12636df2009-09-28 22:32:211310 new ViewHostMsg_CreateWindow(routing_id_, user_gesture, &routing_id));
1311 if (routing_id == MSG_ROUTING_NONE)
[email protected]48c9cf2d2009-09-16 16:47:521312 return NULL;
[email protected]48c9cf2d2009-09-16 16:47:521313
[email protected]48c9cf2d2009-09-16 16:47:521314 RenderView* view = RenderView::Create(render_thread_,
[email protected]12636df2009-09-28 22:32:211315 NULL,
1316 routing_id_,
[email protected]48c9cf2d2009-09-16 16:47:521317 renderer_preferences_,
1318 webkit_preferences_,
[email protected]12636df2009-09-28 22:32:211319 shared_popup_counter_,
1320 routing_id);
[email protected]48c9cf2d2009-09-16 16:47:521321 view->opened_by_user_gesture_ = user_gesture;
1322
1323 // Record the security origin of the creator.
[email protected]91733b62009-09-18 06:21:091324 GURL creator_url(creator->securityOrigin().toString().utf8());
[email protected]48c9cf2d2009-09-16 16:47:521325 if (!creator_url.is_valid() || !creator_url.IsStandard())
1326 creator_url = GURL();
1327 view->creator_url_ = creator_url;
1328
1329 // Copy over the alternate error page URL so we can have alt error pages in
1330 // the new render view (we don't need the browser to send the URL back down).
1331 view->alternate_error_page_url_ = alternate_error_page_url_;
1332
1333 return view->webview();
1334}
1335
1336WebWidget* RenderView::createPopupMenu(bool activatable) {
1337 RenderWidget* widget = RenderWidget::Create(routing_id_,
1338 render_thread_,
1339 activatable);
1340 return widget->webwidget();
1341}
1342
1343WebWidget* RenderView::createPopupMenu(const WebPopupMenuInfo& info) {
1344 RenderWidget* widget = RenderWidget::Create(routing_id_,
1345 render_thread_,
1346 true);
1347 widget->ConfigureAsExternalPopupMenu(info);
1348 return widget->webwidget();
1349}
1350
1351void RenderView::didAddMessageToConsole(
1352 const WebConsoleMessage& message, const WebString& source_name,
1353 unsigned source_line) {
1354 Send(new ViewHostMsg_AddMessageToConsole(routing_id_,
1355 UTF16ToWideHack(message.text),
1356 static_cast<int32>(source_line),
1357 UTF16ToWideHack(source_name)));
1358}
1359
1360void RenderView::printPage(WebFrame* frame) {
[email protected]71a14262009-09-22 20:02:581361 DCHECK(frame);
1362 Print(frame, true);
[email protected]48c9cf2d2009-09-16 16:47:521363}
1364
1365void RenderView::didStartLoading() {
1366 if (is_loading_) {
1367 DLOG(WARNING) << "didStartLoading called while loading";
1368 return;
1369 }
1370
1371 is_loading_ = true;
1372 // Clear the pointer so that we can assign it only when there is an unknown
1373 // plugin on a page.
1374 first_default_plugin_.reset();
1375
1376 Send(new ViewHostMsg_DidStartLoading(routing_id_));
1377}
1378
1379void RenderView::didStopLoading() {
1380 if (!is_loading_) {
1381 DLOG(WARNING) << "DidStopLoading called while not loading";
1382 return;
1383 }
1384
1385 is_loading_ = false;
1386
1387 // NOTE: For now we're doing the safest thing, and sending out notification
1388 // when done loading. This currently isn't an issue as the favicon is only
1389 // displayed when done loading. Ideally we would send notification when
1390 // finished parsing the head, but webkit doesn't support that yet.
1391 // The feed discovery code would also benefit from access to the head.
[email protected]26aa0482009-09-30 16:55:271392 GURL favicon_url(webview()->mainFrame()->favIconURL());
[email protected]48c9cf2d2009-09-16 16:47:521393 if (!favicon_url.is_empty())
1394 Send(new ViewHostMsg_UpdateFavIconURL(routing_id_, page_id_, favicon_url));
1395
[email protected]26aa0482009-09-30 16:55:271396 AddGURLSearchProvider(webview()->mainFrame()->openSearchDescriptionURL(),
[email protected]48c9cf2d2009-09-16 16:47:521397 true); // autodetected
1398
1399 Send(new ViewHostMsg_DidStopLoading(routing_id_));
1400
1401 MessageLoop::current()->PostDelayedTask(FROM_HERE,
1402 method_factory_.NewRunnableMethod(&RenderView::CapturePageInfo, page_id_,
1403 false),
1404 kDelayForCaptureMs);
1405
1406 // The page is loaded. Try to process the file we need to upload if any.
1407 ProcessPendingUpload();
1408
1409 // Since the page is done loading, we are sure we don't need to try
1410 // again.
1411 ResetPendingUpload();
1412}
1413
[email protected]04fc9482009-09-18 22:13:031414bool RenderView::shouldBeginEditing(const WebRange& range) {
1415 return true;
1416}
1417
1418bool RenderView::shouldEndEditing(const WebRange& range) {
1419 return true;
1420}
1421
1422bool RenderView::shouldInsertNode(const WebNode& node, const WebRange& range,
1423 WebEditingAction action) {
1424 return true;
1425}
1426
1427bool RenderView::shouldInsertText(const WebString& text, const WebRange& range,
1428 WebEditingAction action) {
1429 return true;
1430}
1431
1432bool RenderView::shouldChangeSelectedRange(const WebRange& from_range,
1433 const WebRange& to_range,
1434 WebTextAffinity affinity,
1435 bool still_selecting) {
1436 return true;
1437}
1438
1439bool RenderView::shouldDeleteRange(const WebRange& range) {
1440 return true;
1441}
1442
1443bool RenderView::shouldApplyStyle(const WebString& style,
1444 const WebRange& range) {
1445 return true;
1446}
1447
1448bool RenderView::isSmartInsertDeleteEnabled() {
1449 return true;
1450}
1451
1452bool RenderView::isSelectTrailingWhitespaceEnabled() {
1453#if defined(OS_WIN)
1454 return true;
1455#else
1456 return false;
1457#endif
1458}
1459
1460void RenderView::setInputMethodEnabled(bool enabled) {
1461 // Save the updated IME status and mark the input focus has been updated.
1462 // The IME status is to be sent to a browser process next time when
1463 // the input caret is rendered.
1464 if (!ime_control_busy_) {
1465 ime_control_updated_ = true;
1466 ime_control_new_state_ = enabled;
1467 }
1468}
1469
1470void RenderView::didChangeSelection(bool is_empty_selection) {
1471#if defined(OS_LINUX)
1472 if (!handling_input_event_)
1473 return;
1474 // TODO(estade): investigate incremental updates to the selection so that we
1475 // don't send the entire selection over IPC every time.
1476 if (!is_empty_selection) {
1477 // Sometimes we get repeated didChangeSelection calls from webkit when
1478 // the selection hasn't actually changed. We don't want to report these
1479 // because it will cause us to continually claim the X clipboard.
1480 const std::string& this_selection =
[email protected]26aa0482009-09-30 16:55:271481 webview()->focusedFrame()->selectionAsText().utf8();
[email protected]04fc9482009-09-18 22:13:031482 if (this_selection == last_selection_)
1483 return;
1484
1485 Send(new ViewHostMsg_SelectionChanged(routing_id_,
1486 this_selection));
1487 last_selection_ = this_selection;
1488 } else {
1489 last_selection_.clear();
1490 }
1491#endif
1492}
1493
1494void RenderView::didExecuteCommand(const WebString& command_name) {
1495 const std::wstring& name = UTF16ToWideHack(command_name);
1496 if (StartsWith(name, L"Move", true) ||
1497 StartsWith(name, L"Insert", true) ||
1498 StartsWith(name, L"Delete", true))
1499 return;
1500 UserMetricsRecordAction(name);
1501}
1502
[email protected]b2528b72009-09-24 06:57:101503bool RenderView::handleCurrentKeyboardEvent() {
1504 if (edit_commands_.empty())
1505 return false;
1506
[email protected]26aa0482009-09-30 16:55:271507 WebFrame* frame = webview()->focusedFrame();
[email protected]b2528b72009-09-24 06:57:101508 if (!frame)
1509 return false;
1510
1511 EditCommands::iterator it = edit_commands_.begin();
1512 EditCommands::iterator end = edit_commands_.end();
1513
[email protected]507b33ea2009-09-29 03:56:511514 bool did_execute_command = false;
[email protected]b2528b72009-09-24 06:57:101515 for (; it != end; ++it) {
[email protected]e6e15012009-09-30 14:59:331516 // In gtk and cocoa, it's possible to bind multiple edit commands to one
1517 // key (but it's the exception). Once one edit command is not executed, it
1518 // seems safest to not execute the rest.
[email protected]b2528b72009-09-24 06:57:101519 if (!frame->executeCommand(WebString::fromUTF8(it->name),
1520 WebString::fromUTF8(it->value)))
1521 break;
[email protected]507b33ea2009-09-29 03:56:511522 did_execute_command = true;
[email protected]b2528b72009-09-24 06:57:101523 }
1524
[email protected]507b33ea2009-09-29 03:56:511525 return did_execute_command;
[email protected]b2528b72009-09-24 06:57:101526}
1527
[email protected]1dbafaf72009-09-23 19:43:561528void RenderView::spellCheck(
1529 const WebString& text, int& misspelled_offset, int& misspelled_length) {
1530 EnsureDocumentTag();
1531 Send(new ViewHostMsg_SpellCheck(
1532 routing_id_, UTF16ToWideHack(text), document_tag_,
1533 &misspelled_offset, &misspelled_length));
1534}
1535
1536WebString RenderView::autoCorrectWord(const WebKit::WebString& word) {
1537 std::wstring autocorrect_word;
1538 const CommandLine& command_line = *CommandLine::ForCurrentProcess();
1539 if (command_line.HasSwitch(switches::kAutoSpellCorrect)) {
1540 EnsureDocumentTag();
1541 Send(new ViewHostMsg_GetAutoCorrectWord(
1542 routing_id_, UTF16ToWideHack(word), document_tag_, &autocorrect_word));
1543 }
1544 return WideToUTF16Hack(autocorrect_word);
1545}
1546
[email protected]c49085c72009-10-02 16:28:561547void RenderView::showSpellingUI(bool show) {
1548 Send(new ViewHostMsg_ShowSpellingPanel(routing_id_, show));
1549}
1550
[email protected]1dbafaf72009-09-23 19:43:561551void RenderView::updateSpellingUIWithMisspelledWord(const WebString& word) {
1552 Send(new ViewHostMsg_UpdateSpellingPanelWithMisspelledWord(
1553 routing_id_, UTF16ToWideHack(word)));
1554}
1555
[email protected]48c9cf2d2009-09-16 16:47:521556void RenderView::runModalAlertDialog(
1557 WebFrame* frame, const WebString& message) {
1558 RunJavaScriptMessage(MessageBoxFlags::kIsJavascriptAlert,
1559 UTF16ToWideHack(message),
1560 std::wstring(),
1561 frame->url(),
1562 NULL);
1563}
1564
1565bool RenderView::runModalConfirmDialog(
1566 WebFrame* frame, const WebString& message) {
1567 return RunJavaScriptMessage(MessageBoxFlags::kIsJavascriptConfirm,
1568 UTF16ToWideHack(message),
1569 std::wstring(),
1570 frame->url(),
1571 NULL);
1572}
1573
1574bool RenderView::runModalPromptDialog(
1575 WebFrame* frame, const WebString& message, const WebString& default_value,
1576 WebString* actual_value) {
1577 std::wstring result;
1578 bool ok = RunJavaScriptMessage(MessageBoxFlags::kIsJavascriptPrompt,
1579 UTF16ToWideHack(message),
1580 UTF16ToWideHack(default_value),
1581 frame->url(),
1582 &result);
1583 if (ok)
1584 actual_value->assign(WideToUTF16Hack(result));
1585 return ok;
1586}
1587
1588bool RenderView::runModalBeforeUnloadDialog(
1589 WebFrame* frame, const WebString& message) {
1590 bool success = false;
1591 // This is an ignored return value, but is included so we can accept the same
1592 // response as RunJavaScriptMessage.
1593 std::wstring ignored_result;
[email protected]12636df2009-09-28 22:32:211594 SendAndRunNestedMessageLoop(new ViewHostMsg_RunBeforeUnloadConfirm(
[email protected]48c9cf2d2009-09-16 16:47:521595 routing_id_, frame->url(), UTF16ToWideHack(message), &success,
[email protected]12636df2009-09-28 22:32:211596 &ignored_result));
[email protected]48c9cf2d2009-09-16 16:47:521597 return success;
1598}
1599
1600void RenderView::setStatusText(const WebString& text) {
1601}
1602
1603void RenderView::setMouseOverURL(const WebURL& url) {
[email protected]8d32b9832009-09-17 06:21:011604 GURL latest_url(url);
[email protected]48c9cf2d2009-09-16 16:47:521605 if (latest_url == target_url_)
1606 return;
1607 // Tell the browser to display a destination link.
1608 if (target_url_status_ == TARGET_INFLIGHT ||
1609 target_url_status_ == TARGET_PENDING) {
1610 // If we have a request in-flight, save the URL to be sent when we
1611 // receive an ACK to the in-flight request. We can happily overwrite
1612 // any existing pending sends.
1613 pending_target_url_ = latest_url;
1614 target_url_status_ = TARGET_PENDING;
1615 } else {
1616 Send(new ViewHostMsg_UpdateTargetURL(routing_id_, page_id_, latest_url));
1617 target_url_ = latest_url;
1618 target_url_status_ = TARGET_INFLIGHT;
1619 }
1620}
1621
1622void RenderView::setToolTipText(const WebString& text, WebTextDirection hint) {
1623 Send(new ViewHostMsg_SetTooltipText(routing_id_, UTF16ToWideHack(text),
1624 hint));
1625}
1626
1627void RenderView::startDragging(const WebPoint& from, const WebDragData& data,
1628 WebDragOperationsMask allowed_ops) {
1629 Send(new ViewHostMsg_StartDragging(routing_id_,
1630 WebDropData(data),
1631 allowed_ops));
1632}
1633
[email protected]28b92df2009-09-25 17:35:451634bool RenderView::acceptsLoadDrops() {
1635 return renderer_preferences_.can_accept_load_drops;
1636}
1637
[email protected]48c9cf2d2009-09-16 16:47:521638void RenderView::focusNext() {
1639 Send(new ViewHostMsg_TakeFocus(routing_id_, false));
1640}
1641
1642void RenderView::focusPrevious() {
1643 Send(new ViewHostMsg_TakeFocus(routing_id_, true));
1644}
1645
1646void RenderView::navigateBackForwardSoon(int offset) {
1647 history_back_list_count_ += offset;
1648 history_forward_list_count_ -= offset;
1649
1650 Send(new ViewHostMsg_GoToEntryAtOffset(routing_id_, offset));
1651}
1652
1653int RenderView::historyBackListCount() {
1654 return history_back_list_count_;
1655}
1656
1657int RenderView::historyForwardListCount() {
1658 return history_forward_list_count_;
1659}
1660
1661void RenderView::didAddHistoryItem() {
1662 // We don't want to update the history length for the start page
1663 // navigation.
[email protected]26aa0482009-09-30 16:55:271664 WebFrame* main_frame = webview()->mainFrame();
[email protected]48c9cf2d2009-09-16 16:47:521665 DCHECK(main_frame != NULL);
1666
1667 WebDataSource* ds = main_frame->dataSource();
1668 DCHECK(ds != NULL);
1669
1670 NavigationState* navigation_state = NavigationState::FromDataSource(ds);
1671 DCHECK(navigation_state);
1672 if (navigation_state->transition_type() == PageTransition::START_PAGE)
1673 return;
1674
1675 history_back_list_count_++;
1676 history_forward_list_count_ = 0;
1677}
1678
[email protected]79dbc662009-09-04 05:42:511679// WebKit::WebWidgetClient ----------------------------------------------------
1680
initial.commit09911bf2008-07-26 23:55:291681// We are supposed to get a single call to Show for a newly created RenderView
1682// that was created via RenderView::CreateWebView. So, we wait until this
1683// point to dispatch the ShowView message.
1684//
1685// This method provides us with the information about how to display the newly
1686// created RenderView (i.e., as a constrained popup or as a new tab).
1687//
[email protected]4873c7d2009-07-16 06:36:281688void RenderView::show(WebNavigationPolicy policy) {
initial.commit09911bf2008-07-26 23:55:291689 DCHECK(!did_show_) << "received extraneous Show call";
1690 DCHECK(opener_id_ != MSG_ROUTING_NONE);
1691
1692 if (did_show_)
1693 return;
1694 did_show_ = true;
1695
1696 // NOTE: initial_pos_ may still have its default values at this point, but
1697 // that's okay. It'll be ignored if disposition is not NEW_POPUP, or the
1698 // browser process will impose a default position otherwise.
[email protected]4873c7d2009-07-16 06:36:281699 Send(new ViewHostMsg_ShowView(opener_id_, routing_id_,
1700 NavigationPolicyToDisposition(policy), initial_pos_,
1701 opened_by_user_gesture_, creator_url_));
[email protected]2533ce12009-05-09 00:02:241702 SetPendingWindowRect(initial_pos_);
initial.commit09911bf2008-07-26 23:55:291703}
1704
[email protected]4873c7d2009-07-16 06:36:281705void RenderView::closeWidgetSoon() {
[email protected]2c4410d2009-05-06 23:46:221706 if (!popup_notification_visible_)
[email protected]4873c7d2009-07-16 06:36:281707 RenderWidget::closeWidgetSoon();
[email protected]634a6f92008-12-01 21:39:311708}
1709
[email protected]4873c7d2009-07-16 06:36:281710void RenderView::runModal() {
initial.commit09911bf2008-07-26 23:55:291711 DCHECK(did_show_) << "should already have shown the view";
1712
[email protected]12636df2009-09-28 22:32:211713 SendAndRunNestedMessageLoop(new ViewHostMsg_RunModal(routing_id_));
initial.commit09911bf2008-07-26 23:55:291714}
1715
[email protected]3d9689372009-09-10 04:29:171716// WebKit::WebFrameClient -----------------------------------------------------
1717
1718WebPlugin* RenderView::createPlugin(
1719 WebFrame* frame, const WebPluginParams& params) {
1720 return new webkit_glue::WebPluginImpl(frame, params, AsWeakPtr());
1721}
1722
1723WebWorker* RenderView::createWorker(WebFrame* frame, WebWorkerClient* client) {
1724 return new WebWorkerProxy(client, RenderThread::current(), routing_id_);
1725}
1726
1727WebMediaPlayer* RenderView::createMediaPlayer(
1728 WebFrame* frame, WebMediaPlayerClient* client) {
1729 scoped_refptr<media::FilterFactoryCollection> factory =
1730 new media::FilterFactoryCollection();
1731 // Add in any custom filter factories first.
1732 const CommandLine* cmd_line = CommandLine::ForCurrentProcess();
1733 if (!cmd_line->HasSwitch(switches::kDisableAudio)) {
1734 // Add the chrome specific audio renderer.
1735 factory->AddFactory(
1736 AudioRendererImpl::CreateFactory(audio_message_filter()));
1737 }
1738
1739 // TODO(hclam): obtain the following parameters from |client|.
1740 webkit_glue::MediaResourceLoaderBridgeFactory* bridge_factory =
1741 new webkit_glue::MediaResourceLoaderBridgeFactory(
1742 GURL::EmptyGURL(), // referrer
1743 "null", // frame origin
1744 "null", // main_frame_origin
1745 base::GetCurrentProcId(),
1746 appcache::kNoHostId,
1747 routing_id());
1748
1749 if (!cmd_line->HasSwitch(switches::kSimpleDataSource)) {
1750 // Add the chrome specific media data source.
1751 factory->AddFactory(
1752 webkit_glue::BufferedDataSource::CreateFactory(MessageLoop::current(),
1753 bridge_factory));
1754 } else {
1755 factory->AddFactory(
1756 webkit_glue::SimpleDataSource::CreateFactory(MessageLoop::current(),
1757 bridge_factory));
1758 }
1759 return new webkit_glue::WebMediaPlayerImpl(client, factory);
1760}
1761
1762void RenderView::willClose(WebFrame* frame) {
1763 if (!frame->parent()) {
1764 const GURL& url = frame->url();
1765 if (url.SchemeIs("http") || url.SchemeIs("https"))
1766 DumpLoadHistograms();
1767 }
1768}
1769
1770void RenderView::loadURLExternally(
1771 WebFrame* frame, const WebURLRequest& request,
1772 WebNavigationPolicy policy) {
[email protected]efce17b2009-09-11 18:04:591773 GURL referrer(request.httpHeaderField(WebString::fromUTF8("Referer")));
1774 if (policy == WebKit::WebNavigationPolicyDownload) {
1775 Send(new ViewHostMsg_DownloadUrl(routing_id_, request.url(), referrer));
1776 } else {
1777 OpenURL(request.url(), referrer, policy);
1778 }
[email protected]3d9689372009-09-10 04:29:171779}
1780
1781WebNavigationPolicy RenderView::decidePolicyForNavigation(
1782 WebFrame* frame, const WebURLRequest& request, WebNavigationType type,
1783 WebNavigationPolicy default_policy, bool is_redirect) {
1784 // Webkit is asking whether to navigate to a new URL.
1785 // This is fine normally, except if we're showing UI from one security
1786 // context and they're trying to navigate to a different context.
1787 const GURL& url = request.url();
1788
1789 // If the browser is interested, then give it a chance to look at top level
1790 // navigations
1791 if (renderer_preferences_.browser_handles_top_level_requests &&
1792 // Only send once.
1793 last_top_level_navigation_page_id_ != page_id_ &&
1794 // Not interested in reloads.
1795 type != WebKit::WebNavigationTypeReload &&
1796 type != WebKit::WebNavigationTypeFormSubmitted &&
1797 // Must be a top level frame.
1798 frame->parent() == NULL) {
1799 // Skip if navigation is on the same page (using '#').
1800 GURL frame_origin = GURL(frame->url()).GetOrigin();
1801 if (url.GetOrigin() != frame_origin || url.ref().empty()) {
1802 last_top_level_navigation_page_id_ = page_id_;
1803 OpenURL(url, GURL(), default_policy);
1804 return WebKit::WebNavigationPolicyIgnore; // Suppress the load here.
1805 }
1806 }
1807
1808 // A content initiated navigation may have originated from a link-click,
1809 // script, drag-n-drop operation, etc.
1810 bool is_content_initiated =
1811 NavigationState::FromDataSource(frame->provisionalDataSource())->
1812 is_content_initiated();
1813
1814 // We only care about navigations that are within the current tab (as opposed
1815 // to, for example, opening a new window).
1816 // But we sometimes navigate to about:blank to clear a tab, and we want to
1817 // still allow that.
1818 if (default_policy == WebKit::WebNavigationPolicyCurrentTab &&
1819 is_content_initiated && frame->parent() == NULL &&
1820 !url.SchemeIs(chrome::kAboutScheme)) {
1821 // When we received such unsolicited navigations, we sometimes want to
1822 // punt them up to the browser to handle.
1823 if (BindingsPolicy::is_dom_ui_enabled(enabled_bindings_) ||
1824 BindingsPolicy::is_extension_enabled(enabled_bindings_) ||
1825 frame->isViewSourceModeEnabled() ||
1826 url.SchemeIs(chrome::kViewSourceScheme) ||
1827 url.SchemeIs(chrome::kPrintScheme)) {
1828 OpenURL(url, GURL(), default_policy);
1829 return WebKit::WebNavigationPolicyIgnore; // Suppress the load here.
1830 }
1831 }
1832
1833 // Detect when a page is "forking" a new tab that can be safely rendered in
1834 // its own process. This is done by sites like Gmail that try to open links
1835 // in new windows without script connections back to the original page. We
1836 // treat such cases as browser navigations (in which we will create a new
1837 // renderer for a cross-site navigation), rather than WebKit navigations.
1838 //
1839 // We use the following heuristic to decide whether to fork a new page in its
1840 // own process:
1841 // The parent page must open a new tab to about:blank, set the new tab's
1842 // window.opener to null, and then redirect the tab to a cross-site URL using
1843 // JavaScript.
1844 bool is_fork =
1845 // Must start from a tab showing about:blank, which is later redirected.
[email protected]e0d481582009-09-15 21:06:251846 GURL(frame->url()) == GURL(chrome::kAboutBlankURL) &&
[email protected]3d9689372009-09-10 04:29:171847 // Must be the first real navigation of the tab.
[email protected]48c9cf2d2009-09-16 16:47:521848 historyBackListCount() < 1 &&
1849 historyForwardListCount() < 1 &&
[email protected]3d9689372009-09-10 04:29:171850 // The parent page must have set the child's window.opener to null before
1851 // redirecting to the desired URL.
1852 frame->opener() == NULL &&
1853 // Must be a top-level frame.
1854 frame->parent() == NULL &&
1855 // Must not have issued the request from this page.
1856 is_content_initiated &&
1857 // Must be targeted at the current tab.
1858 default_policy == WebKit::WebNavigationPolicyCurrentTab &&
1859 // Must be a JavaScript navigation, which appears as "other".
1860 type == WebKit::WebNavigationTypeOther;
1861 if (is_fork) {
1862 // Open the URL via the browser, not via WebKit.
1863 OpenURL(url, GURL(), default_policy);
1864 return WebKit::WebNavigationPolicyIgnore;
1865 }
1866
1867 return default_policy;
1868}
1869
1870void RenderView::willSubmitForm(WebFrame* frame, const WebForm& form) {
1871 NavigationState* navigation_state =
1872 NavigationState::FromDataSource(frame->provisionalDataSource());
1873
1874 if (navigation_state->transition_type() == PageTransition::LINK)
1875 navigation_state->set_transition_type(PageTransition::FORM_SUBMIT);
1876
1877 // Save these to be processed when the ensuing navigation is committed.
1878 navigation_state->set_searchable_form_data(
1879 SearchableFormData::Create(form));
1880 navigation_state->set_password_form_data(
1881 PasswordFormDomManager::CreatePasswordForm(form));
1882
1883 if (form.isAutoCompleteEnabled()) {
1884 scoped_ptr<AutofillForm> autofill_form(AutofillForm::Create(form));
1885 if (autofill_form.get())
1886 Send(new ViewHostMsg_AutofillFormSubmitted(routing_id_, *autofill_form));
1887 }
1888}
1889
1890void RenderView::willPerformClientRedirect(
1891 WebFrame* frame, const WebURL& from, const WebURL& to, double interval,
1892 double fire_time) {
1893 // Ignore
1894}
1895
1896void RenderView::didCancelClientRedirect(WebFrame* frame) {
1897 // Ignore
1898}
1899
1900void RenderView::didCompleteClientRedirect(
1901 WebFrame* frame, const WebURL& from) {
1902 if (!frame->parent())
1903 completed_client_redirect_src_ = from;
1904}
1905
1906void RenderView::didCreateDataSource(WebFrame* frame, WebDataSource* ds) {
1907 // The rest of RenderView assumes that a WebDataSource will always have a
1908 // non-null NavigationState.
1909 if (pending_navigation_state_.get()) {
1910 ds->setExtraData(pending_navigation_state_.release());
1911 } else {
1912 ds->setExtraData(NavigationState::CreateContentInitiated());
1913 }
1914}
1915
1916void RenderView::didStartProvisionalLoad(WebFrame* frame) {
1917 WebDataSource* ds = frame->provisionalDataSource();
1918 NavigationState* navigation_state = NavigationState::FromDataSource(ds);
1919
1920 navigation_state->set_start_load_time(Time::Now());
1921
1922 // Update the request time if WebKit has better knowledge of it.
1923 if (navigation_state->request_time().is_null()) {
1924 double event_time = ds->triggeringEventTime();
1925 if (event_time != 0.0)
1926 navigation_state->set_request_time(Time::FromDoubleT(event_time));
1927 }
1928
1929 bool is_top_most = !frame->parent();
1930 if (is_top_most) {
1931 navigation_gesture_ = frame->isProcessingUserGesture() ?
1932 NavigationGestureUnknown : NavigationGestureAuto;
1933
1934 // Make sure redirect tracking state is clear for the new load.
1935 completed_client_redirect_src_ = GURL();
1936 } else if (frame->parent()->isLoading()) {
1937 // Take note of AUTO_SUBFRAME loads here, so that we can know how to
1938 // load an error page. See DidFailProvisionalLoadWithError.
1939 navigation_state->set_transition_type(PageTransition::AUTO_SUBFRAME);
1940 }
1941
1942 Send(new ViewHostMsg_DidStartProvisionalLoadForFrame(
1943 routing_id_, is_top_most, ds->request().url()));
1944}
1945
1946void RenderView::didReceiveServerRedirectForProvisionalLoad(WebFrame* frame) {
1947 if (frame->parent())
1948 return;
1949 // Received a redirect on the main frame.
1950 WebDataSource* data_source = frame->provisionalDataSource();
1951 if (!data_source) {
1952 // Should only be invoked when we have a data source.
1953 NOTREACHED();
1954 return;
1955 }
1956 std::vector<GURL> redirects;
1957 GetRedirectChain(data_source, &redirects);
1958 if (redirects.size() >= 2) {
1959 Send(new ViewHostMsg_DidRedirectProvisionalLoad(
1960 routing_id_, page_id_, redirects[redirects.size() - 2],
1961 redirects[redirects.size() - 1]));
1962 }
1963}
1964
1965void RenderView::didFailProvisionalLoad(
1966 WebFrame* frame, const WebURLError& error) {
1967 // Notify the browser that we failed a provisional load with an error.
1968 //
1969 // Note: It is important this notification occur before DidStopLoading so the
1970 // SSL manager can react to the provisional load failure before being
1971 // notified the load stopped.
1972 //
1973 WebDataSource* ds = frame->provisionalDataSource();
1974 DCHECK(ds);
1975
1976 const WebURLRequest& failed_request = ds->request();
1977
1978 bool show_repost_interstitial =
1979 (error.reason == net::ERR_CACHE_MISS &&
1980 EqualsASCII(failed_request.httpMethod(), "POST"));
1981 Send(new ViewHostMsg_DidFailProvisionalLoadWithError(
1982 routing_id_, !frame->parent(), error.reason, error.unreachableURL,
1983 show_repost_interstitial));
1984
1985 // Don't display an error page if this is simply a cancelled load. Aside
1986 // from being dumb, WebCore doesn't expect it and it will cause a crash.
1987 if (error.reason == net::ERR_ABORTED)
1988 return;
1989
1990 // Make sure we never show errors in view source mode.
1991 frame->enableViewSourceMode(false);
1992
1993 NavigationState* navigation_state = NavigationState::FromDataSource(ds);
1994
1995 // If this is a failed back/forward/reload navigation, then we need to do a
1996 // 'replace' load. This is necessary to avoid messing up session history.
1997 // Otherwise, we do a normal load, which simulates a 'go' navigation as far
1998 // as session history is concerned.
1999 //
2000 // AUTO_SUBFRAME loads should always be treated as loads that do not advance
2001 // the page id.
2002 //
2003 bool replace =
2004 navigation_state->pending_page_id() != -1 ||
2005 navigation_state->transition_type() == PageTransition::AUTO_SUBFRAME;
2006
2007 // If we failed on a browser initiated request, then make sure that our error
2008 // page load is regarded as the same browser initiated request.
2009 if (!navigation_state->is_content_initiated()) {
2010 pending_navigation_state_.reset(NavigationState::CreateBrowserInitiated(
2011 navigation_state->pending_page_id(),
2012 navigation_state->transition_type(),
2013 navigation_state->request_time()));
2014 }
2015
2016 // Provide the user with a more helpful error page?
2017 if (MaybeLoadAlternateErrorPage(frame, error, replace))
2018 return;
2019
2020 // Fallback to a local error page.
2021 LoadNavigationErrorPage(frame, failed_request, error, std::string(),
2022 replace);
2023}
2024
2025void RenderView::didReceiveDocumentData(
2026 WebFrame* frame, const char* data, size_t data_len,
2027 bool& prevent_default) {
2028 NavigationState* navigation_state =
2029 NavigationState::FromDataSource(frame->dataSource());
2030 if (!navigation_state->postpone_loading_data())
2031 return;
2032
2033 // We're going to call commitDocumentData ourselves...
2034 prevent_default = true;
2035
2036 // Continue buffering the response data for the original 404 page. If it
2037 // grows too large, then we'll just let it through.
2038 navigation_state->append_postponed_data(data, data_len);
2039 if (navigation_state->postponed_data().size() >= 512) {
2040 navigation_state->set_postpone_loading_data(false);
2041 frame->commitDocumentData(navigation_state->postponed_data().data(),
2042 navigation_state->postponed_data().size());
2043 navigation_state->clear_postponed_data();
2044 }
2045}
2046
2047void RenderView::didCommitProvisionalLoad(
2048 WebFrame* frame, bool is_new_navigation) {
2049 NavigationState* navigation_state =
2050 NavigationState::FromDataSource(frame->dataSource());
2051
2052 navigation_state->set_commit_load_time(Time::Now());
2053 if (is_new_navigation) {
2054 // When we perform a new navigation, we need to update the previous session
2055 // history entry with state for the page we are leaving.
2056 UpdateSessionHistory(frame);
2057
2058 // We bump our Page ID to correspond with the new session history entry.
2059 page_id_ = next_page_id_++;
2060
2061 MessageLoop::current()->PostDelayedTask(FROM_HERE,
2062 method_factory_.NewRunnableMethod(&RenderView::CapturePageInfo,
2063 page_id_, true),
2064 kDelayForForcedCaptureMs);
2065 } else {
2066 // Inspect the navigation_state on this frame to see if the navigation
2067 // corresponds to a session history navigation... Note: |frame| may or
2068 // may not be the toplevel frame, but for the case of capturing session
2069 // history, the first committed frame suffices. We keep track of whether
2070 // we've seen this commit before so that only capture session history once
2071 // per navigation.
2072 //
2073 // Note that we need to check if the page ID changed. In the case of a
2074 // reload, the page ID doesn't change, and UpdateSessionHistory gets the
2075 // previous URL and the current page ID, which would be wrong.
2076 if (navigation_state->pending_page_id() != -1 &&
2077 navigation_state->pending_page_id() != page_id_ &&
2078 !navigation_state->request_committed()) {
2079 // This is a successful session history navigation!
2080 UpdateSessionHistory(frame);
2081 page_id_ = navigation_state->pending_page_id();
2082 }
2083 }
2084
2085 // Remember that we've already processed this request, so we don't update
2086 // the session history again. We do this regardless of whether this is
2087 // a session history navigation, because if we attempted a session history
2088 // navigation without valid HistoryItem state, WebCore will think it is a
2089 // new navigation.
2090 navigation_state->set_request_committed(true);
2091
2092 UpdateURL(frame);
2093
2094 // If this committed load was initiated by a client redirect, we're
2095 // at the last stop now, so clear it.
2096 completed_client_redirect_src_ = GURL();
2097
2098 // Check whether we have new encoding name.
[email protected]26aa0482009-09-30 16:55:272099 UpdateEncoding(frame, frame->view()->pageEncoding().utf8());
[email protected]3d9689372009-09-10 04:29:172100}
2101
2102void RenderView::didClearWindowObject(WebFrame* frame) {
2103 if (BindingsPolicy::is_dom_automation_enabled(enabled_bindings_))
2104 BindDOMAutomationController(frame);
2105 if (BindingsPolicy::is_dom_ui_enabled(enabled_bindings_)) {
2106 dom_ui_bindings_.set_message_sender(this);
2107 dom_ui_bindings_.set_routing_id(routing_id_);
2108 dom_ui_bindings_.BindToJavascript(frame, L"chrome");
2109 }
2110 if (BindingsPolicy::is_external_host_enabled(enabled_bindings_)) {
2111 external_host_bindings_.set_message_sender(this);
2112 external_host_bindings_.set_routing_id(routing_id_);
2113 external_host_bindings_.BindToJavascript(frame, L"externalHost");
2114 }
2115}
2116
2117void RenderView::didCreateDocumentElement(WebFrame* frame) {
2118 if (RenderThread::current()) { // Will be NULL during unit tests.
2119 RenderThread::current()->user_script_slave()->InjectScripts(
2120 frame, UserScript::DOCUMENT_START);
2121 }
[email protected]078b34612009-09-19 19:31:512122 if (view_type_ == ViewType::EXTENSION_TOOLSTRIP ||
2123 view_type_ == ViewType::EXTENSION_MOLE) {
2124 InjectToolstripCSS();
2125 ExtensionProcessBindings::SetViewType(webview(), view_type_);
2126 }
[email protected]3d9689372009-09-10 04:29:172127
[email protected]912256b32009-09-18 09:47:352128 while (!pending_code_execution_queue_.empty()) {
2129 scoped_refptr<CodeExecutionInfo> info =
2130 pending_code_execution_queue_.front();
2131 OnExecuteCode(info->request_id, info->extension_id, info->is_js_code,
2132 info->code_string);
2133 pending_code_execution_queue_.pop();
2134 }
2135
[email protected]3d9689372009-09-10 04:29:172136 // Notify the browser about non-blank documents loading in the top frame.
2137 GURL url = frame->url();
[email protected]e0d481582009-09-15 21:06:252138 if (url.is_valid() && url.spec() != chrome::kAboutBlankURL) {
[email protected]26aa0482009-09-30 16:55:272139 if (frame == webview()->mainFrame())
[email protected]3d9689372009-09-10 04:29:172140 Send(new ViewHostMsg_DocumentAvailableInMainFrame(routing_id_));
2141 }
2142}
2143
2144void RenderView::didReceiveTitle(WebFrame* frame, const WebString& title) {
2145 UpdateTitle(frame, title);
2146
2147 // Also check whether we have new encoding name.
[email protected]26aa0482009-09-30 16:55:272148 UpdateEncoding(frame, frame->view()->pageEncoding().utf8());
[email protected]3d9689372009-09-10 04:29:172149}
2150
2151void RenderView::didFinishDocumentLoad(WebFrame* frame) {
2152 WebDataSource* ds = frame->dataSource();
2153 NavigationState* navigation_state = NavigationState::FromDataSource(ds);
2154 DCHECK(navigation_state);
2155 navigation_state->set_finish_document_load_time(Time::Now());
2156
2157 Send(new ViewHostMsg_DocumentLoadedInFrame(routing_id_));
2158
2159 // The document has now been fully loaded. Scan for password forms to be
2160 // sent up to the browser.
2161 SendPasswordForms(frame);
2162
2163 // Check whether we have new encoding name.
[email protected]26aa0482009-09-30 16:55:272164 UpdateEncoding(frame, frame->view()->pageEncoding().utf8());
[email protected]3d9689372009-09-10 04:29:172165
2166 if (RenderThread::current()) { // Will be NULL during unit tests.
2167 RenderThread::current()->user_script_slave()->InjectScripts(
2168 frame, UserScript::DOCUMENT_END);
2169 }
2170}
2171
2172void RenderView::didHandleOnloadEvents(WebFrame* frame) {
2173 // Ignore
2174}
2175
2176void RenderView::didFailLoad(WebFrame* frame, const WebURLError& error) {
2177 // Ignore
2178}
2179
2180void RenderView::didFinishLoad(WebFrame* frame) {
2181 WebDataSource* ds = frame->dataSource();
2182 NavigationState* navigation_state = NavigationState::FromDataSource(ds);
2183 DCHECK(navigation_state);
2184 navigation_state->set_finish_load_time(Time::Now());
2185}
2186
2187void RenderView::didChangeLocationWithinPage(
2188 WebFrame* frame, bool is_new_navigation) {
2189 // If this was a reference fragment navigation that we initiated, then we
2190 // could end up having a non-null pending navigation state. We just need to
2191 // update the ExtraData on the datasource so that others who read the
2192 // ExtraData will get the new NavigationState. Similarly, if we did not
2193 // initiate this navigation, then we need to take care to reset any pre-
2194 // existing navigation state to a content-initiated navigation state.
2195 // DidCreateDataSource conveniently takes care of this for us.
2196 didCreateDataSource(frame, frame->dataSource());
2197
2198 didCommitProvisionalLoad(frame, is_new_navigation);
2199
[email protected]26aa0482009-09-30 16:55:272200 UpdateTitle(frame, frame->view()->mainFrame()->dataSource()->pageTitle());
[email protected]3d9689372009-09-10 04:29:172201}
2202
[email protected]476b6f82009-09-10 21:00:592203void RenderView::didUpdateCurrentHistoryItem(WebFrame* frame) {
2204 if (!nav_state_sync_timer_.IsRunning()) {
2205 nav_state_sync_timer_.Start(
2206 TimeDelta::FromSeconds(delay_seconds_for_form_state_sync_), this,
2207 &RenderView::SyncNavigationState);
2208 }
2209}
2210
[email protected]3d9689372009-09-10 04:29:172211void RenderView::assignIdentifierToRequest(
2212 WebFrame* frame, unsigned identifier, const WebURLRequest& request) {
2213 // Ignore
2214}
2215
2216void RenderView::willSendRequest(
2217 WebFrame* frame, unsigned identifier, WebURLRequest& request,
2218 const WebURLResponse& redirect_response) {
2219 request.setRequestorID(routing_id_);
2220}
2221
2222void RenderView::didReceiveResponse(
2223 WebFrame* frame, unsigned identifier, const WebURLResponse& response) {
2224 // Consider loading an alternate error page for 404 responses.
2225 if (response.httpStatusCode() != 404)
2226 return;
2227
2228 // Only do this for responses that correspond to a provisional data source
2229 // of the top-most frame. If we have a provisional data source, then we
2230 // can't have any sub-resources yet, so we know that this response must
2231 // correspond to a frame load.
2232 if (!frame->provisionalDataSource() || frame->parent())
2233 return;
2234
2235 // If we are in view source mode, then just let the user see the source of
2236 // the server's 404 error page.
2237 if (frame->isViewSourceModeEnabled())
2238 return;
2239
2240 // Can we even load an alternate error page for this URL?
2241 if (!GetAlternateErrorPageURL(response.url(), HTTP_404).is_valid())
2242 return;
2243
2244 NavigationState* navigation_state =
2245 NavigationState::FromDataSource(frame->provisionalDataSource());
2246 navigation_state->set_postpone_loading_data(true);
2247 navigation_state->clear_postponed_data();
2248}
2249
2250void RenderView::didFinishResourceLoad(
2251 WebFrame* frame, unsigned identifier) {
2252 NavigationState* navigation_state =
2253 NavigationState::FromDataSource(frame->dataSource());
2254 if (!navigation_state->postpone_loading_data())
2255 return;
2256
2257 // The server returned a 404 and the content was < 512 bytes (which we
2258 // suppressed). Go ahead and fetch the alternate page content.
2259
2260 const GURL& frame_url = frame->url();
2261
2262 const GURL& error_page_url = GetAlternateErrorPageURL(frame_url, HTTP_404);
2263 DCHECK(error_page_url.is_valid());
2264
2265 WebURLError original_error;
2266 original_error.unreachableURL = frame_url;
2267
2268 navigation_state->set_alt_error_page_fetcher(
2269 new AltErrorPageResourceFetcher(
2270 error_page_url, frame, original_error,
2271 NewCallback(this, &RenderView::AltErrorPageFinished)));
2272}
2273
2274void RenderView::didFailResourceLoad(
2275 WebFrame* frame, unsigned identifier, const WebURLError& error) {
2276 // Ignore
2277}
2278
2279void RenderView::didLoadResourceFromMemoryCache(
2280 WebFrame* frame, const WebURLRequest& request,
2281 const WebURLResponse& response) {
2282 // Let the browser know we loaded a resource from the memory cache. This
2283 // message is needed to display the correct SSL indicators.
2284 Send(new ViewHostMsg_DidLoadResourceFromMemoryCache(
2285 routing_id_,
2286 request.url(),
[email protected]91733b62009-09-18 06:21:092287 frame->securityOrigin().toString().utf8(),
2288 frame->top()->securityOrigin().toString().utf8(),
[email protected]3d9689372009-09-10 04:29:172289 response.securityInfo()));
2290}
2291
[email protected]e3d60e5d2009-09-25 21:08:292292void RenderView::didDisplayInsecureContent(WebKit::WebFrame* frame) {
2293 Send(new ViewHostMsg_DidDisplayInsecureContent(routing_id_));
2294}
2295
2296void RenderView::didRunInsecureContent(
2297 WebFrame* frame, const WebSecurityOrigin& origin) {
2298 Send(new ViewHostMsg_DidRunInsecureContent(
2299 routing_id_,
2300 origin.toString().utf8()));
2301}
2302
[email protected]3d9689372009-09-10 04:29:172303void RenderView::didExhaustMemoryAvailableForScript(WebFrame* frame) {
2304 Send(new ViewHostMsg_JSOutOfMemory(routing_id_));
2305}
2306
2307void RenderView::didChangeContentsSize(WebFrame* frame, const WebSize& size) {
2308 // We don't always want to send the change messages over IPC, only if we've
2309 // be put in that mode by getting a |ViewMsg_EnableIntrinsicWidthChangedMode|
2310 // message.
[email protected]f87eee052009-09-10 21:39:092311 if (send_preferred_width_changes_) {
[email protected]3d9689372009-09-10 04:29:172312 // WebCore likes to tell us things have changed even when they haven't, so
2313 // cache the width and only send the IPC message when we're sure the
2314 // width is different.
[email protected]26aa0482009-09-30 16:55:272315 int width = webview()->mainFrame()->contentsPreferredWidth();
[email protected]3d9689372009-09-10 04:29:172316 if (width != preferred_width_) {
2317 Send(new ViewHostMsg_DidContentsPreferredWidthChange(routing_id_, width));
2318 preferred_width_ = width;
2319 }
2320 }
2321}
2322
[email protected]79dbc662009-09-04 05:42:512323// webkit_glue::WebPluginPageDelegate -----------------------------------------
2324
[email protected]f103ab72009-09-02 17:10:592325webkit_glue::WebPluginDelegate* RenderView::CreatePluginDelegate(
2326 const GURL& url,
2327 const std::string& mime_type,
[email protected]f103ab72009-09-02 17:10:592328 std::string* actual_mime_type) {
2329 if (!PluginChannelHost::IsListening())
2330 return NULL;
2331
2332 GURL policy_url;
[email protected]26aa0482009-09-30 16:55:272333 WebFrame* main_frame = webview()->mainFrame();
[email protected]f103ab72009-09-02 17:10:592334 if (main_frame)
2335 policy_url = main_frame->url();
2336
2337 FilePath path;
[email protected]610c0892009-09-08 19:46:182338 render_thread_->Send(new ViewHostMsg_GetPluginPath(
2339 url, policy_url, mime_type, &path, actual_mime_type));
[email protected]f103ab72009-09-02 17:10:592340 if (path.value().empty())
2341 return NULL;
2342
2343 const std::string* mime_type_to_use;
2344 if (!actual_mime_type->empty())
2345 mime_type_to_use = actual_mime_type;
2346 else
2347 mime_type_to_use = &mime_type;
2348
[email protected]d032f492009-09-29 00:33:462349 bool in_process_plugin = RenderProcess::current()->in_process_plugins();
2350 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kInternalNaCl)) {
2351 if (mime_type == "application/x-nacl-srpc") {
2352 in_process_plugin = true;
2353 }
2354 }
2355 if (in_process_plugin) {
[email protected]f103ab72009-09-02 17:10:592356#if defined(OS_WIN) // In-proc plugins aren't supported on Linux or Mac.
[email protected]8a3b7962009-09-04 05:53:232357 return WebPluginDelegateImpl::Create(
[email protected]f103ab72009-09-02 17:10:592358 path, *mime_type_to_use, gfx::NativeViewFromId(host_window_));
2359#else
2360 NOTIMPLEMENTED();
2361 return NULL;
2362#endif
2363 }
2364
[email protected]610c0892009-09-08 19:46:182365 return new WebPluginDelegateProxy(*mime_type_to_use, AsWeakPtr());
[email protected]f103ab72009-09-02 17:10:592366}
2367
2368void RenderView::CreatedPluginWindow(gfx::PluginWindowHandle window) {
2369#if defined(OS_LINUX)
2370 RenderThread::current()->Send(new ViewHostMsg_CreatePluginContainer(
2371 routing_id(), window));
2372#endif
2373}
2374
2375void RenderView::WillDestroyPluginWindow(gfx::PluginWindowHandle window) {
2376#if defined(OS_LINUX)
2377 RenderThread::current()->Send(new ViewHostMsg_DestroyPluginContainer(
2378 routing_id(), window));
2379#endif
2380 CleanupWindowInPluginMoves(window);
2381}
2382
2383void RenderView::DidMovePlugin(const webkit_glue::WebPluginGeometry& move) {
2384 SchedulePluginMove(move);
2385}
2386
2387void RenderView::DidStartLoadingForPlugin() {
2388 // TODO(darin): Make is_loading_ be a counter!
[email protected]48c9cf2d2009-09-16 16:47:522389 didStartLoading();
[email protected]f103ab72009-09-02 17:10:592390}
2391
2392void RenderView::DidStopLoadingForPlugin() {
2393 // TODO(darin): Make is_loading_ be a counter!
[email protected]48c9cf2d2009-09-16 16:47:522394 didStopLoading();
[email protected]f103ab72009-09-02 17:10:592395}
2396
2397void RenderView::ShowModalHTMLDialogForPlugin(
2398 const GURL& url,
2399 const gfx::Size& size,
2400 const std::string& json_arguments,
2401 std::string* json_retval) {
[email protected]12636df2009-09-28 22:32:212402 SendAndRunNestedMessageLoop(new ViewHostMsg_ShowModalHTMLDialog(
[email protected]f103ab72009-09-02 17:10:592403 routing_id_, url, size.width(), size.height(), json_arguments,
[email protected]12636df2009-09-28 22:32:212404 json_retval));
[email protected]f103ab72009-09-02 17:10:592405}
2406
initial.commit09911bf2008-07-26 23:55:292407void RenderView::SyncNavigationState() {
2408 if (!webview())
2409 return;
2410
[email protected]26aa0482009-09-30 16:55:272411 const WebHistoryItem& item = webview()->mainFrame()->currentHistoryItem();
[email protected]ca948a22009-06-25 19:36:172412 if (item.isNull())
initial.commit09911bf2008-07-26 23:55:292413 return;
[email protected]ca948a22009-06-25 19:36:172414
2415 Send(new ViewHostMsg_UpdateState(
2416 routing_id_, page_id_, webkit_glue::HistoryItemToString(item)));
initial.commit09911bf2008-07-26 23:55:292417}
2418
2419void RenderView::ShowContextMenu(WebView* webview,
[email protected]581b87eb2009-07-23 23:06:562420 ContextNodeType node_type,
initial.commit09911bf2008-07-26 23:55:292421 int x,
2422 int y,
2423 const GURL& link_url,
[email protected]574a1d62009-07-17 03:23:462424 const GURL& src_url,
initial.commit09911bf2008-07-26 23:55:292425 const GURL& page_url,
2426 const GURL& frame_url,
[email protected]574a1d62009-07-17 03:23:462427 const ContextMenuMediaParams& media_params,
initial.commit09911bf2008-07-26 23:55:292428 const std::wstring& selection_text,
2429 const std::wstring& misspelled_word,
[email protected]6aa376b2008-09-23 18:49:522430 int edit_flags,
[email protected]c9825a42009-05-01 22:51:502431 const std::string& security_info,
2432 const std::string& frame_charset) {
[email protected]e09ba552009-02-05 03:26:292433 ContextMenuParams params;
[email protected]581b87eb2009-07-23 23:06:562434 params.node_type = node_type;
initial.commit09911bf2008-07-26 23:55:292435 params.x = x;
2436 params.y = y;
[email protected]574a1d62009-07-17 03:23:462437 params.src_url = src_url;
initial.commit09911bf2008-07-26 23:55:292438 params.link_url = link_url;
[email protected]e6c79812009-04-22 22:31:422439 params.unfiltered_link_url = link_url;
initial.commit09911bf2008-07-26 23:55:292440 params.page_url = page_url;
2441 params.frame_url = frame_url;
[email protected]574a1d62009-07-17 03:23:462442 params.media_params = media_params;
initial.commit09911bf2008-07-26 23:55:292443 params.selection_text = selection_text;
2444 params.misspelled_word = misspelled_word;
[email protected]be645db2009-02-06 20:36:332445 params.spellcheck_enabled =
[email protected]26aa0482009-09-30 16:55:272446 webview->focusedFrame()->isContinuousSpellCheckingEnabled();
initial.commit09911bf2008-07-26 23:55:292447 params.edit_flags = edit_flags;
[email protected]6aa376b2008-09-23 18:49:522448 params.security_info = security_info;
[email protected]c9825a42009-05-01 22:51:502449 params.frame_charset = frame_charset;
initial.commit09911bf2008-07-26 23:55:292450 Send(new ViewHostMsg_ContextMenu(routing_id_, params));
2451}
2452
[email protected]b0950a72009-09-29 23:16:172453bool RenderView::DownloadImage(int id, const GURL& image_url, int image_size) {
2454 // Make sure webview was not shut down.
2455 if (!webview())
2456 return false;
2457 // Create an image resource fetcher and assign it with a call back object.
2458 image_fetchers_.insert(new ImageResourceFetcher(
[email protected]26aa0482009-09-30 16:55:272459 image_url, webview()->mainFrame(), id, image_size,
[email protected]b0950a72009-09-29 23:16:172460 NewCallback(this, &RenderView::DidDownloadImage)));
2461 return true;
2462}
2463
2464void RenderView::DidDownloadImage(ImageResourceFetcher* fetcher,
initial.commit09911bf2008-07-26 23:55:292465 const SkBitmap& image) {
[email protected]b0950a72009-09-29 23:16:172466 // Notify requester of image download status.
2467 Send(new ViewHostMsg_DidDownloadFavIcon(routing_id_,
2468 fetcher->id(),
2469 fetcher->image_url(),
2470 image.isNull(),
2471 image));
2472 // Dispose of the image fetcher.
2473 DCHECK(image_fetchers_.find(fetcher) != image_fetchers_.end());
2474 image_fetchers_.erase(fetcher);
2475 // We're in the callback from the ImageResourceFetcher, best to delay
2476 // deletion.
2477 MessageLoop::current()->DeleteSoon(FROM_HERE, fetcher);
initial.commit09911bf2008-07-26 23:55:292478}
2479
[email protected]bf5c2ff392009-07-08 16:24:332480void RenderView::OnDownloadFavIcon(int id,
2481 const GURL& image_url,
2482 int image_size) {
[email protected]f11ca0732009-04-11 00:09:342483 bool data_image_failed = false;
2484 if (image_url.SchemeIs("data")) {
2485 SkBitmap data_image = ImageFromDataUrl(image_url);
2486 data_image_failed = data_image.empty();
2487 if (!data_image_failed) {
[email protected]bf5c2ff392009-07-08 16:24:332488 Send(new ViewHostMsg_DidDownloadFavIcon(routing_id_, id, image_url, false,
2489 data_image));
[email protected]f11ca0732009-04-11 00:09:342490 }
2491 }
2492
[email protected]bf5c2ff392009-07-08 16:24:332493 if (data_image_failed ||
[email protected]b0950a72009-09-29 23:16:172494 !DownloadImage(id, image_url, image_size)) {
[email protected]bf5c2ff392009-07-08 16:24:332495 Send(new ViewHostMsg_DidDownloadFavIcon(routing_id_, id, image_url, true,
2496 SkBitmap()));
2497 }
initial.commit09911bf2008-07-26 23:55:292498}
2499
[email protected]f11ca0732009-04-11 00:09:342500SkBitmap RenderView::ImageFromDataUrl(const GURL& url) const {
2501 std::string mime_type, char_set, data;
2502 if (net::DataURL::Parse(url, &mime_type, &char_set, &data) && !data.empty()) {
2503 // Decode the favicon using WebKit's image decoder.
2504 webkit_glue::ImageDecoder decoder(gfx::Size(kFavIconSize, kFavIconSize));
2505 const unsigned char* src_data =
2506 reinterpret_cast<const unsigned char*>(&data[0]);
2507
2508 return decoder.Decode(src_data, data.size());
2509 }
2510 return SkBitmap();
2511}
2512
initial.commit09911bf2008-07-26 23:55:292513void RenderView::OnGetApplicationInfo(int page_id) {
2514 webkit_glue::WebApplicationInfo app_info;
2515 if (page_id == page_id_)
2516 webkit_glue::GetApplicationInfo(webview(), &app_info);
2517
2518 // Prune out any data URLs in the set of icons. The browser process expects
2519 // any icon with a data URL to have originated from a favicon. We don't want
2520 // to decode arbitrary data URLs in the browser process. See
2521 // http://b/issue?id=1162972
2522 for (size_t i = 0; i < app_info.icons.size(); ++i) {
[email protected]6de74452009-02-25 18:04:592523 if (app_info.icons[i].url.SchemeIs(chrome::kDataScheme)) {
initial.commit09911bf2008-07-26 23:55:292524 app_info.icons.erase(app_info.icons.begin() + i);
2525 --i;
2526 }
2527 }
2528
2529 Send(new ViewHostMsg_DidGetApplicationInfo(routing_id_, page_id, app_info));
2530}
2531
[email protected]7ccddb8c2009-08-04 17:36:552532GURL RenderView::GetAlternateErrorPageURL(const GURL& failed_url,
initial.commit09911bf2008-07-26 23:55:292533 ErrorPageType error_type) {
[email protected]7ccddb8c2009-08-04 17:36:552534 if (failed_url.SchemeIsSecure()) {
initial.commit09911bf2008-07-26 23:55:292535 // If the URL that failed was secure, then the embedding web page was not
2536 // expecting a network attacker to be able to manipulate its contents. As
2537 // we fetch alternate error pages over HTTP, we would be allowing a network
2538 // attacker to manipulate the contents of the response if we tried to use
2539 // the link doctor here.
2540 return GURL::EmptyGURL();
2541 }
2542
2543 // Grab the base URL from the browser process.
2544 if (!alternate_error_page_url_.is_valid())
2545 return GURL::EmptyGURL();
2546
2547 // Strip query params from the failed URL.
2548 GURL::Replacements remove_params;
2549 remove_params.ClearUsername();
2550 remove_params.ClearPassword();
2551 remove_params.ClearQuery();
2552 remove_params.ClearRef();
[email protected]7ccddb8c2009-08-04 17:36:552553 const GURL url_to_send = failed_url.ReplaceComponents(remove_params);
initial.commit09911bf2008-07-26 23:55:292554
2555 // Construct the query params to send to link doctor.
2556 std::string params(alternate_error_page_url_.query());
2557 params.append("&url=");
2558 params.append(EscapeQueryParamValue(url_to_send.spec()));
2559 params.append("&sourceid=chrome");
2560 params.append("&error=");
2561 switch (error_type) {
2562 case DNS_ERROR:
2563 params.append("dnserror");
2564 break;
2565
2566 case HTTP_404:
2567 params.append("http404");
2568 break;
2569
[email protected]5df266ac2008-10-15 19:50:132570 case CONNECTION_ERROR:
[email protected]e1f934b2009-01-26 20:41:332571 params.append("connectionfailure");
[email protected]5df266ac2008-10-15 19:50:132572 break;
2573
initial.commit09911bf2008-07-26 23:55:292574 default:
2575 NOTREACHED() << "unknown ErrorPageType";
2576 }
2577
2578 // OK, build the final url to return.
2579 GURL::Replacements link_doctor_params;
2580 link_doctor_params.SetQueryStr(params);
2581 GURL url = alternate_error_page_url_.ReplaceComponents(link_doctor_params);
2582 return url;
2583}
2584
[email protected]7ea066a2009-04-06 20:21:592585void RenderView::OnFind(int request_id,
2586 const string16& search_text,
2587 const WebKit::WebFindOptions& options) {
[email protected]26aa0482009-09-30 16:55:272588 WebFrame* main_frame = webview()->mainFrame();
[email protected]b4bb2502009-10-01 22:35:272589 WebFrame* frame_after_main = main_frame->traverseNext(true);
[email protected]26aa0482009-09-30 16:55:272590 WebFrame* focused_frame = webview()->focusedFrame();
initial.commit09911bf2008-07-26 23:55:292591 WebFrame* search_frame = focused_frame; // start searching focused frame.
2592
2593 bool multi_frame = (frame_after_main != main_frame);
2594
2595 // If we have multiple frames, we don't want to wrap the search within the
2596 // frame, so we check here if we only have main_frame in the chain.
2597 bool wrap_within_frame = !multi_frame;
2598
[email protected]b3f2b912009-04-09 16:18:522599 WebRect selection_rect;
initial.commit09911bf2008-07-26 23:55:292600 bool result = false;
2601
2602 do {
[email protected]dd7daa82009-08-10 05:46:452603 result = search_frame->find(
[email protected]7ea066a2009-04-06 20:21:592604 request_id, search_text, options, wrap_within_frame, &selection_rect);
initial.commit09911bf2008-07-26 23:55:292605
2606 if (!result) {
2607 // don't leave text selected as you move to the next frame.
[email protected]a100d76bb2009-08-14 17:50:222608 search_frame->executeCommand(WebString::fromUTF8("Unselect"));
initial.commit09911bf2008-07-26 23:55:292609
2610 // Find the next frame, but skip the invisible ones.
2611 do {
2612 // What is the next frame to search? (we might be going backwards). Note
2613 // that we specify wrap=true so that search_frame never becomes NULL.
[email protected]7ea066a2009-04-06 20:21:592614 search_frame = options.forward ?
[email protected]b4bb2502009-10-01 22:35:272615 search_frame->traverseNext(true) :
2616 search_frame->traversePrevious(true);
[email protected]dd7daa82009-08-10 05:46:452617 } while (!search_frame->hasVisibleContent() &&
2618 search_frame != focused_frame);
initial.commit09911bf2008-07-26 23:55:292619
[email protected]884db412008-11-24 23:46:502620 // Make sure selection doesn't affect the search operation in new frame.
[email protected]a100d76bb2009-08-14 17:50:222621 search_frame->executeCommand(WebString::fromUTF8("Unselect"));
initial.commit09911bf2008-07-26 23:55:292622
2623 // If we have multiple frames and we have wrapped back around to the
2624 // focused frame, we need to search it once more allowing wrap within
2625 // the frame, otherwise it will report 'no match' if the focused frame has
2626 // reported matches, but no frames after the focused_frame contain a
2627 // match for the search word(s).
2628 if (multi_frame && search_frame == focused_frame) {
[email protected]dd7daa82009-08-10 05:46:452629 result = search_frame->find(
[email protected]7ea066a2009-04-06 20:21:592630 request_id, search_text, options, true, // Force wrapping.
2631 &selection_rect);
initial.commit09911bf2008-07-26 23:55:292632 }
2633 }
2634
[email protected]26aa0482009-09-30 16:55:272635 webview()->setFocusedFrame(search_frame);
initial.commit09911bf2008-07-26 23:55:292636 } while (!result && search_frame != focused_frame);
2637
[email protected]7ea066a2009-04-06 20:21:592638 if (options.findNext) {
[email protected]4f3dc372009-02-24 00:10:292639 // Force the main_frame to report the actual count.
[email protected]dd7daa82009-08-10 05:46:452640 main_frame->increaseMatchCount(0, request_id);
[email protected]4f3dc372009-02-24 00:10:292641 } else {
2642 // If nothing is found, set result to "0 of 0", otherwise, set it to
2643 // "-1 of 1" to indicate that we found at least one item, but we don't know
2644 // yet what is active.
2645 int ordinal = result ? -1 : 0; // -1 here means, we might know more later.
2646 int match_count = result ? 1 : 0; // 1 here means possibly more coming.
initial.commit09911bf2008-07-26 23:55:292647
[email protected]4f3dc372009-02-24 00:10:292648 // If we find no matches then this will be our last status update.
2649 // Otherwise the scoping effort will send more results.
2650 bool final_status_update = !result;
initial.commit09911bf2008-07-26 23:55:292651
[email protected]4f3dc372009-02-24 00:10:292652 // Send the search result over to the browser process.
[email protected]4f999132009-03-31 18:08:402653 Send(new ViewHostMsg_Find_Reply(routing_id_,
[email protected]7ea066a2009-04-06 20:21:592654 request_id,
[email protected]4f3dc372009-02-24 00:10:292655 match_count,
2656 selection_rect,
2657 ordinal,
2658 final_status_update));
initial.commit09911bf2008-07-26 23:55:292659
initial.commit09911bf2008-07-26 23:55:292660 // Scoping effort begins, starting with the mainframe.
2661 search_frame = main_frame;
2662
[email protected]dd7daa82009-08-10 05:46:452663 main_frame->resetMatchCount();
initial.commit09911bf2008-07-26 23:55:292664
2665 do {
2666 // Cancel all old scoping requests before starting a new one.
[email protected]dd7daa82009-08-10 05:46:452667 search_frame->cancelPendingScopingEffort();
initial.commit09911bf2008-07-26 23:55:292668
2669 // We don't start another scoping effort unless at least one match has
2670 // been found.
2671 if (result) {
2672 // Start new scoping request. If the scoping function determines that it
2673 // needs to scope, it will defer until later.
[email protected]dd7daa82009-08-10 05:46:452674 search_frame->scopeStringMatches(request_id,
[email protected]7ea066a2009-04-06 20:21:592675 search_text,
2676 options,
initial.commit09911bf2008-07-26 23:55:292677 true); // reset the tickmarks
2678 }
2679
2680 // Iterate to the next frame. The frame will not necessarily scope, for
2681 // example if it is not visible.
[email protected]b4bb2502009-10-01 22:35:272682 search_frame = search_frame->traverseNext(true);
initial.commit09911bf2008-07-26 23:55:292683 } while (search_frame != main_frame);
2684 }
2685}
2686
[email protected]5c4266922009-07-10 16:41:272687void RenderView::OnDeterminePageText() {
2688 if (!is_loading_) {
2689 if (!webview())
2690 return;
[email protected]26aa0482009-09-30 16:55:272691 WebFrame* main_frame = webview()->mainFrame();
[email protected]5c4266922009-07-10 16:41:272692 std::wstring contents;
2693 CaptureText(main_frame, &contents);
2694 Send(new ViewMsg_DeterminePageText_Reply(routing_id_, contents));
2695 determine_page_text_after_loading_stops_ = false;
2696 return;
2697 }
2698
2699 // We set |determine_page_text_after_loading_stops_| true here so that,
2700 // after page has been loaded completely, the text in the page is captured.
2701 determine_page_text_after_loading_stops_ = true;
2702}
2703
initial.commit09911bf2008-07-26 23:55:292704void RenderView::ReportFindInPageMatchCount(int count, int request_id,
2705 bool final_update) {
2706 // If we have a message that has been queued up, then we should just replace
2707 // it. The ACK from the browser will make sure it gets sent when the browser
2708 // wants it.
2709 if (queued_find_reply_message_.get()) {
2710 IPC::Message* msg = new ViewHostMsg_Find_Reply(
2711 routing_id_,
2712 request_id,
2713 count,
[email protected]b3f2b912009-04-09 16:18:522714 gfx::Rect(),
initial.commit09911bf2008-07-26 23:55:292715 -1, // Don't update active match ordinal.
2716 final_update);
2717 queued_find_reply_message_.reset(msg);
2718 } else {
2719 // Send the search result over to the browser process.
2720 Send(new ViewHostMsg_Find_Reply(
2721 routing_id_,
2722 request_id,
2723 count,
[email protected]b3f2b912009-04-09 16:18:522724 gfx::Rect(),
initial.commit09911bf2008-07-26 23:55:292725 -1, // // Don't update active match ordinal.
2726 final_update));
2727 }
2728}
2729
2730void RenderView::ReportFindInPageSelection(int request_id,
2731 int active_match_ordinal,
[email protected]b3f2b912009-04-09 16:18:522732 const WebRect& selection_rect) {
initial.commit09911bf2008-07-26 23:55:292733 // Send the search result over to the browser process.
2734 Send(new ViewHostMsg_Find_Reply(routing_id_,
2735 request_id,
2736 -1,
2737 selection_rect,
2738 active_match_ordinal,
2739 false));
2740}
2741
[email protected]ed4bf2d2009-05-05 00:10:062742bool RenderView::WasOpenedByUserGesture() const {
initial.commit09911bf2008-07-26 23:55:292743 return opened_by_user_gesture_;
2744}
2745
initial.commit09911bf2008-07-26 23:55:292746void RenderView::DnsPrefetch(const std::vector<std::string>& host_names) {
2747 Send(new ViewHostMsg_DnsPrefetch(host_names));
2748}
2749
[email protected]630e26b2008-10-14 22:55:172750void RenderView::OnZoom(int function) {
2751 static const bool kZoomIsTextOnly = false;
2752 switch (function) {
2753 case PageZoom::SMALLER:
[email protected]26aa0482009-09-30 16:55:272754 webview()->zoomOut(kZoomIsTextOnly);
initial.commit09911bf2008-07-26 23:55:292755 break;
[email protected]630e26b2008-10-14 22:55:172756 case PageZoom::STANDARD:
[email protected]26aa0482009-09-30 16:55:272757 webview()->zoomDefault();
initial.commit09911bf2008-07-26 23:55:292758 break;
[email protected]630e26b2008-10-14 22:55:172759 case PageZoom::LARGER:
[email protected]26aa0482009-09-30 16:55:272760 webview()->zoomIn(kZoomIsTextOnly);
initial.commit09911bf2008-07-26 23:55:292761 break;
2762 default:
2763 NOTREACHED();
2764 }
2765}
2766
[email protected]41fc0322009-09-04 22:23:402767void RenderView::OnSetPageEncoding(const std::string& encoding_name) {
[email protected]26aa0482009-09-30 16:55:272768 webview()->setPageEncoding(WebString::fromUTF8(encoding_name));
initial.commit09911bf2008-07-26 23:55:292769}
2770
[email protected]a697f4c2009-09-14 22:30:182771void RenderView::OnResetPageEncodingToDefault() {
[email protected]26aa0482009-09-30 16:55:272772 WebString no_encoding;
2773 webview()->setPageEncoding(no_encoding);
[email protected]a697f4c2009-09-14 22:30:182774}
2775
[email protected]0df30122009-06-03 12:13:082776void RenderView::UpdateInspectorSettings(const std::wstring& raw_settings) {
2777 Send(new ViewHostMsg_UpdateInspectorSettings(routing_id_, raw_settings));
2778}
2779
[email protected]611cad42009-03-16 18:51:342780WebDevToolsAgentDelegate* RenderView::GetWebDevToolsAgentDelegate() {
[email protected]b75b7d072009-04-06 13:47:002781 return devtools_agent_.get();
[email protected]611cad42009-03-16 18:51:342782}
2783
[email protected]dd7daa82009-08-10 05:46:452784WebFrame* RenderView::GetChildFrame(const std::wstring& xpath) const {
2785 if (xpath.empty())
[email protected]26aa0482009-09-30 16:55:272786 return webview()->mainFrame();
[email protected]dd7daa82009-08-10 05:46:452787
2788 // xpath string can represent a frame deep down the tree (across multiple
2789 // frame DOMs).
2790 // Example, /html/body/table/tbody/tr/td/iframe\n/frameset/frame[0]
2791 // should break into 2 xpaths
2792 // /html/body/table/tbody/tr/td/iframe & /frameset/frame[0]
2793
[email protected]26aa0482009-09-30 16:55:272794 WebFrame* frame = webview()->mainFrame();
[email protected]dd7daa82009-08-10 05:46:452795
2796 std::wstring xpath_remaining = xpath;
2797 while (!xpath_remaining.empty()) {
2798 std::wstring::size_type delim_pos = xpath_remaining.find_first_of(L'\n');
2799 std::wstring xpath_child;
2800 if (delim_pos != std::wstring::npos) {
2801 xpath_child = xpath_remaining.substr(0, delim_pos);
2802 xpath_remaining.erase(0, delim_pos + 1);
2803 } else {
2804 xpath_remaining.swap(xpath_child);
2805 }
2806 frame = frame->findChildByExpression(WideToUTF16Hack(xpath_child));
initial.commit09911bf2008-07-26 23:55:292807 }
2808
[email protected]dd7daa82009-08-10 05:46:452809 return frame;
initial.commit09911bf2008-07-26 23:55:292810}
2811
[email protected]f29acf52008-11-03 20:08:332812void RenderView::EvaluateScript(const std::wstring& frame_xpath,
2813 const std::wstring& script) {
initial.commit09911bf2008-07-26 23:55:292814 WebFrame* web_frame = GetChildFrame(frame_xpath);
2815 if (!web_frame)
2816 return;
2817
[email protected]dd7daa82009-08-10 05:46:452818 web_frame->executeScript(WebScriptSource(WideToUTF16Hack(script)));
initial.commit09911bf2008-07-26 23:55:292819}
2820
[email protected]1810e132009-03-24 23:35:482821void RenderView::InsertCSS(const std::wstring& frame_xpath,
[email protected]ffaef0c2009-09-15 17:08:082822 const std::string& css,
2823 const std::string& id) {
[email protected]1810e132009-03-24 23:35:482824 WebFrame* web_frame = GetChildFrame(frame_xpath);
2825 if (!web_frame)
2826 return;
2827
[email protected]ffaef0c2009-09-15 17:08:082828 web_frame->insertStyleText(WebString::fromUTF8(css), WebString::fromUTF8(id));
[email protected]1810e132009-03-24 23:35:482829}
2830
initial.commit09911bf2008-07-26 23:55:292831void RenderView::OnScriptEvalRequest(const std::wstring& frame_xpath,
2832 const std::wstring& jscript) {
[email protected]f29acf52008-11-03 20:08:332833 EvaluateScript(frame_xpath, jscript);
initial.commit09911bf2008-07-26 23:55:292834}
2835
[email protected]1810e132009-03-24 23:35:482836void RenderView::OnCSSInsertRequest(const std::wstring& frame_xpath,
[email protected]ffaef0c2009-09-15 17:08:082837 const std::string& css,
2838 const std::string& id) {
2839 InsertCSS(frame_xpath, css, id);
[email protected]ae461542009-06-19 19:03:412840
2841 // Notify RenderViewHost that css has been inserted into the frame.
2842 Send(new ViewHostMsg_OnCSSInserted(routing_id_));
[email protected]1810e132009-03-24 23:35:482843}
2844
[email protected]7ea066a2009-04-06 20:21:592845void RenderView::OnAddMessageToConsole(
2846 const string16& frame_xpath,
2847 const string16& message,
2848 const WebConsoleMessage::Level& level) {
2849 WebFrame* web_frame = GetChildFrame(UTF16ToWideHack(frame_xpath));
[email protected]0dea3ea2009-03-31 23:30:592850 if (web_frame)
[email protected]dd7daa82009-08-10 05:46:452851 web_frame->addMessageToConsole(WebConsoleMessage(level, message));
initial.commit09911bf2008-07-26 23:55:292852}
2853
[email protected]81e63782009-02-27 19:35:092854void RenderView::OnAllowBindings(int enabled_bindings_flags) {
2855 enabled_bindings_ |= enabled_bindings_flags;
initial.commit09911bf2008-07-26 23:55:292856}
2857
2858void RenderView::OnSetDOMUIProperty(const std::string& name,
2859 const std::string& value) {
[email protected]81e63782009-02-27 19:35:092860 DCHECK(BindingsPolicy::is_dom_ui_enabled(enabled_bindings_));
initial.commit09911bf2008-07-26 23:55:292861 dom_ui_bindings_.SetProperty(name, value);
2862}
2863
2864void RenderView::OnReservePageIDRange(int size_of_range) {
2865 next_page_id_ += size_of_range + 1;
2866}
2867
[email protected]e80c73b2009-04-07 23:24:582868void RenderView::OnDragSourceEndedOrMoved(const gfx::Point& client_point,
2869 const gfx::Point& screen_point,
[email protected]1d9f4132009-09-08 17:29:252870 bool ended,
2871 WebDragOperation op) {
[email protected]5f9ae6c2009-07-08 02:38:032872 if (ended) {
[email protected]26aa0482009-09-30 16:55:272873 webview()->dragSourceEndedAt(client_point, screen_point, op);
[email protected]5f9ae6c2009-07-08 02:38:032874 } else {
[email protected]26aa0482009-09-30 16:55:272875 webview()->dragSourceMovedTo(client_point, screen_point);
[email protected]5f9ae6c2009-07-08 02:38:032876 }
initial.commit09911bf2008-07-26 23:55:292877}
2878
2879void RenderView::OnDragSourceSystemDragEnded() {
[email protected]26aa0482009-09-30 16:55:272880 webview()->dragSourceSystemDragEnded();
initial.commit09911bf2008-07-26 23:55:292881}
2882
2883void RenderView::OnUploadFileRequest(const ViewMsg_UploadFile_Params& p) {
2884 webkit_glue::FileUploadData* f = new webkit_glue::FileUploadData;
2885 f->file_path = p.file_path;
2886 f->form_name = p.form;
2887 f->file_name = p.file;
2888 f->submit_name = p.submit;
2889
2890 // Build the other form values map.
2891 if (!p.other_values.empty()) {
2892 std::vector<std::wstring> e;
2893 std::vector<std::wstring> kvp;
2894 std::vector<std::wstring>::iterator i;
2895
2896 SplitString(p.other_values, L'\n', &e);
2897 for (i = e.begin(); i != e.end(); ++i) {
2898 SplitString(*i, L'=', &kvp);
2899 if (kvp.size() == 2)
2900 f->other_form_values[kvp[0]] = kvp[1];
2901 kvp.clear();
2902 }
2903 }
2904
2905 pending_upload_data_.reset(f);
2906 ProcessPendingUpload();
2907}
2908
2909void RenderView::ProcessPendingUpload() {
2910 webkit_glue::FileUploadData* f = pending_upload_data_.get();
2911 if (f && webview() && webkit_glue::FillFormToUploadFile(webview(), *f))
2912 ResetPendingUpload();
2913}
2914
2915void RenderView::ResetPendingUpload() {
2916 pending_upload_data_.reset();
2917}
2918
2919void RenderView::OnFormFill(const FormData& form) {
2920 webkit_glue::FillForm(this->webview(), form);
2921}
2922
2923void RenderView::OnFillPasswordForm(
[email protected]daa8c58e2009-06-15 17:21:102924 const webkit_glue::PasswordFormDomManager::FillData& form_data) {
initial.commit09911bf2008-07-26 23:55:292925 webkit_glue::FillPasswordForm(this->webview(), form_data);
2926}
2927
2928void RenderView::OnDragTargetDragEnter(const WebDropData& drop_data,
[email protected]e80c73b2009-04-07 23:24:582929 const gfx::Point& client_point,
[email protected]1d9f4132009-09-08 17:29:252930 const gfx::Point& screen_point,
2931 WebDragOperationsMask ops) {
[email protected]26aa0482009-09-30 16:55:272932 WebDragOperation operation = webview()->dragTargetDragEnter(
[email protected]e80c73b2009-04-07 23:24:582933 drop_data.ToDragData(),
2934 drop_data.identity,
2935 client_point,
[email protected]1d9f4132009-09-08 17:29:252936 screen_point,
2937 ops);
initial.commit09911bf2008-07-26 23:55:292938
[email protected]1d9f4132009-09-08 17:29:252939 Send(new ViewHostMsg_UpdateDragCursor(routing_id_, operation));
initial.commit09911bf2008-07-26 23:55:292940}
2941
[email protected]e80c73b2009-04-07 23:24:582942void RenderView::OnDragTargetDragOver(const gfx::Point& client_point,
[email protected]1d9f4132009-09-08 17:29:252943 const gfx::Point& screen_point,
2944 WebDragOperationsMask ops) {
[email protected]26aa0482009-09-30 16:55:272945 WebDragOperation operation = webview()->dragTargetDragOver(
[email protected]1d9f4132009-09-08 17:29:252946 client_point,
2947 screen_point,
2948 ops);
initial.commit09911bf2008-07-26 23:55:292949
[email protected]1d9f4132009-09-08 17:29:252950 Send(new ViewHostMsg_UpdateDragCursor(routing_id_, operation));
initial.commit09911bf2008-07-26 23:55:292951}
2952
2953void RenderView::OnDragTargetDragLeave() {
[email protected]26aa0482009-09-30 16:55:272954 webview()->dragTargetDragLeave();
initial.commit09911bf2008-07-26 23:55:292955}
2956
[email protected]e80c73b2009-04-07 23:24:582957void RenderView::OnDragTargetDrop(const gfx::Point& client_point,
2958 const gfx::Point& screen_point) {
[email protected]26aa0482009-09-30 16:55:272959 webview()->dragTargetDrop(client_point, screen_point);
initial.commit09911bf2008-07-26 23:55:292960}
2961
2962void RenderView::OnUpdateWebPreferences(const WebPreferences& prefs) {
[email protected]2fab253a2009-08-17 23:00:592963 webkit_preferences_ = prefs;
2964 webkit_preferences_.Apply(webview());
initial.commit09911bf2008-07-26 23:55:292965}
2966
2967void RenderView::OnSetAltErrorPageURL(const GURL& url) {
2968 alternate_error_page_url_ = url;
2969}
2970
initial.commit09911bf2008-07-26 23:55:292971void RenderView::OnInstallMissingPlugin() {
2972 // This could happen when the first default plugin is deleted.
[email protected]f103ab72009-09-02 17:10:592973 if (first_default_plugin_)
2974 first_default_plugin_->InstallMissingPlugin();
initial.commit09911bf2008-07-26 23:55:292975}
2976
[email protected]b62d1a8c2009-01-13 23:54:572977void RenderView::OnFileChooserResponse(
[email protected]561abe62009-04-06 18:08:342978 const std::vector<FilePath>& file_names) {
[email protected]8029f5672009-03-20 22:33:362979 // This could happen if we navigated to a different page before the user
2980 // closed the chooser.
2981 if (!file_chooser_.get())
2982 return;
2983
[email protected]b62d1a8c2009-01-13 23:54:572984 file_chooser_->OnFileChoose(file_names);
initial.commit09911bf2008-07-26 23:55:292985 file_chooser_.reset();
2986}
2987
2988void RenderView::OnEnableViewSourceMode() {
2989 if (!webview())
2990 return;
[email protected]26aa0482009-09-30 16:55:272991 WebFrame* main_frame = webview()->mainFrame();
initial.commit09911bf2008-07-26 23:55:292992 if (!main_frame)
2993 return;
2994
[email protected]dd7daa82009-08-10 05:46:452995 main_frame->enableViewSourceMode(true);
initial.commit09911bf2008-07-26 23:55:292996}
2997
[email protected]0666aef2009-05-13 19:48:082998void RenderView::OnEnableIntrinsicWidthChangedMode() {
2999 send_preferred_width_changes_ = true;
3000}
3001
[email protected]80d96fa2009-06-10 22:34:513002void RenderView::OnSetRendererPrefs(const RendererPreferences& renderer_prefs) {
3003 renderer_preferences_ = renderer_prefs;
[email protected]6e282c92009-07-24 01:19:373004 UpdateFontRenderingFromRendererPrefs();
[email protected]7a74e102009-09-03 00:16:563005#if defined(OS_LINUX)
[email protected]1c83eb42009-09-11 21:08:413006 WebColorName name = WebKit::WebColorWebkitFocusRingColor;
3007 WebKit::setNamedColors(&name, &renderer_prefs.focus_ring_color, 1);
[email protected]7a74e102009-09-03 00:16:563008#endif
[email protected]80d96fa2009-06-10 22:34:513009}
3010
[email protected]581b87eb2009-07-23 23:06:563011void RenderView::OnMediaPlayerActionAt(int x,
3012 int y,
3013 const MediaPlayerAction& action) {
3014 if (!webview())
3015 return;
3016
3017 webview()->MediaPlayerActionAt(x, y, action);
3018}
3019
[email protected]7b291f92009-08-14 05:43:533020void RenderView::OnNotifyRendererViewType(ViewType::Type type) {
[email protected]078b34612009-09-19 19:31:513021 // When this is first set, the bindings aren't fully loaded. We only need
3022 // to call through this API after the page has already been loaded. It's
3023 // also called in didCreateDocumentElement to bootstrap.
3024 if (view_type_ != ViewType::INVALID) {
3025 if (type == ViewType::EXTENSION_MOLE ||
3026 type == ViewType::EXTENSION_TOOLSTRIP) {
3027 ExtensionProcessBindings::SetViewType(webview(), type);
3028 }
3029 }
[email protected]7b291f92009-08-14 05:43:533030 view_type_ = type;
3031}
3032
3033void RenderView::OnUpdateBrowserWindowId(int window_id) {
3034 browser_window_id_ = window_id;
3035}
3036
initial.commit09911bf2008-07-26 23:55:293037void RenderView::OnUpdateBackForwardListCount(int back_list_count,
3038 int forward_list_count) {
3039 history_back_list_count_ = back_list_count;
3040 history_forward_list_count_ = forward_list_count;
3041}
3042
[email protected]266eb6f2008-09-30 23:56:503043void RenderView::OnGetAccessibilityInfo(
[email protected]6a983b42009-03-20 20:12:253044 const webkit_glue::WebAccessibility::InParams& in_params,
3045 webkit_glue::WebAccessibility::OutParams* out_params) {
[email protected]6c8afae52009-01-22 02:24:573046#if defined(OS_WIN)
[email protected]6a983b42009-03-20 20:12:253047 if (!web_accessibility_manager_.get()) {
3048 web_accessibility_manager_.reset(
3049 webkit_glue::WebAccessibilityManager::Create());
3050 }
[email protected]266eb6f2008-09-30 23:56:503051
[email protected]6a983b42009-03-20 20:12:253052 if (!web_accessibility_manager_->GetAccObjInfo(webview(), in_params,
3053 out_params)) {
[email protected]266eb6f2008-09-30 23:56:503054 return;
3055 }
[email protected]6c8afae52009-01-22 02:24:573056#else // defined(OS_WIN)
3057 // TODO(port): accessibility not yet implemented
3058 NOTIMPLEMENTED();
3059#endif
[email protected]266eb6f2008-09-30 23:56:503060}
3061
[email protected]6a983b42009-03-20 20:12:253062void RenderView::OnClearAccessibilityInfo(int acc_obj_id, bool clear_all) {
[email protected]6c8afae52009-01-22 02:24:573063#if defined(OS_WIN)
[email protected]6a983b42009-03-20 20:12:253064 if (!web_accessibility_manager_.get()) {
[email protected]266eb6f2008-09-30 23:56:503065 // If accessibility is not activated, ignore clearing message.
3066 return;
3067 }
[email protected]e846d0d2009-05-20 00:53:063068
[email protected]6a983b42009-03-20 20:12:253069 if (!web_accessibility_manager_->ClearAccObjMap(acc_obj_id, clear_all))
[email protected]266eb6f2008-09-30 23:56:503070 return;
[email protected]e846d0d2009-05-20 00:53:063071
[email protected]6c8afae52009-01-22 02:24:573072#else // defined(OS_WIN)
3073 // TODO(port): accessibility not yet implemented
3074 NOTIMPLEMENTED();
3075#endif
[email protected]266eb6f2008-09-30 23:56:503076}
3077
initial.commit09911bf2008-07-26 23:55:293078void RenderView::OnGetAllSavableResourceLinksForCurrentPage(
3079 const GURL& page_url) {
3080 // Prepare list to storage all savable resource links.
3081 std::vector<GURL> resources_list;
3082 std::vector<GURL> referrers_list;
3083 std::vector<GURL> frames_list;
3084 webkit_glue::SavableResourcesResult result(&resources_list,
3085 &referrers_list,
3086 &frames_list);
3087
3088 if (!webkit_glue::GetAllSavableResourceLinksForCurrentPage(webview(),
3089 page_url,
3090 &result)) {
3091 // If something is wrong when collecting all savable resource links,
3092 // send empty list to embedder(browser) to tell it failed.
3093 referrers_list.clear();
3094 resources_list.clear();
3095 frames_list.clear();
3096 }
3097
3098 // Send result of all savable resource links to embedder.
3099 Send(new ViewHostMsg_SendCurrentPageAllSavableResourceLinks(routing_id_,
3100 resources_list,
3101 referrers_list,
3102 frames_list));
3103}
3104
3105void RenderView::OnGetSerializedHtmlDataForCurrentPageWithLocalLinks(
[email protected]f6b48532009-02-12 01:56:323106 const std::vector<GURL>& links,
[email protected]fde6714d12009-02-18 22:39:313107 const std::vector<FilePath>& local_paths,
3108 const FilePath& local_directory_name) {
[email protected]26aa0482009-09-30 16:55:273109 webkit_glue::DomSerializer dom_serializer(webview()->mainFrame(),
initial.commit09911bf2008-07-26 23:55:293110 true,
3111 this,
3112 links,
3113 local_paths,
3114 local_directory_name);
3115 dom_serializer.SerializeDom();
3116}
3117
3118void RenderView::DidSerializeDataForFrame(const GURL& frame_url,
3119 const std::string& data, PageSavingSerializationStatus status) {
3120 Send(new ViewHostMsg_SendSerializedHtmlData(routing_id_,
3121 frame_url, data, static_cast<int32>(status)));
3122}
3123
[email protected]04b4a6c2008-08-02 00:44:473124void RenderView::OnMsgShouldClose() {
[email protected]26aa0482009-09-30 16:55:273125 bool should_close = webview()->dispatchBeforeUnloadEvent();
[email protected]04b4a6c2008-08-02 00:44:473126 Send(new ViewHostMsg_ShouldClose_ACK(routing_id_, should_close));
initial.commit09911bf2008-07-26 23:55:293127}
3128
[email protected]eb6b87a2009-07-24 15:57:393129void RenderView::OnClosePage(const ViewMsg_ClosePage_Params& params) {
initial.commit09911bf2008-07-26 23:55:293130 // TODO(creis): We'd rather use webview()->Close() here, but that currently
3131 // sets the WebView's delegate_ to NULL, preventing any JavaScript dialogs
3132 // in the onunload handler from appearing. For now, we're bypassing that and
3133 // calling the FrameLoader's CloseURL method directly. This should be
3134 // revisited to avoid having two ways to close a page. Having a single way
3135 // to close that can run onunload is also useful for fixing
3136 // http://b/issue?id=753080.
[email protected]26aa0482009-09-30 16:55:273137 WebFrame* main_frame = webview()->mainFrame();
[email protected]7a9b51f2009-06-29 21:28:293138 if (main_frame) {
[email protected]dd7daa82009-08-10 05:46:453139 const GURL& url = main_frame->url();
[email protected]3d9689372009-09-10 04:29:173140 // TODO(davemoore) this code should be removed once willClose() gets
[email protected]7a9b51f2009-06-29 21:28:293141 // called when a page is destroyed. DumpLoadHistograms() is safe to call
3142 // multiple times for the same frame, but it will simplify things.
[email protected]dd7daa82009-08-10 05:46:453143 if (url.SchemeIs(chrome::kHttpScheme) ||
3144 url.SchemeIs(chrome::kHttpsScheme))
[email protected]7a9b51f2009-06-29 21:28:293145 DumpLoadHistograms();
[email protected]7a9b51f2009-06-29 21:28:293146 }
[email protected]26aa0482009-09-30 16:55:273147 webview()->dispatchUnloadEvent();
initial.commit09911bf2008-07-26 23:55:293148
[email protected]eb6b87a2009-07-24 15:57:393149 // Just echo back the params in the ACK.
3150 Send(new ViewHostMsg_ClosePage_ACK(routing_id_, params));
initial.commit09911bf2008-07-26 23:55:293151}
3152
3153void RenderView::OnThemeChanged() {
[email protected]6c8afae52009-01-22 02:24:573154#if defined(OS_WIN)
initial.commit09911bf2008-07-26 23:55:293155 gfx::NativeTheme::instance()->CloseHandles();
3156 gfx::Rect view_rect(0, 0, size_.width(), size_.height());
[email protected]4873c7d2009-07-16 06:36:283157 didInvalidateRect(view_rect);
[email protected]6c8afae52009-01-22 02:24:573158#else // defined(OS_WIN)
3159 // TODO(port): we don't support theming on non-Windows platforms yet
3160 NOTIMPLEMENTED();
3161#endif
initial.commit09911bf2008-07-26 23:55:293162}
3163
[email protected]28790922009-03-09 19:48:373164void RenderView::OnMessageFromExternalHost(const std::string& message,
3165 const std::string& origin,
3166 const std::string& target) {
[email protected]3ac14a052008-08-15 21:22:153167 if (message.empty())
3168 return;
3169
[email protected]28790922009-03-09 19:48:373170 external_host_bindings_.ForwardMessageFromExternalHost(message, origin,
3171 target);
[email protected]3ac14a052008-08-15 21:22:153172}
3173
[email protected]0aa55312008-10-17 21:53:083174void RenderView::OnDisassociateFromPopupCount() {
3175 if (decrement_shared_popup_at_destruction_)
3176 shared_popup_counter_->data--;
3177 shared_popup_counter_ = new SharedRenderViewCounter(0);
3178 decrement_shared_popup_at_destruction_ = false;
3179}
3180
[email protected]15d79e12009-08-02 19:23:453181bool RenderView::MaybeLoadAlternateErrorPage(WebFrame* frame,
3182 const WebURLError& error,
3183 bool replace) {
3184 // We only show alternate error pages in the main frame. They are
3185 // intended to assist the user when navigating, so there is not much
3186 // value in showing them for failed subframes. Ideally, we would be
3187 // able to use the TYPED transition type for this, but that flag is
3188 // not preserved across page reloads.
[email protected]dd7daa82009-08-10 05:46:453189 if (frame->parent())
[email protected]15d79e12009-08-02 19:23:453190 return false;
3191
3192 // Use the alternate error page service if this is a DNS failure or
[email protected]c53976d52009-08-07 18:58:373193 // connection failure.
[email protected]15d79e12009-08-02 19:23:453194 int ec = error.reason;
3195 if (ec != net::ERR_NAME_NOT_RESOLVED &&
3196 ec != net::ERR_CONNECTION_FAILED &&
3197 ec != net::ERR_CONNECTION_REFUSED &&
3198 ec != net::ERR_ADDRESS_UNREACHABLE &&
[email protected]c53976d52009-08-07 18:58:373199 ec != net::ERR_CONNECTION_TIMED_OUT)
[email protected]15d79e12009-08-02 19:23:453200 return false;
3201
3202 const GURL& error_page_url = GetAlternateErrorPageURL(error.unreachableURL,
[email protected]7ccddb8c2009-08-04 17:36:553203 ec == net::ERR_NAME_NOT_RESOLVED ? DNS_ERROR : CONNECTION_ERROR);
[email protected]15d79e12009-08-02 19:23:453204 if (!error_page_url.is_valid())
3205 return false;
3206
3207 // Load an empty page first so there is an immediate response to the error,
3208 // and then kick off a request for the alternate error page.
[email protected]dd7daa82009-08-10 05:46:453209 frame->loadHTMLString(std::string(),
[email protected]15d79e12009-08-02 19:23:453210 GURL(kUnreachableWebDataURL),
3211 error.unreachableURL,
3212 replace);
3213
3214 // Now, create a fetcher for the error page and associate it with the data
3215 // source we just created via the LoadHTMLString call. That way if another
3216 // navigation occurs, the fetcher will get destroyed.
3217 NavigationState* navigation_state =
[email protected]dd7daa82009-08-10 05:46:453218 NavigationState::FromDataSource(frame->provisionalDataSource());
[email protected]15d79e12009-08-02 19:23:453219 navigation_state->set_alt_error_page_fetcher(
3220 new AltErrorPageResourceFetcher(
3221 error_page_url, frame, error,
3222 NewCallback(this, &RenderView::AltErrorPageFinished)));
3223 return true;
3224}
3225
initial.commit09911bf2008-07-26 23:55:293226std::string RenderView::GetAltHTMLForTemplate(
3227 const DictionaryValue& error_strings, int template_resource_id) const {
[email protected]8a16266e2009-09-10 21:08:393228 const base::StringPiece template_html(
initial.commit09911bf2008-07-26 23:55:293229 ResourceBundle::GetSharedInstance().GetRawDataResource(
3230 template_resource_id));
3231
3232 if (template_html.empty()) {
3233 NOTREACHED() << "unable to load template. ID: " << template_resource_id;
3234 return "";
3235 }
[email protected]7cd22a52009-07-14 00:40:253236
initial.commit09911bf2008-07-26 23:55:293237 // "t" is the id of the templates root node.
[email protected]7cd22a52009-07-14 00:40:253238 return jstemplate_builder::GetTemplatesHtml(
initial.commit09911bf2008-07-26 23:55:293239 template_html, &error_strings, "t");
3240}
[email protected]0e79b9e2009-02-13 04:20:483241
[email protected]15d79e12009-08-02 19:23:453242void RenderView::AltErrorPageFinished(WebFrame* frame,
3243 const WebURLError& original_error,
3244 const std::string& html) {
3245 // Here, we replace the blank page we loaded previously.
[email protected]7ccddb8c2009-08-04 17:36:553246
3247 // If we failed to download the alternate error page, fall back to the
3248 // original error page if present. Otherwise, LoadNavigationErrorPage
3249 // will simply display a default error page.
3250 const std::string* html_to_load = &html;
3251 if (html.empty()) {
3252 NavigationState* navigation_state =
[email protected]dd7daa82009-08-10 05:46:453253 NavigationState::FromDataSource(frame->dataSource());
[email protected]7ccddb8c2009-08-04 17:36:553254 html_to_load = &navigation_state->postponed_data();
3255 }
3256 LoadNavigationErrorPage(
3257 frame, WebURLRequest(), original_error, *html_to_load, true);
[email protected]15d79e12009-08-02 19:23:453258}
3259
[email protected]30f75e62009-02-25 22:01:003260void RenderView::OnMoveOrResizeStarted() {
3261 if (webview())
3262 webview()->HideAutofillPopup();
3263}
3264
[email protected]30f75e62009-02-25 22:01:003265void RenderView::OnResize(const gfx::Size& new_size,
3266 const gfx::Rect& resizer_rect) {
3267 if (webview())
3268 webview()->HideAutofillPopup();
3269 RenderWidget::OnResize(new_size, resizer_rect);
3270}
[email protected]0aa477bd2009-03-23 22:21:433271
[email protected]05d478752009-04-08 23:38:163272void RenderView::OnClearFocusedNode() {
3273 if (webview())
[email protected]26aa0482009-09-30 16:55:273274 webview()->clearFocusedNode();
[email protected]05d478752009-04-08 23:38:163275}
3276
[email protected]699ab0d2009-04-23 23:19:143277void RenderView::OnSetBackground(const SkBitmap& background) {
3278 if (webview())
[email protected]b4bb2502009-10-01 22:35:273279 webview()->setIsTransparent(!background.empty());
[email protected]699ab0d2009-04-23 23:19:143280
3281 SetBackground(background);
3282}
3283
[email protected]8c66c5a2009-07-22 17:26:343284void RenderView::OnSetActive(bool active) {
3285 if (webview())
[email protected]b4bb2502009-10-01 22:35:273286 webview()->setIsActive(active);
[email protected]8c66c5a2009-07-22 17:26:343287}
3288
[email protected]309d7a282009-03-24 09:18:273289void RenderView::SendExtensionRequest(const std::string& name,
3290 const std::string& args,
[email protected]c6619182009-05-12 14:59:323291 int request_id,
[email protected]2f25d7b92009-06-10 00:06:473292 bool has_callback) {
[email protected]c6619182009-05-12 14:59:323293 Send(new ViewHostMsg_ExtensionRequest(routing_id_, name, args, request_id,
[email protected]2f25d7b92009-06-10 00:06:473294 has_callback));
[email protected]309d7a282009-03-24 09:18:273295}
3296
[email protected]c6619182009-05-12 14:59:323297void RenderView::OnExtensionResponse(int request_id,
3298 bool success,
3299 const std::string& response,
3300 const std::string& error) {
[email protected]0f6053962009-07-09 19:26:353301 ExtensionProcessBindings::HandleResponse(
3302 request_id, success, response, error);
[email protected]309d7a282009-03-24 09:18:273303}
[email protected]c20210e62009-04-03 21:39:263304
[email protected]078b34612009-09-19 19:31:513305void RenderView::InjectToolstripCSS() {
3306 if (view_type_ != ViewType::EXTENSION_TOOLSTRIP)
3307 return;
3308
3309 static const base::StringPiece toolstrip_css(
3310 ResourceBundle::GetSharedInstance().GetRawDataResource(
3311 IDR_EXTENSION_TOOLSTRIP_CSS));
3312 std::string css = toolstrip_css.as_string();
3313 InsertCSS(L"", css, "ToolstripDefaultCSS");
3314}
3315
[email protected]7120f132009-07-20 21:05:373316void RenderView::OnExtensionMessageInvoke(const std::string& function_name,
3317 const ListValue& args) {
3318 RendererExtensionBindings::Invoke(function_name, args, this);
3319}
3320
[email protected]e7e4f3c2009-04-21 15:24:083321// Dump all load time histograms.
[email protected]c20210e62009-04-03 21:39:263322//
[email protected]7a9b51f2009-06-29 21:28:293323// There are 13 histograms measuring various times.
[email protected]c20210e62009-04-03 21:39:263324// The time points we keep are
3325// request: time document was requested by user
3326// start: time load of document started
[email protected]a2f6bc112009-06-27 16:27:253327// commit: time load of document started
[email protected]7a9b51f2009-06-29 21:28:293328// finish_document: main document loaded, before onload()
[email protected]c20210e62009-04-03 21:39:263329// finish: after onload() and all resources are loaded
[email protected]7a9b51f2009-06-29 21:28:293330// first_paint: first paint performed
3331// first_paint_after_load: first paint performed after load is finished
3332// begin: request if it was user requested, start otherwise
3333//
[email protected]c20210e62009-04-03 21:39:263334// The times that we histogram are
[email protected]a2f6bc112009-06-27 16:27:253335// request->start,
[email protected]7a9b51f2009-06-29 21:28:293336// start->commit,
3337// commit->finish_document,
3338// finish_document->finish,
3339// begin->commit,
3340// begin->finishDoc,
3341// begin->finish,
3342// begin->first_paint,
3343// begin->first_paint_after_load
3344// commit->finishDoc,
3345// commit->first_paint,
3346// commit->first_paint_after_load,
3347// finish->first_paint_after_load,
[email protected]c20210e62009-04-03 21:39:263348//
[email protected]e7e4f3c2009-04-21 15:24:083349// It's possible for the request time not to be set, if a client
3350// redirect had been done (the user never requested the page)
3351// Also, it's possible to load a page without ever laying it out
[email protected]7a9b51f2009-06-29 21:28:293352// so first_paint and first_paint_after_load can be 0.
[email protected]c20210e62009-04-03 21:39:263353void RenderView::DumpLoadHistograms() const {
[email protected]26aa0482009-09-30 16:55:273354 WebFrame* main_frame = webview()->mainFrame();
[email protected]ed3fb032009-06-16 19:50:563355 NavigationState* navigation_state =
[email protected]dd7daa82009-08-10 05:46:453356 NavigationState::FromDataSource(main_frame->dataSource());
[email protected]7a9b51f2009-06-29 21:28:293357 Time finish = navigation_state->finish_load_time();
[email protected]ed3fb032009-06-16 19:50:563358
[email protected]7a9b51f2009-06-29 21:28:293359 // If we've already dumped or we haven't finished loading, do nothing.
3360 if (navigation_state->load_histograms_recorded() || finish.is_null())
3361 return;
[email protected]ed3fb032009-06-16 19:50:563362
[email protected]7a9b51f2009-06-29 21:28:293363 Time request = navigation_state->request_time();
3364 Time start = navigation_state->start_load_time();
3365 Time commit = navigation_state->commit_load_time();
3366 Time finish_doc = navigation_state->finish_document_load_time();
3367 Time first_paint = navigation_state->first_paint_time();
3368 Time first_paint_after_load =
3369 navigation_state->first_paint_after_load_time();
[email protected]c20210e62009-04-03 21:39:263370
[email protected]7a9b51f2009-06-29 21:28:293371 Time begin;
3372 // Client side redirects will have no request time.
3373 if (request.is_null()) {
3374 begin = start;
3375 } else {
3376 begin = request;
3377 UMA_HISTOGRAM_MEDIUM_TIMES("Renderer4.RequestToStart", start - request);
[email protected]e7e4f3c2009-04-21 15:24:083378 }
[email protected]7a9b51f2009-06-29 21:28:293379 UMA_HISTOGRAM_MEDIUM_TIMES("Renderer4.StartToCommit", commit - start);
3380 UMA_HISTOGRAM_MEDIUM_TIMES(
3381 "Renderer4.CommitToFinishDoc", finish_doc - commit);
3382 UMA_HISTOGRAM_MEDIUM_TIMES(
3383 "Renderer4.FinishDocToFinish", finish - finish_doc);
3384
3385 UMA_HISTOGRAM_MEDIUM_TIMES("Renderer4.BeginToCommit", commit - begin);
3386 UMA_HISTOGRAM_MEDIUM_TIMES("Renderer4.BeginToFinishDoc", finish_doc - begin);
[email protected]e695fbd62009-06-30 16:31:543387
3388 static const TimeDelta kBeginToFinishMin(TimeDelta::FromMilliseconds(10));
3389 static const TimeDelta kBeginToFinishMax(TimeDelta::FromMinutes(10));
3390 static const size_t kBeginToFinishBucketCount(100);
3391
3392 UMA_HISTOGRAM_CUSTOM_TIMES("Renderer4.BeginToFinish",
3393 finish - begin, kBeginToFinishMin,
3394 kBeginToFinishMax, kBeginToFinishBucketCount);
[email protected]0a32257a2009-07-09 18:10:413395 UMA_HISTOGRAM_CUSTOM_TIMES("Renderer4.StartToFinish",
3396 finish - start, kBeginToFinishMin,
3397 kBeginToFinishMax, kBeginToFinishBucketCount);
3398 if (!request.is_null())
3399 UMA_HISTOGRAM_CUSTOM_TIMES("Renderer4.RequestToFinish",
3400 finish - request, kBeginToFinishMin,
3401 kBeginToFinishMax, kBeginToFinishBucketCount);
[email protected]e695fbd62009-06-30 16:31:543402
[email protected]36285b52009-06-30 19:10:003403 static bool use_dns_histogram(FieldTrialList::Find("DnsImpact") &&
3404 !FieldTrialList::Find("DnsImpact")->group_name().empty());
[email protected]0a32257a2009-07-09 18:10:413405 if (use_dns_histogram) {
[email protected]36285b52009-06-30 19:10:003406 UMA_HISTOGRAM_CUSTOM_TIMES(
3407 FieldTrial::MakeName("Renderer4.BeginToFinish", "DnsImpact").data(),
3408 finish - begin, kBeginToFinishMin,
3409 kBeginToFinishMax, kBeginToFinishBucketCount);
[email protected]0a32257a2009-07-09 18:10:413410 UMA_HISTOGRAM_CUSTOM_TIMES(
3411 FieldTrial::MakeName("Renderer4.StartToFinish", "DnsImpact").data(),
3412 finish - start, kBeginToFinishMin,
3413 kBeginToFinishMax, kBeginToFinishBucketCount);
3414 if (!request.is_null())
3415 UMA_HISTOGRAM_CUSTOM_TIMES(
3416 FieldTrial::MakeName("Renderer4.RequestToFinish", "DnsImpact").data(),
3417 finish - request, kBeginToFinishMin,
3418 kBeginToFinishMax, kBeginToFinishBucketCount);
3419 }
[email protected]e695fbd62009-06-30 16:31:543420
[email protected]36285b52009-06-30 19:10:003421 static bool use_sdch_histogram(FieldTrialList::Find("GlobalSdch") &&
3422 !FieldTrialList::Find("GlobalSdch")->group_name().empty());
[email protected]0a32257a2009-07-09 18:10:413423 if (use_sdch_histogram) {
[email protected]36285b52009-06-30 19:10:003424 UMA_HISTOGRAM_CUSTOM_TIMES(
3425 FieldTrial::MakeName("Renderer4.BeginToFinish", "GlobalSdch").data(),
3426 finish - begin, kBeginToFinishMin,
3427 kBeginToFinishMax, kBeginToFinishBucketCount);
[email protected]0a32257a2009-07-09 18:10:413428 UMA_HISTOGRAM_CUSTOM_TIMES(
3429 FieldTrial::MakeName("Renderer4.StartToFinish", "GlobalSdch").data(),
3430 finish - start, kBeginToFinishMin,
3431 kBeginToFinishMax, kBeginToFinishBucketCount);
3432 if (!request.is_null())
3433 UMA_HISTOGRAM_CUSTOM_TIMES(
3434 FieldTrial::MakeName("Renderer4.RequestToFinish",
3435 "GlobalSdch").data(),
3436 finish - request, kBeginToFinishMin,
3437 kBeginToFinishMax, kBeginToFinishBucketCount);
3438 }
[email protected]7a9b51f2009-06-29 21:28:293439
[email protected]5fff93f2009-08-02 04:27:343440 static bool use_socket_late_binding_histogram =
3441 FieldTrialList::Find("SocketLateBinding") &&
3442 !FieldTrialList::Find("SocketLateBinding")->group_name().empty();
3443 if (use_socket_late_binding_histogram) {
3444 UMA_HISTOGRAM_CUSTOM_TIMES(
3445 FieldTrial::MakeName("Renderer4.BeginToFinish",
3446 "SocketLateBinding").data(),
3447 finish - begin, kBeginToFinishMin,
3448 kBeginToFinishMax, kBeginToFinishBucketCount);
3449 UMA_HISTOGRAM_CUSTOM_TIMES(
3450 FieldTrial::MakeName("Renderer4.StartToFinish",
3451 "SocketLateBinding").data(),
3452 finish - start, kBeginToFinishMin,
3453 kBeginToFinishMax, kBeginToFinishBucketCount);
3454 if (!request.is_null())
3455 UMA_HISTOGRAM_CUSTOM_TIMES(
3456 FieldTrial::MakeName("Renderer4.RequestToFinish",
3457 "SocketLateBinding").data(),
3458 finish - request, kBeginToFinishMin,
3459 kBeginToFinishMax, kBeginToFinishBucketCount);
3460 }
3461
[email protected]7e05f6c42009-07-11 01:50:483462 static bool use_cache_histogram1(FieldTrialList::Find("CacheSize") &&
3463 !FieldTrialList::Find("CacheSize")->group_name().empty());
3464 if (use_cache_histogram1)
3465 UMA_HISTOGRAM_CUSTOM_TIMES(
3466 FieldTrial::MakeName("Renderer4.StartToFinish", "CacheSize").data(),
3467 finish - start, kBeginToFinishMin,
3468 kBeginToFinishMax, kBeginToFinishBucketCount);
3469
3470 static bool use_cache_histogram2(FieldTrialList::Find("NewEviction") &&
3471 !FieldTrialList::Find("NewEviction")->group_name().empty());
3472 if (use_cache_histogram2)
3473 UMA_HISTOGRAM_CUSTOM_TIMES(
3474 FieldTrial::MakeName("Renderer4.StartToFinish", "NewEviction").data(),
3475 finish - start, kBeginToFinishMin,
3476 kBeginToFinishMax, kBeginToFinishBucketCount);
3477
[email protected]ab0729e2009-09-30 04:42:463478 static bool use_async_tcp(FieldTrialList::Find("AsyncSlowStart") &&
3479 !FieldTrialList::Find("AsyncSlowStart")->group_name().empty());
3480 if (use_async_tcp) {
3481 UMA_HISTOGRAM_CUSTOM_TIMES(
3482 FieldTrial::MakeName("Renderer4.StartToFinish",
3483 "AsyncSlowStart").data(),
3484 finish - start, kBeginToFinishMin,
3485 kBeginToFinishMax, kBeginToFinishBucketCount);
3486 }
3487
[email protected]7a9b51f2009-06-29 21:28:293488 UMA_HISTOGRAM_MEDIUM_TIMES("Renderer4.CommitToFinish", finish - commit);
3489
3490 if (!first_paint.is_null()) {
3491 UMA_HISTOGRAM_MEDIUM_TIMES(
3492 "Renderer4.BeginToFirstPaint", first_paint - begin);
3493 UMA_HISTOGRAM_MEDIUM_TIMES(
3494 "Renderer4.CommitToFirstPaint", first_paint - commit);
[email protected]c20210e62009-04-03 21:39:263495 }
[email protected]7a9b51f2009-06-29 21:28:293496
3497 if (!first_paint_after_load.is_null()) {
3498 UMA_HISTOGRAM_MEDIUM_TIMES(
3499 "Renderer4.BeginToFirstPaintAfterLoad", first_paint_after_load - begin);
3500 UMA_HISTOGRAM_MEDIUM_TIMES(
3501 "Renderer4.CommitToFirstPaintAfterLoad",
3502 first_paint_after_load - commit);
3503 UMA_HISTOGRAM_MEDIUM_TIMES(
3504 "Renderer4.FinishToFirstPaintAfterLoad",
3505 first_paint_after_load - finish);
3506 }
3507
3508 navigation_state->set_load_histograms_recorded(true);
[email protected]c20210e62009-04-03 21:39:263509}
[email protected]e846d0d2009-05-20 00:53:063510
3511void RenderView::FocusAccessibilityObject(
3512 WebCore::AccessibilityObject* acc_obj) {
3513#if defined(OS_WIN)
3514 if (!web_accessibility_manager_.get()) {
3515 web_accessibility_manager_.reset(
3516 webkit_glue::WebAccessibilityManager::Create());
3517 }
3518
3519 // Retrieve the accessibility object id of the AccessibilityObject.
3520 int acc_obj_id = web_accessibility_manager_->FocusAccObj(acc_obj);
3521
3522 // If id is valid, alert the browser side that an accessibility focus change
3523 // occurred.
3524 if (acc_obj_id >= 0)
3525 Send(new ViewHostMsg_AccessibilityFocusChange(routing_id_, acc_obj_id));
3526
3527#else // defined(OS_WIN)
3528 // TODO(port): accessibility not yet implemented
3529 NOTIMPLEMENTED();
3530#endif
3531}
[email protected]daa8c58e2009-06-15 17:21:103532
3533void RenderView::SendPasswordForms(WebFrame* frame) {
[email protected]dd7daa82009-08-10 05:46:453534 WebVector<WebForm> forms;
3535 frame->forms(forms);
[email protected]daa8c58e2009-06-15 17:21:103536
3537 std::vector<PasswordForm> password_forms;
3538 for (size_t i = 0; i < forms.size(); ++i) {
3539 const WebForm& form = forms[i];
3540
3541 // Respect autocomplete=off.
3542 if (form.isAutoCompleteEnabled()) {
3543 scoped_ptr<PasswordForm> password_form(
3544 PasswordFormDomManager::CreatePasswordForm(form));
3545 if (password_form.get())
3546 password_forms.push_back(*password_form);
3547 }
3548 }
3549
3550 if (!password_forms.empty())
3551 Send(new ViewHostMsg_PasswordFormsSeen(routing_id_, password_forms));
3552}
[email protected]0fda7272009-06-26 15:49:333553
3554void RenderView::Print(WebFrame* frame, bool script_initiated) {
3555 DCHECK(frame);
3556 if (print_helper_.get() == NULL) {
3557 print_helper_.reset(new PrintWebViewHelper(this));
3558 }
3559 print_helper_->Print(frame, script_initiated);
3560}
[email protected]446705872009-09-10 07:22:483561
3562void RenderView::OnSetEditCommandsForNextKeyEvent(
3563 const EditCommands& edit_commands) {
3564 edit_commands_ = edit_commands;
3565}
3566
[email protected]912256b32009-09-18 09:47:353567void RenderView::OnExecuteCode(int request_id, const std::string& extension_id,
3568 bool is_js_code,
3569 const std::string& code_string) {
3570 if (is_loading_) {
3571 scoped_refptr<CodeExecutionInfo> info = new CodeExecutionInfo(
3572 request_id, extension_id, is_js_code, code_string);
3573 pending_code_execution_queue_.push(info);
3574 return;
3575 }
[email protected]26aa0482009-09-30 16:55:273576 WebFrame* main_frame = webview() ? webview()->mainFrame() : NULL;
[email protected]912256b32009-09-18 09:47:353577 if (!main_frame) {
3578 Send(new ViewMsg_ExecuteCodeFinished(routing_id_, request_id, false));
3579 return;
3580 }
3581
3582 if (is_js_code) {
3583 std::vector<WebScriptSource> sources;
3584 sources.push_back(
3585 WebScriptSource(WebString::fromUTF8(code_string)));
3586 UserScriptSlave::InsertInitExtensionCode(&sources, extension_id);
3587 main_frame->executeScriptInNewWorld(&sources.front(), sources.size(),
3588 EXTENSION_GROUP_CONTENT_SCRIPTS);
3589 } else {
3590 main_frame->insertStyleText(WebString::fromUTF8(code_string), WebString());
3591 }
3592
3593 Send(new ViewMsg_ExecuteCodeFinished(routing_id_, request_id, true));
3594}
3595
[email protected]446705872009-09-10 07:22:483596void RenderView::DidHandleKeyEvent() {
3597 edit_commands_.clear();
3598}
3599
[email protected]83dde542009-09-11 20:59:553600void RenderView::EnsureDocumentTag() {
3601 // TODO(darin): There's actually no reason for this to be here. We should
3602 // have the browser side manage the document tag.
3603#if defined(OS_MACOSX)
3604 if (!has_document_tag_) {
3605 // Make the call to get the tag.
3606 Send(new ViewHostMsg_GetDocumentTag(routing_id_, &document_tag_));
3607 has_document_tag_ = true;
3608 }
3609#endif
3610}
[email protected]12636df2009-09-28 22:32:213611
3612bool RenderView::SendAndRunNestedMessageLoop(IPC::SyncMessage* message) {
[email protected]8beff0762009-09-29 02:18:303613 PluginChannelHost::Broadcast(
3614 new PluginMsg_SignalModalDialogEvent(host_window_));
[email protected]12636df2009-09-28 22:32:213615
3616 message->EnableMessagePumping(); // Runs a nested message loop.
3617 bool rv = Send(message);
3618
[email protected]8beff0762009-09-29 02:18:303619 PluginChannelHost::Broadcast(
3620 new PluginMsg_ResetModalDialogEvent(host_window_));
[email protected]12636df2009-09-28 22:32:213621
3622 return rv;
3623}