blob: b0cb9dc73d7e56ef0ac8eabf772c82d58913b189 [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]3d9689372009-09-10 04:29:17317 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 // Don't let WebCore keep a B/F list - we have our own.
322 // We let it keep 1 entry because FrameLoader::goToItem expects an item in the
323 // backForwardList, which is used only in ASSERTs.
324 webview()->SetBackForwardListSize(1);
325
326 routing_id_ = routing_id;
[email protected]81a34412009-01-05 19:17:24327 render_thread_->AddRoute(routing_id_, this);
initial.commit09911bf2008-07-26 23:55:29328 // Take a reference on behalf of the RenderThread. This will be balanced
329 // when we receive ViewMsg_Close.
330 AddRef();
331
332 // If this is a popup, we must wait for the CreatingNew_ACK message before
333 // completing initialization. Otherwise, we can finish it now.
334 if (opener_id == MSG_ROUTING_NONE) {
335 did_show_ = true;
336 CompleteInit(parent_hwnd);
337 }
338
339 host_window_ = parent_hwnd;
initial.commit09911bf2008-07-26 23:55:29340
[email protected]58bfc6b2009-06-24 09:45:02341 const CommandLine& command_line = *CommandLine::ForCurrentProcess();
[email protected]81e63782009-02-27 19:35:09342 if (command_line.HasSwitch(switches::kDomAutomationController))
343 enabled_bindings_ |= BindingsPolicy::DOM_AUTOMATION;
initial.commit09911bf2008-07-26 23:55:29344
[email protected]5fb88962009-04-16 19:03:25345 audio_message_filter_ = new AudioMessageFilter(routing_id_);
346 render_thread_->AddFilter(audio_message_filter_);
initial.commit09911bf2008-07-26 23:55:29347}
348
349void RenderView::OnMessageReceived(const IPC::Message& message) {
[email protected]f8b6b6f2009-03-10 16:48:26350 WebFrame* main_frame = webview() ? webview()->GetMainFrame() : NULL;
[email protected]ef916272009-07-08 21:40:55351 child_process_logging::ScopedActiveURLSetter url_setter(
[email protected]dd7daa82009-08-10 05:46:45352 main_frame ? main_frame->url() : WebURL());
[email protected]f8b6b6f2009-03-10 16:48:26353
[email protected]b2abac72009-02-26 12:39:28354 // If this is developer tools renderer intercept tools messages first.
[email protected]e4ac5df2009-03-17 15:33:11355 if (devtools_client_.get() && devtools_client_->OnMessageReceived(message))
[email protected]b2abac72009-02-26 12:39:28356 return;
[email protected]b4b967e2009-04-22 11:33:05357 if (devtools_agent_.get() && devtools_agent_->OnMessageReceived(message))
358 return;
[email protected]b2abac72009-02-26 12:39:28359
initial.commit09911bf2008-07-26 23:55:29360 IPC_BEGIN_MESSAGE_MAP(RenderView, message)
initial.commit09911bf2008-07-26 23:55:29361 IPC_MESSAGE_HANDLER(ViewMsg_CaptureThumbnail, SendThumbnail)
initial.commit09911bf2008-07-26 23:55:29362 IPC_MESSAGE_HANDLER(ViewMsg_PrintPages, OnPrintPages)
[email protected]82270452009-06-19 15:58:01363 IPC_MESSAGE_HANDLER(ViewMsg_PrintingDone, OnPrintingDone)
initial.commit09911bf2008-07-26 23:55:29364 IPC_MESSAGE_HANDLER(ViewMsg_Navigate, OnNavigate)
365 IPC_MESSAGE_HANDLER(ViewMsg_Stop, OnStop)
366 IPC_MESSAGE_HANDLER(ViewMsg_LoadAlternateHTMLText, OnLoadAlternateHTMLText)
367 IPC_MESSAGE_HANDLER(ViewMsg_StopFinding, OnStopFinding)
368 IPC_MESSAGE_HANDLER(ViewMsg_Undo, OnUndo)
369 IPC_MESSAGE_HANDLER(ViewMsg_Redo, OnRedo)
370 IPC_MESSAGE_HANDLER(ViewMsg_Cut, OnCut)
371 IPC_MESSAGE_HANDLER(ViewMsg_Copy, OnCopy)
[email protected]c0cc3092009-09-12 08:27:27372#if defined(OS_MACOSX)
[email protected]a954bf72009-09-12 07:30:35373 IPC_MESSAGE_HANDLER(ViewMsg_CopyToFindPboard, OnCopyToFindPboard)
[email protected]c0cc3092009-09-12 08:27:27374#endif
initial.commit09911bf2008-07-26 23:55:29375 IPC_MESSAGE_HANDLER(ViewMsg_Paste, OnPaste)
376 IPC_MESSAGE_HANDLER(ViewMsg_Replace, OnReplace)
[email protected]98324892009-09-09 21:16:05377 IPC_MESSAGE_HANDLER(ViewMsg_ToggleSpellPanel, OnToggleSpellPanel)
378 IPC_MESSAGE_HANDLER(ViewMsg_AdvanceToNextMisspelling,
379 OnAdvanceToNextMisspelling)
[email protected]bbbd545c2008-12-15 20:18:04380 IPC_MESSAGE_HANDLER(ViewMsg_ToggleSpellCheck, OnToggleSpellCheck)
initial.commit09911bf2008-07-26 23:55:29381 IPC_MESSAGE_HANDLER(ViewMsg_Delete, OnDelete)
382 IPC_MESSAGE_HANDLER(ViewMsg_SelectAll, OnSelectAll)
383 IPC_MESSAGE_HANDLER(ViewMsg_CopyImageAt, OnCopyImageAt)
[email protected]4b59ae602009-06-23 20:58:15384 IPC_MESSAGE_HANDLER(ViewMsg_ExecuteEditCommand, OnExecuteEditCommand)
initial.commit09911bf2008-07-26 23:55:29385 IPC_MESSAGE_HANDLER(ViewMsg_Find, OnFind)
[email protected]5c4266922009-07-10 16:41:27386 IPC_MESSAGE_HANDLER(ViewMsg_DeterminePageText, OnDeterminePageText)
[email protected]630e26b2008-10-14 22:55:17387 IPC_MESSAGE_HANDLER(ViewMsg_Zoom, OnZoom)
initial.commit09911bf2008-07-26 23:55:29388 IPC_MESSAGE_HANDLER(ViewMsg_SetPageEncoding, OnSetPageEncoding)
[email protected]a697f4c2009-09-14 22:30:18389 IPC_MESSAGE_HANDLER(ViewMsg_ResetPageEncodingToDefault,
390 OnResetPageEncodingToDefault)
[email protected]b2abac72009-02-26 12:39:28391 IPC_MESSAGE_HANDLER(ViewMsg_SetupDevToolsClient, OnSetupDevToolsClient)
[email protected]bf5c2ff392009-07-08 16:24:33392 IPC_MESSAGE_HANDLER(ViewMsg_DownloadFavIcon, OnDownloadFavIcon)
initial.commit09911bf2008-07-26 23:55:29393 IPC_MESSAGE_HANDLER(ViewMsg_ScriptEvalRequest, OnScriptEvalRequest)
[email protected]1810e132009-03-24 23:35:48394 IPC_MESSAGE_HANDLER(ViewMsg_CSSInsertRequest, OnCSSInsertRequest)
initial.commit09911bf2008-07-26 23:55:29395 IPC_MESSAGE_HANDLER(ViewMsg_AddMessageToConsole, OnAddMessageToConsole)
initial.commit09911bf2008-07-26 23:55:29396 IPC_MESSAGE_HANDLER(ViewMsg_ReservePageIDRange, OnReservePageIDRange)
397 IPC_MESSAGE_HANDLER(ViewMsg_UploadFile, OnUploadFileRequest)
398 IPC_MESSAGE_HANDLER(ViewMsg_FormFill, OnFormFill)
399 IPC_MESSAGE_HANDLER(ViewMsg_FillPasswordForm, OnFillPasswordForm)
400 IPC_MESSAGE_HANDLER(ViewMsg_DragTargetDragEnter, OnDragTargetDragEnter)
401 IPC_MESSAGE_HANDLER(ViewMsg_DragTargetDragOver, OnDragTargetDragOver)
402 IPC_MESSAGE_HANDLER(ViewMsg_DragTargetDragLeave, OnDragTargetDragLeave)
403 IPC_MESSAGE_HANDLER(ViewMsg_DragTargetDrop, OnDragTargetDrop)
[email protected]18cb2572008-08-21 20:34:45404 IPC_MESSAGE_HANDLER(ViewMsg_AllowBindings, OnAllowBindings)
initial.commit09911bf2008-07-26 23:55:29405 IPC_MESSAGE_HANDLER(ViewMsg_SetDOMUIProperty, OnSetDOMUIProperty)
[email protected]266eb6f2008-09-30 23:56:50406 IPC_MESSAGE_HANDLER(ViewMsg_DragSourceEndedOrMoved,
407 OnDragSourceEndedOrMoved)
initial.commit09911bf2008-07-26 23:55:29408 IPC_MESSAGE_HANDLER(ViewMsg_DragSourceSystemDragEnded,
409 OnDragSourceSystemDragEnded)
410 IPC_MESSAGE_HANDLER(ViewMsg_SetInitialFocus, OnSetInitialFocus)
411 IPC_MESSAGE_HANDLER(ViewMsg_FindReplyACK, OnFindReplyAck)
412 IPC_MESSAGE_HANDLER(ViewMsg_UpdateTargetURL_ACK, OnUpdateTargetURLAck)
413 IPC_MESSAGE_HANDLER(ViewMsg_UpdateWebPreferences, OnUpdateWebPreferences)
414 IPC_MESSAGE_HANDLER(ViewMsg_SetAltErrorPageURL, OnSetAltErrorPageURL)
415 IPC_MESSAGE_HANDLER(ViewMsg_InstallMissingPlugin, OnInstallMissingPlugin)
416 IPC_MESSAGE_HANDLER(ViewMsg_RunFileChooserResponse, OnFileChooserResponse)
417 IPC_MESSAGE_HANDLER(ViewMsg_EnableViewSourceMode, OnEnableViewSourceMode)
418 IPC_MESSAGE_HANDLER(ViewMsg_UpdateBackForwardListCount,
419 OnUpdateBackForwardListCount)
420 IPC_MESSAGE_HANDLER(ViewMsg_GetAllSavableResourceLinksForCurrentPage,
421 OnGetAllSavableResourceLinksForCurrentPage)
[email protected]f09c7182009-03-10 12:54:04422 IPC_MESSAGE_HANDLER(
423 ViewMsg_GetSerializedHtmlDataForCurrentPageWithLocalLinks,
424 OnGetSerializedHtmlDataForCurrentPageWithLocalLinks)
initial.commit09911bf2008-07-26 23:55:29425 IPC_MESSAGE_HANDLER(ViewMsg_GetApplicationInfo, OnGetApplicationInfo)
[email protected]266eb6f2008-09-30 23:56:50426 IPC_MESSAGE_HANDLER(ViewMsg_GetAccessibilityInfo, OnGetAccessibilityInfo)
427 IPC_MESSAGE_HANDLER(ViewMsg_ClearAccessibilityInfo,
428 OnClearAccessibilityInfo)
initial.commit09911bf2008-07-26 23:55:29429 IPC_MESSAGE_HANDLER(ViewMsg_ShouldClose, OnMsgShouldClose)
430 IPC_MESSAGE_HANDLER(ViewMsg_ClosePage, OnClosePage)
431 IPC_MESSAGE_HANDLER(ViewMsg_ThemeChanged, OnThemeChanged)
[email protected]18cb2572008-08-21 20:34:45432 IPC_MESSAGE_HANDLER(ViewMsg_HandleMessageFromExternalHost,
433 OnMessageFromExternalHost)
[email protected]0aa55312008-10-17 21:53:08434 IPC_MESSAGE_HANDLER(ViewMsg_DisassociateFromPopupCount,
435 OnDisassociateFromPopupCount)
[email protected]0ebf3872008-11-07 21:35:03436 IPC_MESSAGE_HANDLER(ViewMsg_AutofillSuggestions,
437 OnReceivedAutofillSuggestions)
[email protected]2c4410d2009-05-06 23:46:22438 IPC_MESSAGE_HANDLER(ViewMsg_PopupNotificationVisibilityChanged,
439 OnPopupNotificationVisibilityChanged)
[email protected]30f75e62009-02-25 22:01:00440 IPC_MESSAGE_HANDLER(ViewMsg_MoveOrResizeStarted, OnMoveOrResizeStarted)
[email protected]309d7a282009-03-24 09:18:27441 IPC_MESSAGE_HANDLER(ViewMsg_ExtensionResponse, OnExtensionResponse)
[email protected]7120f132009-07-20 21:05:37442 IPC_MESSAGE_HANDLER(ViewMsg_ExtensionMessageInvoke,
443 OnExtensionMessageInvoke)
[email protected]05d478752009-04-08 23:38:16444 IPC_MESSAGE_HANDLER(ViewMsg_ClearFocusedNode, OnClearFocusedNode)
[email protected]699ab0d2009-04-23 23:19:14445 IPC_MESSAGE_HANDLER(ViewMsg_SetBackground, OnSetBackground)
[email protected]0666aef2009-05-13 19:48:08446 IPC_MESSAGE_HANDLER(ViewMsg_EnableIntrinsicWidthChangedMode,
447 OnEnableIntrinsicWidthChangedMode)
[email protected]80d96fa2009-06-10 22:34:51448 IPC_MESSAGE_HANDLER(ViewMsg_SetRendererPrefs, OnSetRendererPrefs)
[email protected]7b291f92009-08-14 05:43:53449 IPC_MESSAGE_HANDLER(ViewMsg_UpdateBrowserWindowId,
450 OnUpdateBrowserWindowId)
451 IPC_MESSAGE_HANDLER(ViewMsg_NotifyRenderViewType,
452 OnNotifyRendererViewType)
[email protected]581b87eb2009-07-23 23:06:56453 IPC_MESSAGE_HANDLER(ViewMsg_MediaPlayerActionAt, OnMediaPlayerActionAt)
[email protected]8c66c5a2009-07-22 17:26:34454 IPC_MESSAGE_HANDLER(ViewMsg_SetActive, OnSetActive)
[email protected]446705872009-09-10 07:22:48455 IPC_MESSAGE_HANDLER(ViewMsg_SetEditCommandsForNextKeyEvent,
456 OnSetEditCommandsForNextKeyEvent);
[email protected]912256b32009-09-18 09:47:35457 IPC_MESSAGE_HANDLER(ViewMsg_ExecuteCode,
458 OnExecuteCode)
[email protected]634a6f92008-12-01 21:39:31459
initial.commit09911bf2008-07-26 23:55:29460 // Have the super handle all other messages.
461 IPC_MESSAGE_UNHANDLED(RenderWidget::OnMessageReceived(message))
462 IPC_END_MESSAGE_MAP()
463}
464
initial.commit09911bf2008-07-26 23:55:29465void RenderView::SendThumbnail() {
466 WebFrame* main_frame = webview()->GetMainFrame();
467 if (!main_frame)
468 return;
469
470 // get the URL for this page
[email protected]dd7daa82009-08-10 05:46:45471 GURL url(main_frame->url());
initial.commit09911bf2008-07-26 23:55:29472 if (url.is_empty())
473 return;
474
475 if (size_.IsEmpty())
476 return; // Don't create an empty thumbnail!
477
478 ThumbnailScore score;
479 SkBitmap thumbnail;
[email protected]8649fb32009-06-26 17:51:02480 if (!CaptureThumbnail(webview(), kThumbnailWidth, kThumbnailHeight,
[email protected]b6e4bec2008-11-12 01:17:15481 &thumbnail, &score))
482 return;
483
initial.commit09911bf2008-07-26 23:55:29484 // send the thumbnail message to the browser process
[email protected]674741932009-02-04 23:44:46485 Send(new ViewHostMsg_Thumbnail(routing_id_, url, score, thumbnail));
initial.commit09911bf2008-07-26 23:55:29486}
487
[email protected]068637222009-01-29 16:58:07488void RenderView::OnPrintPages() {
initial.commit09911bf2008-07-26 23:55:29489 DCHECK(webview());
[email protected]aa82249f2009-07-16 17:23:58490 if (webview()) {
491 // If the user has selected text in the currently focused frame we print
492 // only that frame (this makes print selection work for multiple frames).
[email protected]dd7daa82009-08-10 05:46:45493 if (webview()->GetFocusedFrame()->hasSelection())
[email protected]aa82249f2009-07-16 17:23:58494 Print(webview()->GetFocusedFrame(), false);
495 else
496 Print(webview()->GetMainFrame(), false);
497 }
initial.commit09911bf2008-07-26 23:55:29498}
499
[email protected]82270452009-06-19 15:58:01500void RenderView::OnPrintingDone(int document_cookie, bool success) {
501 // Ignoring document cookie here since only one print job can be outstanding
502 // per renderer and document_cookie is 0 when printing is successful.
503 DCHECK(print_helper_.get());
504 if (print_helper_.get() != NULL) {
505 print_helper_->DidFinishPrinting(success);
506 }
507}
508
initial.commit09911bf2008-07-26 23:55:29509void RenderView::CapturePageInfo(int load_id, bool preliminary_capture) {
510 if (load_id != page_id_)
511 return; // this capture call is no longer relevant due to navigation
512 if (load_id == last_indexed_page_id_)
513 return; // we already indexed this page
514
515 if (!webview())
516 return;
517
518 WebFrame* main_frame = webview()->GetMainFrame();
519 if (!main_frame)
520 return;
521
522 // Don't index/capture pages that are in view source mode.
[email protected]dd7daa82009-08-10 05:46:45523 if (main_frame->isViewSourceModeEnabled())
initial.commit09911bf2008-07-26 23:55:29524 return;
525
526 // Don't index/capture pages that failed to load. This only checks the top
527 // level frame so the thumbnail may contain a frame that failed to load.
[email protected]dd7daa82009-08-10 05:46:45528 WebDataSource* ds = main_frame->dataSource();
[email protected]726985e22009-06-18 21:09:28529 if (ds && ds->hasUnreachableURL())
initial.commit09911bf2008-07-26 23:55:29530 return;
531
532 if (!preliminary_capture)
533 last_indexed_page_id_ = load_id;
534
535 // get the URL for this page
[email protected]dd7daa82009-08-10 05:46:45536 GURL url(main_frame->url());
initial.commit09911bf2008-07-26 23:55:29537 if (url.is_empty())
538 return;
539
540 // full text
541 std::wstring contents;
542 CaptureText(main_frame, &contents);
543 if (contents.size()) {
544 // Send the text to the browser for indexing.
545 Send(new ViewHostMsg_PageContents(url, load_id, contents));
546 }
547
[email protected]5c4266922009-07-10 16:41:27548 // Send over text content of this page to the browser.
549 if (determine_page_text_after_loading_stops_) {
550 determine_page_text_after_loading_stops_ = false;
551 Send(new ViewMsg_DeterminePageText_Reply(routing_id_, contents));
552 }
553
initial.commit09911bf2008-07-26 23:55:29554 // thumbnail
555 SendThumbnail();
556}
557
558void RenderView::CaptureText(WebFrame* frame, std::wstring* contents) {
559 contents->clear();
560 if (!frame)
561 return;
562
[email protected]0faf0bd92008-09-09 20:53:27563 // Don't index any https pages. People generally don't want their bank
564 // accounts, etc. indexed on their computer, especially since some of these
565 // things are not marked cachable.
566 // TODO(brettw) we may want to consider more elaborate heuristics such as
567 // the cachability of the page. We may also want to consider subframes (this
568 // test will still index subframes if the subframe is SSL).
[email protected]dd7daa82009-08-10 05:46:45569 if (GURL(frame->url()).SchemeIsSecure())
[email protected]0faf0bd92008-09-09 20:53:27570 return;
571
initial.commit09911bf2008-07-26 23:55:29572#ifdef TIME_TEXT_RETRIEVAL
573 double begin = time_util::GetHighResolutionTimeNow();
574#endif
575
576 // get the contents of the frame
[email protected]dd7daa82009-08-10 05:46:45577 *contents = UTF16ToWideHack(frame->contentAsText(kMaxIndexChars));
initial.commit09911bf2008-07-26 23:55:29578
579#ifdef TIME_TEXT_RETRIEVAL
580 double end = time_util::GetHighResolutionTimeNow();
581 char buf[128];
582 sprintf_s(buf, "%d chars retrieved for indexing in %gms\n",
583 contents.size(), (end - begin)*1000);
584 OutputDebugStringA(buf);
585#endif
586
587 // When the contents are clipped to the maximum, we don't want to have a
588 // partial word indexed at the end that might have been clipped. Therefore,
589 // terminate the string at the last space to ensure no words are clipped.
590 if (contents->size() == kMaxIndexChars) {
591 size_t last_space_index = contents->find_last_of(kWhitespaceWide);
592 if (last_space_index == std::wstring::npos)
593 return; // don't index if we got a huge block of text with no spaces
594 contents->resize(last_space_index);
595 }
596}
597
[email protected]8649fb32009-06-26 17:51:02598bool RenderView::CaptureThumbnail(WebView* view,
initial.commit09911bf2008-07-26 23:55:29599 int w,
600 int h,
601 SkBitmap* thumbnail,
602 ThumbnailScore* score) {
603#ifdef TIME_BITMAP_RETRIEVAL
604 double begin = time_util::GetHighResolutionTimeNow();
605#endif
606
[email protected]4873c7d2009-07-16 06:36:28607 view->layout();
608 const WebSize& size = view->size();
[email protected]b6e4bec2008-11-12 01:17:15609
[email protected]8649fb32009-06-26 17:51:02610 skia::PlatformCanvas canvas;
611 if (!canvas.initialize(size.width, size.height, true))
612 return false;
[email protected]8c89e7792009-08-19 21:18:34613 view->paint(webkit_glue::ToWebCanvas(&canvas),
614 WebRect(0, 0, size.width, size.height));
[email protected]8649fb32009-06-26 17:51:02615
616 skia::BitmapPlatformDevice& device =
617 static_cast<skia::BitmapPlatformDevice&>(canvas.getTopPlatformDevice());
618
619 const SkBitmap& src_bmp = device.accessBitmap(false);
initial.commit09911bf2008-07-26 23:55:29620
[email protected]cab34d6a2009-09-24 01:14:52621 SkRect dest_rect = { 0, 0, SkIntToScalar(w), SkIntToScalar(h) };
initial.commit09911bf2008-07-26 23:55:29622 float dest_aspect = dest_rect.width() / dest_rect.height();
623
624 // Get the src rect so that we can preserve the aspect ratio while filling
625 // the destination.
626 SkIRect src_rect;
627 if (src_bmp.width() < dest_rect.width() ||
628 src_bmp.height() < dest_rect.height()) {
629 // Source image is smaller: we clip the part of source image within the
630 // dest rect, and then stretch it to fill the dest rect. We don't respect
631 // the aspect ratio in this case.
632 src_rect.set(0, 0, static_cast<S16CPU>(dest_rect.width()),
633 static_cast<S16CPU>(dest_rect.height()));
634 score->good_clipping = false;
635 } else {
636 float src_aspect = static_cast<float>(src_bmp.width()) / src_bmp.height();
637 if (src_aspect > dest_aspect) {
638 // Wider than tall, clip horizontally: we center the smaller thumbnail in
639 // the wider screen.
640 S16CPU new_width = static_cast<S16CPU>(src_bmp.height() * dest_aspect);
641 S16CPU x_offset = (src_bmp.width() - new_width) / 2;
642 src_rect.set(x_offset, 0, new_width + x_offset, src_bmp.height());
643 score->good_clipping = false;
644 } else {
645 src_rect.set(0, 0, src_bmp.width(),
646 static_cast<S16CPU>(src_bmp.width() / dest_aspect));
647 score->good_clipping = true;
648 }
649 }
650
[email protected]dd7daa82009-08-10 05:46:45651 score->at_top = (view->GetMainFrame()->scrollOffset().height == 0);
initial.commit09911bf2008-07-26 23:55:29652
653 SkBitmap subset;
[email protected]8649fb32009-06-26 17:51:02654 device.accessBitmap(false).extractSubset(&subset, src_rect);
initial.commit09911bf2008-07-26 23:55:29655
656 // Resample the subset that we want to get it the right size.
[email protected]465b34b72008-12-12 20:19:14657 *thumbnail = skia::ImageOperations::Resize(
658 subset, skia::ImageOperations::RESIZE_LANCZOS3, w, h);
initial.commit09911bf2008-07-26 23:55:29659
660 score->boring_score = CalculateBoringScore(thumbnail);
661
662#ifdef TIME_BITMAP_RETRIEVAL
663 double end = time_util::GetHighResolutionTimeNow();
664 char buf[128];
665 sprintf_s(buf, "thumbnail in %gms\n", (end - begin) * 1000);
666 OutputDebugStringA(buf);
667#endif
[email protected]b6e4bec2008-11-12 01:17:15668 return true;
initial.commit09911bf2008-07-26 23:55:29669}
670
671double RenderView::CalculateBoringScore(SkBitmap* bitmap) {
672 int histogram[256] = {0};
673 color_utils::BuildLumaHistogram(bitmap, histogram);
674
675 int color_count = *std::max_element(histogram, histogram + 256);
676 int pixel_count = bitmap->width() * bitmap->height();
677 return static_cast<double>(color_count) / pixel_count;
678}
679
680void RenderView::OnNavigate(const ViewMsg_Navigate_Params& params) {
681 if (!webview())
682 return;
683
[email protected]8c785c62009-07-13 14:20:15684 if (devtools_agent_.get())
685 devtools_agent_->OnNavigate();
686
[email protected]ef916272009-07-08 21:40:55687 child_process_logging::ScopedActiveURLSetter url_setter(params.url);
[email protected]f8b6b6f2009-03-10 16:48:26688
initial.commit09911bf2008-07-26 23:55:29689 AboutHandler::MaybeHandle(params.url);
690
691 bool is_reload = params.reload;
692
693 WebFrame* main_frame = webview()->GetMainFrame();
[email protected]dd7daa82009-08-10 05:46:45694 if (is_reload && main_frame->currentHistoryItem().isNull()) {
initial.commit09911bf2008-07-26 23:55:29695 // We cannot reload if we do not have any history state. This happens, for
696 // example, when recovering from a crash. Our workaround here is a bit of
697 // a hack since it means that reload after a crashed tab does not cause an
698 // end-to-end cache validation.
699 is_reload = false;
700 }
701
[email protected]77f17a82009-05-21 04:42:54702 // A navigation resulting from loading a javascript URL should not be treated
703 // as a browser initiated event. Instead, we want it to look as if the page
704 // initiated any load resulting from JS execution.
705 if (!params.url.SchemeIs(chrome::kJavaScriptScheme)) {
[email protected]daa8c58e2009-06-15 17:21:10706 pending_navigation_state_.reset(NavigationState::CreateBrowserInitiated(
[email protected]77f17a82009-05-21 04:42:54707 params.page_id, params.transition, params.request_time));
708 }
initial.commit09911bf2008-07-26 23:55:29709
[email protected]04d3c6e2009-05-22 17:00:13710 // If we are reloading, then WebKit will use the history state of the current
711 // page, so we should just ignore any given history state. Otherwise, if we
712 // have history state, then we need to navigate to it, which corresponds to a
713 // back/forward navigation event.
[email protected]e6f546c32009-07-01 17:12:55714 if (is_reload) {
[email protected]dd7daa82009-08-10 05:46:45715 main_frame->reload();
[email protected]e6f546c32009-07-01 17:12:55716 } else if (!params.state.empty()) {
[email protected]04d3c6e2009-05-22 17:00:13717 // We must know the page ID of the page we are navigating back to.
[email protected]f929f2f22009-06-12 16:56:58718 DCHECK_NE(params.page_id, -1);
[email protected]dd7daa82009-08-10 05:46:45719 main_frame->loadHistoryItem(
[email protected]ca948a22009-06-25 19:36:17720 webkit_glue::HistoryItemFromString(params.state));
[email protected]04d3c6e2009-05-22 17:00:13721 } else {
722 // Navigate to the given URL.
[email protected]726985e22009-06-18 21:09:28723 WebURLRequest request(params.url);
initial.commit09911bf2008-07-26 23:55:29724
[email protected]e6f546c32009-07-01 17:12:55725 // A session history navigation should have been accompanied by state.
726 DCHECK_EQ(params.page_id, -1);
[email protected]04d3c6e2009-05-22 17:00:13727
[email protected]dd7daa82009-08-10 05:46:45728 if (main_frame->isViewSourceModeEnabled())
[email protected]e6f546c32009-07-01 17:12:55729 request.setCachePolicy(WebURLRequest::ReturnCacheDataElseLoad);
[email protected]04d3c6e2009-05-22 17:00:13730
[email protected]726985e22009-06-18 21:09:28731 if (params.referrer.is_valid()) {
732 request.setHTTPHeaderField(WebString::fromUTF8("Referer"),
733 WebString::fromUTF8(params.referrer.spec()));
734 }
[email protected]04d3c6e2009-05-22 17:00:13735
[email protected]dd7daa82009-08-10 05:46:45736 main_frame->loadRequest(request);
[email protected]c0588052008-10-27 23:01:50737 }
738
[email protected]77f17a82009-05-21 04:42:54739 // In case LoadRequest failed before DidCreateDataSource was called.
740 pending_navigation_state_.reset();
initial.commit09911bf2008-07-26 23:55:29741}
742
743// Stop loading the current page
744void RenderView::OnStop() {
745 if (webview())
746 webview()->StopLoading();
747}
748
[email protected]e6f546c32009-07-01 17:12:55749void RenderView::OnLoadAlternateHTMLText(const std::string& html,
initial.commit09911bf2008-07-26 23:55:29750 bool new_navigation,
751 const GURL& display_url,
752 const std::string& security_info) {
753 if (!webview())
754 return;
755
[email protected]e6f546c32009-07-01 17:12:55756 pending_navigation_state_.reset(NavigationState::CreateBrowserInitiated(
757 new_navigation ? -1 : page_id_, PageTransition::LINK, Time::Now()));
758 pending_navigation_state_->set_security_info(security_info);
initial.commit09911bf2008-07-26 23:55:29759
[email protected]dd7daa82009-08-10 05:46:45760 webview()->GetMainFrame()->loadHTMLString(html,
[email protected]e6f546c32009-07-01 17:12:55761 GURL(kUnreachableWebDataURL),
762 display_url,
763 !new_navigation);
764
765 pending_navigation_state_.reset();
initial.commit09911bf2008-07-26 23:55:29766}
767
768void RenderView::OnCopyImageAt(int x, int y) {
769 webview()->CopyImageAt(x, y);
770}
771
[email protected]68b1e922009-06-23 16:00:25772void RenderView::OnExecuteEditCommand(const std::string& name,
773 const std::string& value) {
774 if (!webview() || !webview()->GetFocusedFrame())
775 return;
776
[email protected]dd7daa82009-08-10 05:46:45777 webview()->GetFocusedFrame()->executeCommand(
778 WebString::fromUTF8(name), WebString::fromUTF8(value));
[email protected]68b1e922009-06-23 16:00:25779}
780
[email protected]b2abac72009-02-26 12:39:28781void RenderView::OnSetupDevToolsClient() {
[email protected]e4ac5df2009-03-17 15:33:11782 DCHECK(!devtools_client_.get());
783 devtools_client_.reset(new DevToolsClient(this));
[email protected]b2abac72009-02-26 12:39:28784}
785
initial.commit09911bf2008-07-26 23:55:29786void RenderView::OnStopFinding(bool clear_selection) {
787 WebView* view = webview();
788 if (!view)
789 return;
790
791 if (clear_selection)
[email protected]a100d76bb2009-08-14 17:50:22792 view->GetFocusedFrame()->executeCommand(WebString::fromUTF8("Unselect"));
initial.commit09911bf2008-07-26 23:55:29793
794 WebFrame* frame = view->GetMainFrame();
795 while (frame) {
[email protected]dd7daa82009-08-10 05:46:45796 frame->stopFinding(clear_selection);
initial.commit09911bf2008-07-26 23:55:29797 frame = view->GetNextFrameAfter(frame, false);
798 }
799}
800
801void RenderView::OnFindReplyAck() {
802 // Check if there is any queued up request waiting to be sent.
803 if (queued_find_reply_message_.get()) {
804 // Send the search result over to the browser process.
805 Send(queued_find_reply_message_.get());
806 queued_find_reply_message_.release();
807 }
808}
809
810void RenderView::OnUpdateTargetURLAck() {
811 // Check if there is a targeturl waiting to be sent.
812 if (target_url_status_ == TARGET_PENDING) {
813 Send(new ViewHostMsg_UpdateTargetURL(routing_id_, page_id_,
814 pending_target_url_));
815 }
816
817 target_url_status_ = TARGET_NONE;
818}
819
820void RenderView::OnUndo() {
821 if (!webview())
822 return;
823
[email protected]dd7daa82009-08-10 05:46:45824 webview()->GetFocusedFrame()->executeCommand(WebString::fromUTF8("Undo"));
825 UserMetricsRecordAction(L"Undo");
initial.commit09911bf2008-07-26 23:55:29826}
827
828void RenderView::OnRedo() {
829 if (!webview())
830 return;
831
[email protected]dd7daa82009-08-10 05:46:45832 webview()->GetFocusedFrame()->executeCommand(WebString::fromUTF8("Redo"));
833 UserMetricsRecordAction(L"Redo");
initial.commit09911bf2008-07-26 23:55:29834}
835
836void RenderView::OnCut() {
837 if (!webview())
838 return;
839
[email protected]dd7daa82009-08-10 05:46:45840 webview()->GetFocusedFrame()->executeCommand(WebString::fromUTF8("Cut"));
841 UserMetricsRecordAction(L"Cut");
initial.commit09911bf2008-07-26 23:55:29842}
843
844void RenderView::OnCopy() {
845 if (!webview())
846 return;
847
[email protected]dd7daa82009-08-10 05:46:45848 webview()->GetFocusedFrame()->executeCommand(WebString::fromUTF8("Copy"));
849 UserMetricsRecordAction(L"Copy");
initial.commit09911bf2008-07-26 23:55:29850}
851
[email protected]c0cc3092009-09-12 08:27:27852#if defined(OS_MACOSX)
[email protected]a954bf72009-09-12 07:30:35853void RenderView::OnCopyToFindPboard() {
854 if (!webview())
855 return;
856
857 // Since the find pasteboard supports only plain text, this can be simpler
858 // than the |OnCopy()| case.
859 WebFrame* frame = webview()->GetFocusedFrame();
860 if (frame->hasSelection()) {
861 string16 selection = frame->selectionAsText();
862 RenderThread::current()->Send(
863 new ViewHostMsg_ClipboardFindPboardWriteStringAsync(selection));
864 }
865
866 UserMetricsRecordAction(L"CopyToFindPboard");
867}
[email protected]c0cc3092009-09-12 08:27:27868#endif
[email protected]a954bf72009-09-12 07:30:35869
initial.commit09911bf2008-07-26 23:55:29870void RenderView::OnPaste() {
871 if (!webview())
872 return;
873
[email protected]dd7daa82009-08-10 05:46:45874 webview()->GetFocusedFrame()->executeCommand(WebString::fromUTF8("Paste"));
875 UserMetricsRecordAction(L"Paste");
initial.commit09911bf2008-07-26 23:55:29876}
877
878void RenderView::OnReplace(const std::wstring& text) {
879 if (!webview())
880 return;
881
[email protected]dd7daa82009-08-10 05:46:45882 webview()->GetFocusedFrame()->replaceSelection(WideToUTF16Hack(text));
initial.commit09911bf2008-07-26 23:55:29883}
884
[email protected]98324892009-09-09 21:16:05885void RenderView::OnAdvanceToNextMisspelling() {
886 if (!webview())
887 return;
888 webview()->GetFocusedFrame()->executeCommand(
889 WebString::fromUTF8("AdvanceToNextMisspelling"));
890}
891
892void RenderView::OnToggleSpellPanel(bool is_currently_visible) {
893 if (!webview())
894 return;
895 // We need to tell the webView whether the spelling panel is visible or not so
896 // that it won't need to make ipc calls later.
897 webview()->SetSpellingPanelVisibility(is_currently_visible);
898 webview()->GetFocusedFrame()->executeCommand(
899 WebString::fromUTF8("ToggleSpellPanel"));
900}
901
[email protected]bbbd545c2008-12-15 20:18:04902void RenderView::OnToggleSpellCheck() {
903 if (!webview())
904 return;
905
[email protected]dd7daa82009-08-10 05:46:45906 WebFrame* frame = webview()->GetFocusedFrame();
907 frame->enableContinuousSpellChecking(
908 !frame->isContinuousSpellCheckingEnabled());
[email protected]bbbd545c2008-12-15 20:18:04909}
910
initial.commit09911bf2008-07-26 23:55:29911void RenderView::OnDelete() {
912 if (!webview())
913 return;
914
[email protected]dd7daa82009-08-10 05:46:45915 webview()->GetFocusedFrame()->executeCommand(WebString::fromUTF8("Delete"));
916 UserMetricsRecordAction(L"DeleteSelection");
initial.commit09911bf2008-07-26 23:55:29917}
918
919void RenderView::OnSelectAll() {
920 if (!webview())
921 return;
922
[email protected]a100d76bb2009-08-14 17:50:22923 webview()->GetFocusedFrame()->executeCommand(
924 WebString::fromUTF8("SelectAll"));
925 UserMetricsRecordAction(L"SelectAll");
initial.commit09911bf2008-07-26 23:55:29926}
927
928void RenderView::OnSetInitialFocus(bool reverse) {
929 if (!webview())
930 return;
931 webview()->SetInitialFocus(reverse);
932}
933
934///////////////////////////////////////////////////////////////////////////////
935
936// Tell the embedding application that the URL of the active page has changed
937void RenderView::UpdateURL(WebFrame* frame) {
[email protected]dd7daa82009-08-10 05:46:45938 WebDataSource* ds = frame->dataSource();
initial.commit09911bf2008-07-26 23:55:29939 DCHECK(ds);
940
[email protected]726985e22009-06-18 21:09:28941 const WebURLRequest& request = ds->request();
942 const WebURLRequest& original_request = ds->originalRequest();
943 const WebURLResponse& response = ds->response();
initial.commit09911bf2008-07-26 23:55:29944
[email protected]daa8c58e2009-06-15 17:21:10945 NavigationState* navigation_state = NavigationState::FromDataSource(ds);
946 DCHECK(navigation_state);
initial.commit09911bf2008-07-26 23:55:29947
948 ViewHostMsg_FrameNavigate_Params params;
[email protected]726985e22009-06-18 21:09:28949 params.http_status_code = response.httpStatusCode();
initial.commit09911bf2008-07-26 23:55:29950 params.is_post = false;
951 params.page_id = page_id_;
[email protected]726985e22009-06-18 21:09:28952 params.is_content_filtered = response.isContentFiltered();
[email protected]e6f546c32009-07-01 17:12:55953 if (!navigation_state->security_info().empty()) {
initial.commit09911bf2008-07-26 23:55:29954 // SSL state specified in the request takes precedence over the one in the
955 // response.
956 // So far this is only intended for error pages that are not expected to be
957 // over ssl, so we should not get any clash.
[email protected]726985e22009-06-18 21:09:28958 DCHECK(response.securityInfo().isEmpty());
[email protected]e6f546c32009-07-01 17:12:55959 params.security_info = navigation_state->security_info();
initial.commit09911bf2008-07-26 23:55:29960 } else {
[email protected]726985e22009-06-18 21:09:28961 params.security_info = response.securityInfo();
initial.commit09911bf2008-07-26 23:55:29962 }
963
964 // Set the URL to be displayed in the browser UI to the user.
[email protected]726985e22009-06-18 21:09:28965 if (ds->hasUnreachableURL()) {
966 params.url = ds->unreachableURL();
initial.commit09911bf2008-07-26 23:55:29967 } else {
[email protected]726985e22009-06-18 21:09:28968 params.url = request.url();
initial.commit09911bf2008-07-26 23:55:29969 }
970
[email protected]726985e22009-06-18 21:09:28971 GetRedirectChain(ds, &params.redirects);
972 params.should_update_history = !ds->hasUnreachableURL();
initial.commit09911bf2008-07-26 23:55:29973
974 const SearchableFormData* searchable_form_data =
[email protected]daa8c58e2009-06-15 17:21:10975 navigation_state->searchable_form_data();
initial.commit09911bf2008-07-26 23:55:29976 if (searchable_form_data) {
977 params.searchable_form_url = searchable_form_data->url();
978 params.searchable_form_element_name = searchable_form_data->element_name();
979 params.searchable_form_encoding = searchable_form_data->encoding();
980 }
981
982 const PasswordForm* password_form_data =
[email protected]daa8c58e2009-06-15 17:21:10983 navigation_state->password_form_data();
initial.commit09911bf2008-07-26 23:55:29984 if (password_form_data)
985 params.password_form = *password_form_data;
986
987 params.gesture = navigation_gesture_;
988 navigation_gesture_ = NavigationGestureUnknown;
989
[email protected]dd7daa82009-08-10 05:46:45990 if (!frame->parent()) {
initial.commit09911bf2008-07-26 23:55:29991 // Top-level navigation.
992
993 // Update contents MIME type for main frame.
[email protected]9c5645b2009-08-11 03:37:55994 params.contents_mime_type = ds->response().mimeType().utf8();
initial.commit09911bf2008-07-26 23:55:29995
[email protected]daa8c58e2009-06-15 17:21:10996 params.transition = navigation_state->transition_type();
initial.commit09911bf2008-07-26 23:55:29997 if (!PageTransition::IsMainFrame(params.transition)) {
998 // If the main frame does a load, it should not be reported as a subframe
999 // navigation. This can occur in the following case:
1000 // 1. You're on a site with frames.
1001 // 2. You do a subframe navigation. This is stored with transition type
1002 // MANUAL_SUBFRAME.
1003 // 3. You navigate to some non-frame site, say, google.com.
1004 // 4. You navigate back to the page from step 2. Since it was initially
1005 // MANUAL_SUBFRAME, it will be that same transition type here.
1006 // We don't want that, because any navigation that changes the toplevel
1007 // frame should be tracked as a toplevel navigation (this allows us to
1008 // update the URL bar, etc).
1009 params.transition = PageTransition::LINK;
1010 }
1011
initial.commit09911bf2008-07-26 23:55:291012 // If we have a valid consumed client redirect source,
1013 // the page contained a client redirect (meta refresh, document.loc...),
1014 // so we set the referrer and transition to match.
1015 if (completed_client_redirect_src_.is_valid()) {
[email protected]77e09a92008-08-01 18:11:041016 DCHECK(completed_client_redirect_src_ == params.redirects[0]);
initial.commit09911bf2008-07-26 23:55:291017 params.referrer = completed_client_redirect_src_;
1018 params.transition = static_cast<PageTransition::Type>(
1019 params.transition | PageTransition::CLIENT_REDIRECT);
1020 } else {
1021 // Bug 654101: the referrer will be empty on https->http transitions. It
1022 // would be nice if we could get the real referrer from somewhere.
[email protected]726985e22009-06-18 21:09:281023 params.referrer = GURL(
1024 original_request.httpHeaderField(WebString::fromUTF8("Referer")));
initial.commit09911bf2008-07-26 23:55:291025 }
1026
[email protected]726985e22009-06-18 21:09:281027 string16 method = request.httpMethod();
1028 if (EqualsASCII(method, "POST"))
initial.commit09911bf2008-07-26 23:55:291029 params.is_post = true;
1030
[email protected]c2a797d2009-09-21 16:46:321031 // Save some histogram data so we can compute the average memory used per
1032 // page load of the glyphs.
1033 UMA_HISTOGRAM_COUNTS_10000("Memory.GlyphPagesPerLoad",
1034 webkit_glue::GetGlyphPageCount());
1035
initial.commit09911bf2008-07-26 23:55:291036 Send(new ViewHostMsg_FrameNavigate(routing_id_, params));
1037 } else {
1038 // Subframe navigation: the type depends on whether this navigation
1039 // generated a new session history entry. When they do generate a session
1040 // history entry, it means the user initiated the navigation and we should
1041 // mark it as such. This test checks if this is the first time UpdateURL
1042 // has been called since WillNavigateToURL was called to initiate the load.
1043 if (page_id_ > last_page_id_sent_to_browser_)
1044 params.transition = PageTransition::MANUAL_SUBFRAME;
1045 else
1046 params.transition = PageTransition::AUTO_SUBFRAME;
1047
initial.commit09911bf2008-07-26 23:55:291048 Send(new ViewHostMsg_FrameNavigate(routing_id_, params));
1049 }
1050
1051 last_page_id_sent_to_browser_ =
1052 std::max(last_page_id_sent_to_browser_, page_id_);
1053
1054 // If we end up reusing this WebRequest (for example, due to a #ref click),
[email protected]daa8c58e2009-06-15 17:21:101055 // we don't want the transition type to persist. Just clear it.
1056 navigation_state->set_transition_type(PageTransition::LINK);
[email protected]266eb6f2008-09-30 23:56:501057
[email protected]6c8afae52009-01-22 02:24:571058#if defined(OS_WIN)
[email protected]6a983b42009-03-20 20:12:251059 if (web_accessibility_manager_.get()) {
[email protected]be645db2009-02-06 20:36:331060 // Clear accessibility info cache.
[email protected]6a983b42009-03-20 20:12:251061 web_accessibility_manager_->ClearAccObjMap(-1, true);
[email protected]266eb6f2008-09-30 23:56:501062 }
[email protected]6c8afae52009-01-22 02:24:571063#else
[email protected]7d926f92009-03-03 14:26:541064 // TODO(port): accessibility not yet implemented. See http://crbug.com/8288.
[email protected]6c8afae52009-01-22 02:24:571065#endif
initial.commit09911bf2008-07-26 23:55:291066}
1067
1068// Tell the embedding application that the title of the active page has changed
[email protected]3d9689372009-09-10 04:29:171069void RenderView::UpdateTitle(WebFrame* frame, const string16& title) {
initial.commit09911bf2008-07-26 23:55:291070 // Ignore all but top level navigations...
[email protected]3d9689372009-09-10 04:29:171071 if (!frame->parent()) {
[email protected]f0af6a72009-05-30 05:25:171072 Send(new ViewHostMsg_UpdateTitle(
[email protected]3d9689372009-09-10 04:29:171073 routing_id_,
1074 page_id_,
1075 UTF16ToWideHack(title.length() > chrome::kMaxTitleChars ?
1076 title.substr(0, chrome::kMaxTitleChars) : title)));
[email protected]f0af6a72009-05-30 05:25:171077 }
initial.commit09911bf2008-07-26 23:55:291078}
1079
1080void RenderView::UpdateEncoding(WebFrame* frame,
[email protected]41fc0322009-09-04 22:23:401081 const std::string& encoding_name) {
initial.commit09911bf2008-07-26 23:55:291082 // Only update main frame's encoding_name.
1083 if (webview()->GetMainFrame() == frame &&
1084 last_encoding_name_ != encoding_name) {
[email protected]e38f40152008-09-12 23:08:301085 // Save the encoding name for later comparing.
initial.commit09911bf2008-07-26 23:55:291086 last_encoding_name_ = encoding_name;
1087
[email protected]e38f40152008-09-12 23:08:301088 Send(new ViewHostMsg_UpdateEncoding(routing_id_, last_encoding_name_));
initial.commit09911bf2008-07-26 23:55:291089 }
1090}
1091
[email protected]f4d34b52008-11-24 23:05:011092// Sends the previous session history state to the browser so it will be saved
1093// before we navigate to a new page. This must be called *before* the page ID
1094// has been updated so we know what it was.
initial.commit09911bf2008-07-26 23:55:291095void RenderView::UpdateSessionHistory(WebFrame* frame) {
1096 // If we have a valid page ID at this point, then it corresponds to the page
1097 // we are navigating away from. Otherwise, this is the first navigation, so
1098 // there is no past session history to record.
1099 if (page_id_ == -1)
1100 return;
1101
[email protected]ca948a22009-06-25 19:36:171102 const WebHistoryItem& item =
[email protected]dd7daa82009-08-10 05:46:451103 webview()->GetMainFrame()->previousHistoryItem();
[email protected]ca948a22009-06-25 19:36:171104 if (item.isNull())
initial.commit09911bf2008-07-26 23:55:291105 return;
[email protected]ca948a22009-06-25 19:36:171106
1107 Send(new ViewHostMsg_UpdateState(
1108 routing_id_, page_id_, webkit_glue::HistoryItemToString(item)));
initial.commit09911bf2008-07-26 23:55:291109}
1110
[email protected]3d9689372009-09-10 04:29:171111void RenderView::OpenURL(
1112 const GURL& url, const GURL& referrer, WebNavigationPolicy policy) {
1113 Send(new ViewHostMsg_OpenURL(
1114 routing_id_, url, referrer, NavigationPolicyToDisposition(policy)));
1115}
1116
[email protected]79dbc662009-09-04 05:42:511117// WebViewDelegate ------------------------------------------------------------
initial.commit09911bf2008-07-26 23:55:291118
[email protected]a2f6bc112009-06-27 16:27:251119void RenderView::DidPaint() {
1120 WebFrame* main_frame = webview()->GetMainFrame();
1121
[email protected]dd7daa82009-08-10 05:46:451122 if (main_frame->provisionalDataSource()) {
[email protected]a2f6bc112009-06-27 16:27:251123 // If we have a provisional frame we are between the start
1124 // and commit stages of loading...ignore this paint.
1125 return;
1126 }
1127
[email protected]dd7daa82009-08-10 05:46:451128 WebDataSource* ds = main_frame->dataSource();
[email protected]a2f6bc112009-06-27 16:27:251129 NavigationState* navigation_state = NavigationState::FromDataSource(ds);
[email protected]78a3a6f2009-07-02 16:15:011130 DCHECK(navigation_state);
1131
1132 Time now = Time::Now();
1133 if (navigation_state->first_paint_time().is_null()) {
1134 navigation_state->set_first_paint_time(now);
1135 }
1136 if (navigation_state->first_paint_after_load_time().is_null() &&
1137 !navigation_state->finish_load_time().is_null()) {
1138 navigation_state->set_first_paint_after_load_time(now);
[email protected]a2f6bc112009-06-27 16:27:251139 }
1140}
1141
initial.commit09911bf2008-07-26 23:55:291142void RenderView::LoadNavigationErrorPage(WebFrame* frame,
[email protected]726985e22009-06-18 21:09:281143 const WebURLRequest& failed_request,
1144 const WebURLError& error,
initial.commit09911bf2008-07-26 23:55:291145 const std::string& html,
1146 bool replace) {
[email protected]726985e22009-06-18 21:09:281147 GURL failed_url = error.unreachableURL;
initial.commit09911bf2008-07-26 23:55:291148
1149 std::string alt_html;
1150 if (html.empty()) {
1151 // Use a local error page.
1152 int resource_id;
1153 DictionaryValue error_strings;
[email protected]726985e22009-06-18 21:09:281154 if (error.reason == net::ERR_CACHE_MISS &&
1155 EqualsASCII(failed_request.httpMethod(), "POST")) {
initial.commit09911bf2008-07-26 23:55:291156 GetFormRepostErrorValues(failed_url, &error_strings);
1157 resource_id = IDR_ERROR_NO_DETAILS_HTML;
1158 } else {
1159 GetLocalizedErrorValues(error, &error_strings);
1160 resource_id = IDR_NET_ERROR_HTML;
1161 }
[email protected]8e50b602009-03-03 22:59:431162 error_strings.SetString(L"textdirection",
1163 (l10n_util::GetTextDirection() == l10n_util::RIGHT_TO_LEFT) ?
1164 L"rtl" : L"ltr");
initial.commit09911bf2008-07-26 23:55:291165
1166 alt_html = GetAltHTMLForTemplate(error_strings, resource_id);
1167 } else {
1168 alt_html = html;
1169 }
1170
[email protected]dd7daa82009-08-10 05:46:451171 frame->loadHTMLString(alt_html,
[email protected]e6f546c32009-07-01 17:12:551172 GURL(kUnreachableWebDataURL),
1173 failed_url,
1174 replace);
initial.commit09911bf2008-07-26 23:55:291175}
1176
[email protected]7ccddb8c2009-08-04 17:36:551177void RenderView::BindDOMAutomationController(WebFrame* frame) {
initial.commit09911bf2008-07-26 23:55:291178 dom_automation_controller_.set_message_sender(this);
1179 dom_automation_controller_.set_routing_id(routing_id_);
[email protected]7ccddb8c2009-08-04 17:36:551180 dom_automation_controller_.BindToJavascript(frame,
initial.commit09911bf2008-07-26 23:55:291181 L"domAutomationController");
1182}
1183
[email protected]b6ce15972009-07-14 22:14:011184void RenderView::DidCreateScriptContextForFrame(WebFrame* webframe) {
[email protected]7120f132009-07-20 21:05:371185 EventBindings::HandleContextCreated(webframe, false);
[email protected]f816c012009-06-26 21:48:321186}
1187
[email protected]b6ce15972009-07-14 22:14:011188void RenderView::DidDestroyScriptContextForFrame(WebFrame* webframe) {
[email protected]f816c012009-06-26 21:48:321189 EventBindings::HandleContextDestroyed(webframe);
1190}
1191
[email protected]b6ce15972009-07-14 22:14:011192void RenderView::DidCreateIsolatedScriptContext(WebFrame* webframe) {
[email protected]7120f132009-07-20 21:05:371193 EventBindings::HandleContextCreated(webframe, true);
[email protected]b6ce15972009-07-14 22:14:011194}
1195
initial.commit09911bf2008-07-26 23:55:291196bool RenderView::RunJavaScriptMessage(int type,
1197 const std::wstring& message,
1198 const std::wstring& default_value,
[email protected]a455d3812009-03-05 20:18:071199 const GURL& frame_url,
initial.commit09911bf2008-07-26 23:55:291200 std::wstring* result) {
1201 bool success = false;
1202 std::wstring result_temp;
1203 if (!result)
1204 result = &result_temp;
initial.commit09911bf2008-07-26 23:55:291205
[email protected]12636df2009-09-28 22:32:211206 SendAndRunNestedMessageLoop(new ViewHostMsg_RunJavaScriptMessage(
1207 routing_id_, message, default_value, frame_url, type, &success, result));
initial.commit09911bf2008-07-26 23:55:291208 return success;
1209}
1210
1211void RenderView::AddGURLSearchProvider(const GURL& osd_url, bool autodetected) {
1212 if (!osd_url.is_empty())
1213 Send(new ViewHostMsg_PageHasOSDD(routing_id_, page_id_, osd_url,
1214 autodetected));
1215}
1216
[email protected]0ebf3872008-11-07 21:35:031217void RenderView::QueryFormFieldAutofill(const std::wstring& field_name,
1218 const std::wstring& text,
1219 int64 node_id) {
1220 static int message_id_counter = 0;
1221 form_field_autofill_request_id_ = message_id_counter++;
1222 Send(new ViewHostMsg_QueryFormFieldAutofill(routing_id_,
1223 field_name, text,
1224 node_id,
1225 form_field_autofill_request_id_));
1226}
1227
[email protected]4d2b6fb2009-03-20 22:28:171228void RenderView::RemoveStoredAutofillEntry(const std::wstring& name,
1229 const std::wstring& value) {
1230 Send(new ViewHostMsg_RemoveAutofillEntry(routing_id_, name, value));
1231}
1232
[email protected]0ebf3872008-11-07 21:35:031233void RenderView::OnReceivedAutofillSuggestions(
1234 int64 node_id,
1235 int request_id,
[email protected]8d0f15c2008-11-11 01:01:091236 const std::vector<std::wstring>& suggestions,
[email protected]0ebf3872008-11-07 21:35:031237 int default_suggestion_index) {
1238 if (!webview() || request_id != form_field_autofill_request_id_)
1239 return;
1240
1241 webview()->AutofillSuggestionsForNode(node_id, suggestions,
1242 default_suggestion_index);
1243}
1244
[email protected]2c4410d2009-05-06 23:46:221245void RenderView::OnPopupNotificationVisibilityChanged(bool visible) {
[email protected]634a6f92008-12-01 21:39:311246 popup_notification_visible_ = visible;
1247}
1248
initial.commit09911bf2008-07-26 23:55:291249uint32 RenderView::GetCPBrowsingContext() {
1250 uint32 context = 0;
1251 Send(new ViewHostMsg_GetCPBrowsingContext(&context));
1252 return context;
1253}
1254
[email protected]b62d1a8c2009-01-13 23:54:571255void RenderView::RunFileChooser(bool multi_select,
[email protected]b949f1112009-04-12 20:03:081256 const string16& title,
1257 const FilePath& default_filename,
initial.commit09911bf2008-07-26 23:55:291258 WebFileChooserCallback* file_chooser) {
1259 if (file_chooser_.get()) {
1260 // TODO(brettw): bug 1235154: This should be a synchronous message to deal
1261 // with the fact that web pages can programatically trigger this. With the
1262 // asnychronous messages, we can get an additional call when one is pending,
1263 // which this test is for. For now, we just ignore the additional file
1264 // chooser request. WebKit doesn't do anything to expect the callback, so
1265 // we can just ignore calling it.
1266 delete file_chooser;
1267 return;
1268 }
1269 file_chooser_.reset(file_chooser);
[email protected]b62d1a8c2009-01-13 23:54:571270 Send(new ViewHostMsg_RunFileChooser(routing_id_, multi_select, title,
[email protected]b949f1112009-04-12 20:03:081271 default_filename));
initial.commit09911bf2008-07-26 23:55:291272}
1273
initial.commit09911bf2008-07-26 23:55:291274void RenderView::AddSearchProvider(const std::string& url) {
1275 AddGURLSearchProvider(GURL(url),
1276 false); // not autodetected
1277}
1278
[email protected]f103ab72009-09-02 17:10:591279void RenderView::OnMissingPluginStatus(
1280 WebPluginDelegateProxy* delegate,
1281 int status) {
[email protected]6c8afae52009-01-22 02:24:571282#if defined(OS_WIN)
[email protected]f103ab72009-09-02 17:10:591283 if (!first_default_plugin_) {
initial.commit09911bf2008-07-26 23:55:291284 // Show the InfoBar for the first available plugin.
1285 if (status == default_plugin::MISSING_PLUGIN_AVAILABLE) {
[email protected]f103ab72009-09-02 17:10:591286 first_default_plugin_ = delegate->AsWeakPtr();
initial.commit09911bf2008-07-26 23:55:291287 Send(new ViewHostMsg_MissingPluginStatus(routing_id_, status));
1288 }
1289 } else {
1290 // Closes the InfoBar if user clicks on the plugin (instead of the InfoBar)
1291 // to start the download/install.
1292 if (status == default_plugin::MISSING_PLUGIN_USER_STARTED_DOWNLOAD) {
1293 Send(new ViewHostMsg_MissingPluginStatus(routing_id_, status));
1294 }
1295 }
[email protected]6c8afae52009-01-22 02:24:571296#else
1297 // TODO(port): plugins current not supported
1298 NOTIMPLEMENTED();
1299#endif
initial.commit09911bf2008-07-26 23:55:291300}
1301
[email protected]48c9cf2d2009-09-16 16:47:521302// WebKit::WebViewClient ------------------------------------------------------
1303
1304WebView* RenderView::createView(WebFrame* creator) {
1305 // Check to make sure we aren't overloading on popups.
1306 if (shared_popup_counter_->data > kMaximumNumberOfUnacknowledgedPopups)
1307 return NULL;
1308
1309 // This window can't be closed from a window.close() call until we receive a
1310 // message from the Browser process explicitly allowing it.
1311 popup_notification_visible_ = true;
1312
1313 int32 routing_id = MSG_ROUTING_NONE;
1314 bool user_gesture = creator->isProcessingUserGesture();
1315
[email protected]48c9cf2d2009-09-16 16:47:521316 render_thread_->Send(
[email protected]12636df2009-09-28 22:32:211317 new ViewHostMsg_CreateWindow(routing_id_, user_gesture, &routing_id));
1318 if (routing_id == MSG_ROUTING_NONE)
[email protected]48c9cf2d2009-09-16 16:47:521319 return NULL;
[email protected]48c9cf2d2009-09-16 16:47:521320
[email protected]48c9cf2d2009-09-16 16:47:521321 RenderView* view = RenderView::Create(render_thread_,
[email protected]12636df2009-09-28 22:32:211322 NULL,
1323 routing_id_,
[email protected]48c9cf2d2009-09-16 16:47:521324 renderer_preferences_,
1325 webkit_preferences_,
[email protected]12636df2009-09-28 22:32:211326 shared_popup_counter_,
1327 routing_id);
[email protected]48c9cf2d2009-09-16 16:47:521328 view->opened_by_user_gesture_ = user_gesture;
1329
1330 // Record the security origin of the creator.
[email protected]91733b62009-09-18 06:21:091331 GURL creator_url(creator->securityOrigin().toString().utf8());
[email protected]48c9cf2d2009-09-16 16:47:521332 if (!creator_url.is_valid() || !creator_url.IsStandard())
1333 creator_url = GURL();
1334 view->creator_url_ = creator_url;
1335
1336 // Copy over the alternate error page URL so we can have alt error pages in
1337 // the new render view (we don't need the browser to send the URL back down).
1338 view->alternate_error_page_url_ = alternate_error_page_url_;
1339
1340 return view->webview();
1341}
1342
1343WebWidget* RenderView::createPopupMenu(bool activatable) {
1344 RenderWidget* widget = RenderWidget::Create(routing_id_,
1345 render_thread_,
1346 activatable);
1347 return widget->webwidget();
1348}
1349
1350WebWidget* RenderView::createPopupMenu(const WebPopupMenuInfo& info) {
1351 RenderWidget* widget = RenderWidget::Create(routing_id_,
1352 render_thread_,
1353 true);
1354 widget->ConfigureAsExternalPopupMenu(info);
1355 return widget->webwidget();
1356}
1357
1358void RenderView::didAddMessageToConsole(
1359 const WebConsoleMessage& message, const WebString& source_name,
1360 unsigned source_line) {
1361 Send(new ViewHostMsg_AddMessageToConsole(routing_id_,
1362 UTF16ToWideHack(message.text),
1363 static_cast<int32>(source_line),
1364 UTF16ToWideHack(source_name)));
1365}
1366
1367void RenderView::printPage(WebFrame* frame) {
[email protected]71a14262009-09-22 20:02:581368 DCHECK(frame);
1369 Print(frame, true);
[email protected]48c9cf2d2009-09-16 16:47:521370}
1371
1372void RenderView::didStartLoading() {
1373 if (is_loading_) {
1374 DLOG(WARNING) << "didStartLoading called while loading";
1375 return;
1376 }
1377
1378 is_loading_ = true;
1379 // Clear the pointer so that we can assign it only when there is an unknown
1380 // plugin on a page.
1381 first_default_plugin_.reset();
1382
1383 Send(new ViewHostMsg_DidStartLoading(routing_id_));
1384}
1385
1386void RenderView::didStopLoading() {
1387 if (!is_loading_) {
1388 DLOG(WARNING) << "DidStopLoading called while not loading";
1389 return;
1390 }
1391
1392 is_loading_ = false;
1393
1394 // NOTE: For now we're doing the safest thing, and sending out notification
1395 // when done loading. This currently isn't an issue as the favicon is only
1396 // displayed when done loading. Ideally we would send notification when
1397 // finished parsing the head, but webkit doesn't support that yet.
1398 // The feed discovery code would also benefit from access to the head.
1399 GURL favicon_url(webview()->GetMainFrame()->favIconURL());
1400 if (!favicon_url.is_empty())
1401 Send(new ViewHostMsg_UpdateFavIconURL(routing_id_, page_id_, favicon_url));
1402
1403 AddGURLSearchProvider(webview()->GetMainFrame()->openSearchDescriptionURL(),
1404 true); // autodetected
1405
1406 Send(new ViewHostMsg_DidStopLoading(routing_id_));
1407
1408 MessageLoop::current()->PostDelayedTask(FROM_HERE,
1409 method_factory_.NewRunnableMethod(&RenderView::CapturePageInfo, page_id_,
1410 false),
1411 kDelayForCaptureMs);
1412
1413 // The page is loaded. Try to process the file we need to upload if any.
1414 ProcessPendingUpload();
1415
1416 // Since the page is done loading, we are sure we don't need to try
1417 // again.
1418 ResetPendingUpload();
1419}
1420
[email protected]04fc9482009-09-18 22:13:031421bool RenderView::shouldBeginEditing(const WebRange& range) {
1422 return true;
1423}
1424
1425bool RenderView::shouldEndEditing(const WebRange& range) {
1426 return true;
1427}
1428
1429bool RenderView::shouldInsertNode(const WebNode& node, const WebRange& range,
1430 WebEditingAction action) {
1431 return true;
1432}
1433
1434bool RenderView::shouldInsertText(const WebString& text, const WebRange& range,
1435 WebEditingAction action) {
1436 return true;
1437}
1438
1439bool RenderView::shouldChangeSelectedRange(const WebRange& from_range,
1440 const WebRange& to_range,
1441 WebTextAffinity affinity,
1442 bool still_selecting) {
1443 return true;
1444}
1445
1446bool RenderView::shouldDeleteRange(const WebRange& range) {
1447 return true;
1448}
1449
1450bool RenderView::shouldApplyStyle(const WebString& style,
1451 const WebRange& range) {
1452 return true;
1453}
1454
1455bool RenderView::isSmartInsertDeleteEnabled() {
1456 return true;
1457}
1458
1459bool RenderView::isSelectTrailingWhitespaceEnabled() {
1460#if defined(OS_WIN)
1461 return true;
1462#else
1463 return false;
1464#endif
1465}
1466
1467void RenderView::setInputMethodEnabled(bool enabled) {
1468 // Save the updated IME status and mark the input focus has been updated.
1469 // The IME status is to be sent to a browser process next time when
1470 // the input caret is rendered.
1471 if (!ime_control_busy_) {
1472 ime_control_updated_ = true;
1473 ime_control_new_state_ = enabled;
1474 }
1475}
1476
1477void RenderView::didChangeSelection(bool is_empty_selection) {
1478#if defined(OS_LINUX)
1479 if (!handling_input_event_)
1480 return;
1481 // TODO(estade): investigate incremental updates to the selection so that we
1482 // don't send the entire selection over IPC every time.
1483 if (!is_empty_selection) {
1484 // Sometimes we get repeated didChangeSelection calls from webkit when
1485 // the selection hasn't actually changed. We don't want to report these
1486 // because it will cause us to continually claim the X clipboard.
1487 const std::string& this_selection =
1488 webview()->GetFocusedFrame()->selectionAsText().utf8();
1489 if (this_selection == last_selection_)
1490 return;
1491
1492 Send(new ViewHostMsg_SelectionChanged(routing_id_,
1493 this_selection));
1494 last_selection_ = this_selection;
1495 } else {
1496 last_selection_.clear();
1497 }
1498#endif
1499}
1500
1501void RenderView::didExecuteCommand(const WebString& command_name) {
1502 const std::wstring& name = UTF16ToWideHack(command_name);
1503 if (StartsWith(name, L"Move", true) ||
1504 StartsWith(name, L"Insert", true) ||
1505 StartsWith(name, L"Delete", true))
1506 return;
1507 UserMetricsRecordAction(name);
1508}
1509
[email protected]b2528b72009-09-24 06:57:101510bool RenderView::handleCurrentKeyboardEvent() {
1511 if (edit_commands_.empty())
1512 return false;
1513
1514 WebFrame* frame = webview()->GetFocusedFrame();
1515 if (!frame)
1516 return false;
1517
1518 EditCommands::iterator it = edit_commands_.begin();
1519 EditCommands::iterator end = edit_commands_.end();
1520
[email protected]507b33ea2009-09-29 03:56:511521 bool did_execute_command = false;
[email protected]b2528b72009-09-24 06:57:101522 for (; it != end; ++it) {
[email protected]507b33ea2009-09-29 03:56:511523 // In gtk, it's possible to bind multiple edit commands to one key (but it's
1524 // the exception). Once one edit command is not executed, it seems safest to
1525 // not execute the rest.
[email protected]b2528b72009-09-24 06:57:101526 if (!frame->executeCommand(WebString::fromUTF8(it->name),
1527 WebString::fromUTF8(it->value)))
1528 break;
[email protected]507b33ea2009-09-29 03:56:511529 did_execute_command = true;
[email protected]b2528b72009-09-24 06:57:101530 }
1531
[email protected]507b33ea2009-09-29 03:56:511532 return did_execute_command;
[email protected]b2528b72009-09-24 06:57:101533}
1534
[email protected]1dbafaf72009-09-23 19:43:561535void RenderView::spellCheck(
1536 const WebString& text, int& misspelled_offset, int& misspelled_length) {
1537 EnsureDocumentTag();
1538 Send(new ViewHostMsg_SpellCheck(
1539 routing_id_, UTF16ToWideHack(text), document_tag_,
1540 &misspelled_offset, &misspelled_length));
1541}
1542
1543WebString RenderView::autoCorrectWord(const WebKit::WebString& word) {
1544 std::wstring autocorrect_word;
1545 const CommandLine& command_line = *CommandLine::ForCurrentProcess();
1546 if (command_line.HasSwitch(switches::kAutoSpellCorrect)) {
1547 EnsureDocumentTag();
1548 Send(new ViewHostMsg_GetAutoCorrectWord(
1549 routing_id_, UTF16ToWideHack(word), document_tag_, &autocorrect_word));
1550 }
1551 return WideToUTF16Hack(autocorrect_word);
1552}
1553
1554void RenderView::updateSpellingUIWithMisspelledWord(const WebString& word) {
1555 Send(new ViewHostMsg_UpdateSpellingPanelWithMisspelledWord(
1556 routing_id_, UTF16ToWideHack(word)));
1557}
1558
[email protected]48c9cf2d2009-09-16 16:47:521559void RenderView::runModalAlertDialog(
1560 WebFrame* frame, const WebString& message) {
1561 RunJavaScriptMessage(MessageBoxFlags::kIsJavascriptAlert,
1562 UTF16ToWideHack(message),
1563 std::wstring(),
1564 frame->url(),
1565 NULL);
1566}
1567
1568bool RenderView::runModalConfirmDialog(
1569 WebFrame* frame, const WebString& message) {
1570 return RunJavaScriptMessage(MessageBoxFlags::kIsJavascriptConfirm,
1571 UTF16ToWideHack(message),
1572 std::wstring(),
1573 frame->url(),
1574 NULL);
1575}
1576
1577bool RenderView::runModalPromptDialog(
1578 WebFrame* frame, const WebString& message, const WebString& default_value,
1579 WebString* actual_value) {
1580 std::wstring result;
1581 bool ok = RunJavaScriptMessage(MessageBoxFlags::kIsJavascriptPrompt,
1582 UTF16ToWideHack(message),
1583 UTF16ToWideHack(default_value),
1584 frame->url(),
1585 &result);
1586 if (ok)
1587 actual_value->assign(WideToUTF16Hack(result));
1588 return ok;
1589}
1590
1591bool RenderView::runModalBeforeUnloadDialog(
1592 WebFrame* frame, const WebString& message) {
1593 bool success = false;
1594 // This is an ignored return value, but is included so we can accept the same
1595 // response as RunJavaScriptMessage.
1596 std::wstring ignored_result;
[email protected]12636df2009-09-28 22:32:211597 SendAndRunNestedMessageLoop(new ViewHostMsg_RunBeforeUnloadConfirm(
[email protected]48c9cf2d2009-09-16 16:47:521598 routing_id_, frame->url(), UTF16ToWideHack(message), &success,
[email protected]12636df2009-09-28 22:32:211599 &ignored_result));
[email protected]48c9cf2d2009-09-16 16:47:521600 return success;
1601}
1602
1603void RenderView::setStatusText(const WebString& text) {
1604}
1605
1606void RenderView::setMouseOverURL(const WebURL& url) {
[email protected]8d32b9832009-09-17 06:21:011607 GURL latest_url(url);
[email protected]48c9cf2d2009-09-16 16:47:521608 if (latest_url == target_url_)
1609 return;
1610 // Tell the browser to display a destination link.
1611 if (target_url_status_ == TARGET_INFLIGHT ||
1612 target_url_status_ == TARGET_PENDING) {
1613 // If we have a request in-flight, save the URL to be sent when we
1614 // receive an ACK to the in-flight request. We can happily overwrite
1615 // any existing pending sends.
1616 pending_target_url_ = latest_url;
1617 target_url_status_ = TARGET_PENDING;
1618 } else {
1619 Send(new ViewHostMsg_UpdateTargetURL(routing_id_, page_id_, latest_url));
1620 target_url_ = latest_url;
1621 target_url_status_ = TARGET_INFLIGHT;
1622 }
1623}
1624
1625void RenderView::setToolTipText(const WebString& text, WebTextDirection hint) {
1626 Send(new ViewHostMsg_SetTooltipText(routing_id_, UTF16ToWideHack(text),
1627 hint));
1628}
1629
1630void RenderView::startDragging(const WebPoint& from, const WebDragData& data,
1631 WebDragOperationsMask allowed_ops) {
1632 Send(new ViewHostMsg_StartDragging(routing_id_,
1633 WebDropData(data),
1634 allowed_ops));
1635}
1636
[email protected]28b92df2009-09-25 17:35:451637bool RenderView::acceptsLoadDrops() {
1638 return renderer_preferences_.can_accept_load_drops;
1639}
1640
[email protected]48c9cf2d2009-09-16 16:47:521641void RenderView::focusNext() {
1642 Send(new ViewHostMsg_TakeFocus(routing_id_, false));
1643}
1644
1645void RenderView::focusPrevious() {
1646 Send(new ViewHostMsg_TakeFocus(routing_id_, true));
1647}
1648
1649void RenderView::navigateBackForwardSoon(int offset) {
1650 history_back_list_count_ += offset;
1651 history_forward_list_count_ -= offset;
1652
1653 Send(new ViewHostMsg_GoToEntryAtOffset(routing_id_, offset));
1654}
1655
1656int RenderView::historyBackListCount() {
1657 return history_back_list_count_;
1658}
1659
1660int RenderView::historyForwardListCount() {
1661 return history_forward_list_count_;
1662}
1663
1664void RenderView::didAddHistoryItem() {
1665 // We don't want to update the history length for the start page
1666 // navigation.
1667 WebFrame* main_frame = webview()->GetMainFrame();
1668 DCHECK(main_frame != NULL);
1669
1670 WebDataSource* ds = main_frame->dataSource();
1671 DCHECK(ds != NULL);
1672
1673 NavigationState* navigation_state = NavigationState::FromDataSource(ds);
1674 DCHECK(navigation_state);
1675 if (navigation_state->transition_type() == PageTransition::START_PAGE)
1676 return;
1677
1678 history_back_list_count_++;
1679 history_forward_list_count_ = 0;
1680}
1681
[email protected]79dbc662009-09-04 05:42:511682// WebKit::WebWidgetClient ----------------------------------------------------
1683
initial.commit09911bf2008-07-26 23:55:291684// We are supposed to get a single call to Show for a newly created RenderView
1685// that was created via RenderView::CreateWebView. So, we wait until this
1686// point to dispatch the ShowView message.
1687//
1688// This method provides us with the information about how to display the newly
1689// created RenderView (i.e., as a constrained popup or as a new tab).
1690//
[email protected]4873c7d2009-07-16 06:36:281691void RenderView::show(WebNavigationPolicy policy) {
initial.commit09911bf2008-07-26 23:55:291692 DCHECK(!did_show_) << "received extraneous Show call";
1693 DCHECK(opener_id_ != MSG_ROUTING_NONE);
1694
1695 if (did_show_)
1696 return;
1697 did_show_ = true;
1698
1699 // NOTE: initial_pos_ may still have its default values at this point, but
1700 // that's okay. It'll be ignored if disposition is not NEW_POPUP, or the
1701 // browser process will impose a default position otherwise.
[email protected]4873c7d2009-07-16 06:36:281702 Send(new ViewHostMsg_ShowView(opener_id_, routing_id_,
1703 NavigationPolicyToDisposition(policy), initial_pos_,
1704 opened_by_user_gesture_, creator_url_));
[email protected]2533ce12009-05-09 00:02:241705 SetPendingWindowRect(initial_pos_);
initial.commit09911bf2008-07-26 23:55:291706}
1707
[email protected]4873c7d2009-07-16 06:36:281708void RenderView::closeWidgetSoon() {
[email protected]2c4410d2009-05-06 23:46:221709 if (!popup_notification_visible_)
[email protected]4873c7d2009-07-16 06:36:281710 RenderWidget::closeWidgetSoon();
[email protected]634a6f92008-12-01 21:39:311711}
1712
[email protected]4873c7d2009-07-16 06:36:281713void RenderView::runModal() {
initial.commit09911bf2008-07-26 23:55:291714 DCHECK(did_show_) << "should already have shown the view";
1715
[email protected]12636df2009-09-28 22:32:211716 SendAndRunNestedMessageLoop(new ViewHostMsg_RunModal(routing_id_));
initial.commit09911bf2008-07-26 23:55:291717}
1718
[email protected]3d9689372009-09-10 04:29:171719// WebKit::WebFrameClient -----------------------------------------------------
1720
1721WebPlugin* RenderView::createPlugin(
1722 WebFrame* frame, const WebPluginParams& params) {
1723 return new webkit_glue::WebPluginImpl(frame, params, AsWeakPtr());
1724}
1725
1726WebWorker* RenderView::createWorker(WebFrame* frame, WebWorkerClient* client) {
1727 return new WebWorkerProxy(client, RenderThread::current(), routing_id_);
1728}
1729
1730WebMediaPlayer* RenderView::createMediaPlayer(
1731 WebFrame* frame, WebMediaPlayerClient* client) {
1732 scoped_refptr<media::FilterFactoryCollection> factory =
1733 new media::FilterFactoryCollection();
1734 // Add in any custom filter factories first.
1735 const CommandLine* cmd_line = CommandLine::ForCurrentProcess();
1736 if (!cmd_line->HasSwitch(switches::kDisableAudio)) {
1737 // Add the chrome specific audio renderer.
1738 factory->AddFactory(
1739 AudioRendererImpl::CreateFactory(audio_message_filter()));
1740 }
1741
1742 // TODO(hclam): obtain the following parameters from |client|.
1743 webkit_glue::MediaResourceLoaderBridgeFactory* bridge_factory =
1744 new webkit_glue::MediaResourceLoaderBridgeFactory(
1745 GURL::EmptyGURL(), // referrer
1746 "null", // frame origin
1747 "null", // main_frame_origin
1748 base::GetCurrentProcId(),
1749 appcache::kNoHostId,
1750 routing_id());
1751
1752 if (!cmd_line->HasSwitch(switches::kSimpleDataSource)) {
1753 // Add the chrome specific media data source.
1754 factory->AddFactory(
1755 webkit_glue::BufferedDataSource::CreateFactory(MessageLoop::current(),
1756 bridge_factory));
1757 } else {
1758 factory->AddFactory(
1759 webkit_glue::SimpleDataSource::CreateFactory(MessageLoop::current(),
1760 bridge_factory));
1761 }
1762 return new webkit_glue::WebMediaPlayerImpl(client, factory);
1763}
1764
1765void RenderView::willClose(WebFrame* frame) {
1766 if (!frame->parent()) {
1767 const GURL& url = frame->url();
1768 if (url.SchemeIs("http") || url.SchemeIs("https"))
1769 DumpLoadHistograms();
1770 }
1771}
1772
1773void RenderView::loadURLExternally(
1774 WebFrame* frame, const WebURLRequest& request,
1775 WebNavigationPolicy policy) {
[email protected]efce17b2009-09-11 18:04:591776 GURL referrer(request.httpHeaderField(WebString::fromUTF8("Referer")));
1777 if (policy == WebKit::WebNavigationPolicyDownload) {
1778 Send(new ViewHostMsg_DownloadUrl(routing_id_, request.url(), referrer));
1779 } else {
1780 OpenURL(request.url(), referrer, policy);
1781 }
[email protected]3d9689372009-09-10 04:29:171782}
1783
1784WebNavigationPolicy RenderView::decidePolicyForNavigation(
1785 WebFrame* frame, const WebURLRequest& request, WebNavigationType type,
1786 WebNavigationPolicy default_policy, bool is_redirect) {
1787 // Webkit is asking whether to navigate to a new URL.
1788 // This is fine normally, except if we're showing UI from one security
1789 // context and they're trying to navigate to a different context.
1790 const GURL& url = request.url();
1791
1792 // If the browser is interested, then give it a chance to look at top level
1793 // navigations
1794 if (renderer_preferences_.browser_handles_top_level_requests &&
1795 // Only send once.
1796 last_top_level_navigation_page_id_ != page_id_ &&
1797 // Not interested in reloads.
1798 type != WebKit::WebNavigationTypeReload &&
1799 type != WebKit::WebNavigationTypeFormSubmitted &&
1800 // Must be a top level frame.
1801 frame->parent() == NULL) {
1802 // Skip if navigation is on the same page (using '#').
1803 GURL frame_origin = GURL(frame->url()).GetOrigin();
1804 if (url.GetOrigin() != frame_origin || url.ref().empty()) {
1805 last_top_level_navigation_page_id_ = page_id_;
1806 OpenURL(url, GURL(), default_policy);
1807 return WebKit::WebNavigationPolicyIgnore; // Suppress the load here.
1808 }
1809 }
1810
1811 // A content initiated navigation may have originated from a link-click,
1812 // script, drag-n-drop operation, etc.
1813 bool is_content_initiated =
1814 NavigationState::FromDataSource(frame->provisionalDataSource())->
1815 is_content_initiated();
1816
1817 // We only care about navigations that are within the current tab (as opposed
1818 // to, for example, opening a new window).
1819 // But we sometimes navigate to about:blank to clear a tab, and we want to
1820 // still allow that.
1821 if (default_policy == WebKit::WebNavigationPolicyCurrentTab &&
1822 is_content_initiated && frame->parent() == NULL &&
1823 !url.SchemeIs(chrome::kAboutScheme)) {
1824 // When we received such unsolicited navigations, we sometimes want to
1825 // punt them up to the browser to handle.
1826 if (BindingsPolicy::is_dom_ui_enabled(enabled_bindings_) ||
1827 BindingsPolicy::is_extension_enabled(enabled_bindings_) ||
1828 frame->isViewSourceModeEnabled() ||
1829 url.SchemeIs(chrome::kViewSourceScheme) ||
1830 url.SchemeIs(chrome::kPrintScheme)) {
1831 OpenURL(url, GURL(), default_policy);
1832 return WebKit::WebNavigationPolicyIgnore; // Suppress the load here.
1833 }
1834 }
1835
1836 // Detect when a page is "forking" a new tab that can be safely rendered in
1837 // its own process. This is done by sites like Gmail that try to open links
1838 // in new windows without script connections back to the original page. We
1839 // treat such cases as browser navigations (in which we will create a new
1840 // renderer for a cross-site navigation), rather than WebKit navigations.
1841 //
1842 // We use the following heuristic to decide whether to fork a new page in its
1843 // own process:
1844 // The parent page must open a new tab to about:blank, set the new tab's
1845 // window.opener to null, and then redirect the tab to a cross-site URL using
1846 // JavaScript.
1847 bool is_fork =
1848 // Must start from a tab showing about:blank, which is later redirected.
[email protected]e0d481582009-09-15 21:06:251849 GURL(frame->url()) == GURL(chrome::kAboutBlankURL) &&
[email protected]3d9689372009-09-10 04:29:171850 // Must be the first real navigation of the tab.
[email protected]48c9cf2d2009-09-16 16:47:521851 historyBackListCount() < 1 &&
1852 historyForwardListCount() < 1 &&
[email protected]3d9689372009-09-10 04:29:171853 // The parent page must have set the child's window.opener to null before
1854 // redirecting to the desired URL.
1855 frame->opener() == NULL &&
1856 // Must be a top-level frame.
1857 frame->parent() == NULL &&
1858 // Must not have issued the request from this page.
1859 is_content_initiated &&
1860 // Must be targeted at the current tab.
1861 default_policy == WebKit::WebNavigationPolicyCurrentTab &&
1862 // Must be a JavaScript navigation, which appears as "other".
1863 type == WebKit::WebNavigationTypeOther;
1864 if (is_fork) {
1865 // Open the URL via the browser, not via WebKit.
1866 OpenURL(url, GURL(), default_policy);
1867 return WebKit::WebNavigationPolicyIgnore;
1868 }
1869
1870 return default_policy;
1871}
1872
1873void RenderView::willSubmitForm(WebFrame* frame, const WebForm& form) {
1874 NavigationState* navigation_state =
1875 NavigationState::FromDataSource(frame->provisionalDataSource());
1876
1877 if (navigation_state->transition_type() == PageTransition::LINK)
1878 navigation_state->set_transition_type(PageTransition::FORM_SUBMIT);
1879
1880 // Save these to be processed when the ensuing navigation is committed.
1881 navigation_state->set_searchable_form_data(
1882 SearchableFormData::Create(form));
1883 navigation_state->set_password_form_data(
1884 PasswordFormDomManager::CreatePasswordForm(form));
1885
1886 if (form.isAutoCompleteEnabled()) {
1887 scoped_ptr<AutofillForm> autofill_form(AutofillForm::Create(form));
1888 if (autofill_form.get())
1889 Send(new ViewHostMsg_AutofillFormSubmitted(routing_id_, *autofill_form));
1890 }
1891}
1892
1893void RenderView::willPerformClientRedirect(
1894 WebFrame* frame, const WebURL& from, const WebURL& to, double interval,
1895 double fire_time) {
1896 // Ignore
1897}
1898
1899void RenderView::didCancelClientRedirect(WebFrame* frame) {
1900 // Ignore
1901}
1902
1903void RenderView::didCompleteClientRedirect(
1904 WebFrame* frame, const WebURL& from) {
1905 if (!frame->parent())
1906 completed_client_redirect_src_ = from;
1907}
1908
1909void RenderView::didCreateDataSource(WebFrame* frame, WebDataSource* ds) {
1910 // The rest of RenderView assumes that a WebDataSource will always have a
1911 // non-null NavigationState.
1912 if (pending_navigation_state_.get()) {
1913 ds->setExtraData(pending_navigation_state_.release());
1914 } else {
1915 ds->setExtraData(NavigationState::CreateContentInitiated());
1916 }
1917}
1918
1919void RenderView::didStartProvisionalLoad(WebFrame* frame) {
1920 WebDataSource* ds = frame->provisionalDataSource();
1921 NavigationState* navigation_state = NavigationState::FromDataSource(ds);
1922
1923 navigation_state->set_start_load_time(Time::Now());
1924
1925 // Update the request time if WebKit has better knowledge of it.
1926 if (navigation_state->request_time().is_null()) {
1927 double event_time = ds->triggeringEventTime();
1928 if (event_time != 0.0)
1929 navigation_state->set_request_time(Time::FromDoubleT(event_time));
1930 }
1931
1932 bool is_top_most = !frame->parent();
1933 if (is_top_most) {
1934 navigation_gesture_ = frame->isProcessingUserGesture() ?
1935 NavigationGestureUnknown : NavigationGestureAuto;
1936
1937 // Make sure redirect tracking state is clear for the new load.
1938 completed_client_redirect_src_ = GURL();
1939 } else if (frame->parent()->isLoading()) {
1940 // Take note of AUTO_SUBFRAME loads here, so that we can know how to
1941 // load an error page. See DidFailProvisionalLoadWithError.
1942 navigation_state->set_transition_type(PageTransition::AUTO_SUBFRAME);
1943 }
1944
1945 Send(new ViewHostMsg_DidStartProvisionalLoadForFrame(
1946 routing_id_, is_top_most, ds->request().url()));
1947}
1948
1949void RenderView::didReceiveServerRedirectForProvisionalLoad(WebFrame* frame) {
1950 if (frame->parent())
1951 return;
1952 // Received a redirect on the main frame.
1953 WebDataSource* data_source = frame->provisionalDataSource();
1954 if (!data_source) {
1955 // Should only be invoked when we have a data source.
1956 NOTREACHED();
1957 return;
1958 }
1959 std::vector<GURL> redirects;
1960 GetRedirectChain(data_source, &redirects);
1961 if (redirects.size() >= 2) {
1962 Send(new ViewHostMsg_DidRedirectProvisionalLoad(
1963 routing_id_, page_id_, redirects[redirects.size() - 2],
1964 redirects[redirects.size() - 1]));
1965 }
1966}
1967
1968void RenderView::didFailProvisionalLoad(
1969 WebFrame* frame, const WebURLError& error) {
1970 // Notify the browser that we failed a provisional load with an error.
1971 //
1972 // Note: It is important this notification occur before DidStopLoading so the
1973 // SSL manager can react to the provisional load failure before being
1974 // notified the load stopped.
1975 //
1976 WebDataSource* ds = frame->provisionalDataSource();
1977 DCHECK(ds);
1978
1979 const WebURLRequest& failed_request = ds->request();
1980
1981 bool show_repost_interstitial =
1982 (error.reason == net::ERR_CACHE_MISS &&
1983 EqualsASCII(failed_request.httpMethod(), "POST"));
1984 Send(new ViewHostMsg_DidFailProvisionalLoadWithError(
1985 routing_id_, !frame->parent(), error.reason, error.unreachableURL,
1986 show_repost_interstitial));
1987
1988 // Don't display an error page if this is simply a cancelled load. Aside
1989 // from being dumb, WebCore doesn't expect it and it will cause a crash.
1990 if (error.reason == net::ERR_ABORTED)
1991 return;
1992
1993 // Make sure we never show errors in view source mode.
1994 frame->enableViewSourceMode(false);
1995
1996 NavigationState* navigation_state = NavigationState::FromDataSource(ds);
1997
1998 // If this is a failed back/forward/reload navigation, then we need to do a
1999 // 'replace' load. This is necessary to avoid messing up session history.
2000 // Otherwise, we do a normal load, which simulates a 'go' navigation as far
2001 // as session history is concerned.
2002 //
2003 // AUTO_SUBFRAME loads should always be treated as loads that do not advance
2004 // the page id.
2005 //
2006 bool replace =
2007 navigation_state->pending_page_id() != -1 ||
2008 navigation_state->transition_type() == PageTransition::AUTO_SUBFRAME;
2009
2010 // If we failed on a browser initiated request, then make sure that our error
2011 // page load is regarded as the same browser initiated request.
2012 if (!navigation_state->is_content_initiated()) {
2013 pending_navigation_state_.reset(NavigationState::CreateBrowserInitiated(
2014 navigation_state->pending_page_id(),
2015 navigation_state->transition_type(),
2016 navigation_state->request_time()));
2017 }
2018
2019 // Provide the user with a more helpful error page?
2020 if (MaybeLoadAlternateErrorPage(frame, error, replace))
2021 return;
2022
2023 // Fallback to a local error page.
2024 LoadNavigationErrorPage(frame, failed_request, error, std::string(),
2025 replace);
2026}
2027
2028void RenderView::didReceiveDocumentData(
2029 WebFrame* frame, const char* data, size_t data_len,
2030 bool& prevent_default) {
2031 NavigationState* navigation_state =
2032 NavigationState::FromDataSource(frame->dataSource());
2033 if (!navigation_state->postpone_loading_data())
2034 return;
2035
2036 // We're going to call commitDocumentData ourselves...
2037 prevent_default = true;
2038
2039 // Continue buffering the response data for the original 404 page. If it
2040 // grows too large, then we'll just let it through.
2041 navigation_state->append_postponed_data(data, data_len);
2042 if (navigation_state->postponed_data().size() >= 512) {
2043 navigation_state->set_postpone_loading_data(false);
2044 frame->commitDocumentData(navigation_state->postponed_data().data(),
2045 navigation_state->postponed_data().size());
2046 navigation_state->clear_postponed_data();
2047 }
2048}
2049
2050void RenderView::didCommitProvisionalLoad(
2051 WebFrame* frame, bool is_new_navigation) {
2052 NavigationState* navigation_state =
2053 NavigationState::FromDataSource(frame->dataSource());
2054
2055 navigation_state->set_commit_load_time(Time::Now());
2056 if (is_new_navigation) {
2057 // When we perform a new navigation, we need to update the previous session
2058 // history entry with state for the page we are leaving.
2059 UpdateSessionHistory(frame);
2060
2061 // We bump our Page ID to correspond with the new session history entry.
2062 page_id_ = next_page_id_++;
2063
2064 MessageLoop::current()->PostDelayedTask(FROM_HERE,
2065 method_factory_.NewRunnableMethod(&RenderView::CapturePageInfo,
2066 page_id_, true),
2067 kDelayForForcedCaptureMs);
2068 } else {
2069 // Inspect the navigation_state on this frame to see if the navigation
2070 // corresponds to a session history navigation... Note: |frame| may or
2071 // may not be the toplevel frame, but for the case of capturing session
2072 // history, the first committed frame suffices. We keep track of whether
2073 // we've seen this commit before so that only capture session history once
2074 // per navigation.
2075 //
2076 // Note that we need to check if the page ID changed. In the case of a
2077 // reload, the page ID doesn't change, and UpdateSessionHistory gets the
2078 // previous URL and the current page ID, which would be wrong.
2079 if (navigation_state->pending_page_id() != -1 &&
2080 navigation_state->pending_page_id() != page_id_ &&
2081 !navigation_state->request_committed()) {
2082 // This is a successful session history navigation!
2083 UpdateSessionHistory(frame);
2084 page_id_ = navigation_state->pending_page_id();
2085 }
2086 }
2087
2088 // Remember that we've already processed this request, so we don't update
2089 // the session history again. We do this regardless of whether this is
2090 // a session history navigation, because if we attempted a session history
2091 // navigation without valid HistoryItem state, WebCore will think it is a
2092 // new navigation.
2093 navigation_state->set_request_committed(true);
2094
2095 UpdateURL(frame);
2096
2097 // If this committed load was initiated by a client redirect, we're
2098 // at the last stop now, so clear it.
2099 completed_client_redirect_src_ = GURL();
2100
2101 // Check whether we have new encoding name.
2102 UpdateEncoding(frame, frame->view()->GetMainFrameEncodingName());
2103}
2104
2105void RenderView::didClearWindowObject(WebFrame* frame) {
2106 if (BindingsPolicy::is_dom_automation_enabled(enabled_bindings_))
2107 BindDOMAutomationController(frame);
2108 if (BindingsPolicy::is_dom_ui_enabled(enabled_bindings_)) {
2109 dom_ui_bindings_.set_message_sender(this);
2110 dom_ui_bindings_.set_routing_id(routing_id_);
2111 dom_ui_bindings_.BindToJavascript(frame, L"chrome");
2112 }
2113 if (BindingsPolicy::is_external_host_enabled(enabled_bindings_)) {
2114 external_host_bindings_.set_message_sender(this);
2115 external_host_bindings_.set_routing_id(routing_id_);
2116 external_host_bindings_.BindToJavascript(frame, L"externalHost");
2117 }
2118}
2119
2120void RenderView::didCreateDocumentElement(WebFrame* frame) {
2121 if (RenderThread::current()) { // Will be NULL during unit tests.
2122 RenderThread::current()->user_script_slave()->InjectScripts(
2123 frame, UserScript::DOCUMENT_START);
2124 }
[email protected]078b34612009-09-19 19:31:512125 if (view_type_ == ViewType::EXTENSION_TOOLSTRIP ||
2126 view_type_ == ViewType::EXTENSION_MOLE) {
2127 InjectToolstripCSS();
2128 ExtensionProcessBindings::SetViewType(webview(), view_type_);
2129 }
[email protected]3d9689372009-09-10 04:29:172130
[email protected]912256b32009-09-18 09:47:352131 while (!pending_code_execution_queue_.empty()) {
2132 scoped_refptr<CodeExecutionInfo> info =
2133 pending_code_execution_queue_.front();
2134 OnExecuteCode(info->request_id, info->extension_id, info->is_js_code,
2135 info->code_string);
2136 pending_code_execution_queue_.pop();
2137 }
2138
[email protected]3d9689372009-09-10 04:29:172139 // Notify the browser about non-blank documents loading in the top frame.
2140 GURL url = frame->url();
[email protected]e0d481582009-09-15 21:06:252141 if (url.is_valid() && url.spec() != chrome::kAboutBlankURL) {
[email protected]3d9689372009-09-10 04:29:172142 if (frame == webview()->GetMainFrame())
2143 Send(new ViewHostMsg_DocumentAvailableInMainFrame(routing_id_));
2144 }
2145}
2146
2147void RenderView::didReceiveTitle(WebFrame* frame, const WebString& title) {
2148 UpdateTitle(frame, title);
2149
2150 // Also check whether we have new encoding name.
2151 UpdateEncoding(frame, frame->view()->GetMainFrameEncodingName());
2152}
2153
2154void RenderView::didFinishDocumentLoad(WebFrame* frame) {
2155 WebDataSource* ds = frame->dataSource();
2156 NavigationState* navigation_state = NavigationState::FromDataSource(ds);
2157 DCHECK(navigation_state);
2158 navigation_state->set_finish_document_load_time(Time::Now());
2159
2160 Send(new ViewHostMsg_DocumentLoadedInFrame(routing_id_));
2161
2162 // The document has now been fully loaded. Scan for password forms to be
2163 // sent up to the browser.
2164 SendPasswordForms(frame);
2165
2166 // Check whether we have new encoding name.
2167 UpdateEncoding(frame, frame->view()->GetMainFrameEncodingName());
2168
2169 if (RenderThread::current()) { // Will be NULL during unit tests.
2170 RenderThread::current()->user_script_slave()->InjectScripts(
2171 frame, UserScript::DOCUMENT_END);
2172 }
2173}
2174
2175void RenderView::didHandleOnloadEvents(WebFrame* frame) {
2176 // Ignore
2177}
2178
2179void RenderView::didFailLoad(WebFrame* frame, const WebURLError& error) {
2180 // Ignore
2181}
2182
2183void RenderView::didFinishLoad(WebFrame* frame) {
2184 WebDataSource* ds = frame->dataSource();
2185 NavigationState* navigation_state = NavigationState::FromDataSource(ds);
2186 DCHECK(navigation_state);
2187 navigation_state->set_finish_load_time(Time::Now());
2188}
2189
2190void RenderView::didChangeLocationWithinPage(
2191 WebFrame* frame, bool is_new_navigation) {
2192 // If this was a reference fragment navigation that we initiated, then we
2193 // could end up having a non-null pending navigation state. We just need to
2194 // update the ExtraData on the datasource so that others who read the
2195 // ExtraData will get the new NavigationState. Similarly, if we did not
2196 // initiate this navigation, then we need to take care to reset any pre-
2197 // existing navigation state to a content-initiated navigation state.
2198 // DidCreateDataSource conveniently takes care of this for us.
2199 didCreateDataSource(frame, frame->dataSource());
2200
2201 didCommitProvisionalLoad(frame, is_new_navigation);
2202
2203 UpdateTitle(frame, frame->view()->GetMainFrame()->dataSource()->pageTitle());
2204}
2205
[email protected]476b6f82009-09-10 21:00:592206void RenderView::didUpdateCurrentHistoryItem(WebFrame* frame) {
2207 if (!nav_state_sync_timer_.IsRunning()) {
2208 nav_state_sync_timer_.Start(
2209 TimeDelta::FromSeconds(delay_seconds_for_form_state_sync_), this,
2210 &RenderView::SyncNavigationState);
2211 }
2212}
2213
[email protected]3d9689372009-09-10 04:29:172214void RenderView::assignIdentifierToRequest(
2215 WebFrame* frame, unsigned identifier, const WebURLRequest& request) {
2216 // Ignore
2217}
2218
2219void RenderView::willSendRequest(
2220 WebFrame* frame, unsigned identifier, WebURLRequest& request,
2221 const WebURLResponse& redirect_response) {
2222 request.setRequestorID(routing_id_);
2223}
2224
2225void RenderView::didReceiveResponse(
2226 WebFrame* frame, unsigned identifier, const WebURLResponse& response) {
2227 // Consider loading an alternate error page for 404 responses.
2228 if (response.httpStatusCode() != 404)
2229 return;
2230
2231 // Only do this for responses that correspond to a provisional data source
2232 // of the top-most frame. If we have a provisional data source, then we
2233 // can't have any sub-resources yet, so we know that this response must
2234 // correspond to a frame load.
2235 if (!frame->provisionalDataSource() || frame->parent())
2236 return;
2237
2238 // If we are in view source mode, then just let the user see the source of
2239 // the server's 404 error page.
2240 if (frame->isViewSourceModeEnabled())
2241 return;
2242
2243 // Can we even load an alternate error page for this URL?
2244 if (!GetAlternateErrorPageURL(response.url(), HTTP_404).is_valid())
2245 return;
2246
2247 NavigationState* navigation_state =
2248 NavigationState::FromDataSource(frame->provisionalDataSource());
2249 navigation_state->set_postpone_loading_data(true);
2250 navigation_state->clear_postponed_data();
2251}
2252
2253void RenderView::didFinishResourceLoad(
2254 WebFrame* frame, unsigned identifier) {
2255 NavigationState* navigation_state =
2256 NavigationState::FromDataSource(frame->dataSource());
2257 if (!navigation_state->postpone_loading_data())
2258 return;
2259
2260 // The server returned a 404 and the content was < 512 bytes (which we
2261 // suppressed). Go ahead and fetch the alternate page content.
2262
2263 const GURL& frame_url = frame->url();
2264
2265 const GURL& error_page_url = GetAlternateErrorPageURL(frame_url, HTTP_404);
2266 DCHECK(error_page_url.is_valid());
2267
2268 WebURLError original_error;
2269 original_error.unreachableURL = frame_url;
2270
2271 navigation_state->set_alt_error_page_fetcher(
2272 new AltErrorPageResourceFetcher(
2273 error_page_url, frame, original_error,
2274 NewCallback(this, &RenderView::AltErrorPageFinished)));
2275}
2276
2277void RenderView::didFailResourceLoad(
2278 WebFrame* frame, unsigned identifier, const WebURLError& error) {
2279 // Ignore
2280}
2281
2282void RenderView::didLoadResourceFromMemoryCache(
2283 WebFrame* frame, const WebURLRequest& request,
2284 const WebURLResponse& response) {
2285 // Let the browser know we loaded a resource from the memory cache. This
2286 // message is needed to display the correct SSL indicators.
2287 Send(new ViewHostMsg_DidLoadResourceFromMemoryCache(
2288 routing_id_,
2289 request.url(),
[email protected]91733b62009-09-18 06:21:092290 frame->securityOrigin().toString().utf8(),
2291 frame->top()->securityOrigin().toString().utf8(),
[email protected]3d9689372009-09-10 04:29:172292 response.securityInfo()));
2293}
2294
[email protected]e3d60e5d2009-09-25 21:08:292295void RenderView::didDisplayInsecureContent(WebKit::WebFrame* frame) {
2296 Send(new ViewHostMsg_DidDisplayInsecureContent(routing_id_));
2297}
2298
2299void RenderView::didRunInsecureContent(
2300 WebFrame* frame, const WebSecurityOrigin& origin) {
2301 Send(new ViewHostMsg_DidRunInsecureContent(
2302 routing_id_,
2303 origin.toString().utf8()));
2304}
2305
[email protected]3d9689372009-09-10 04:29:172306void RenderView::didExhaustMemoryAvailableForScript(WebFrame* frame) {
2307 Send(new ViewHostMsg_JSOutOfMemory(routing_id_));
2308}
2309
2310void RenderView::didChangeContentsSize(WebFrame* frame, const WebSize& size) {
2311 // We don't always want to send the change messages over IPC, only if we've
2312 // be put in that mode by getting a |ViewMsg_EnableIntrinsicWidthChangedMode|
2313 // message.
[email protected]f87eee052009-09-10 21:39:092314 if (send_preferred_width_changes_) {
[email protected]3d9689372009-09-10 04:29:172315 // WebCore likes to tell us things have changed even when they haven't, so
2316 // cache the width and only send the IPC message when we're sure the
2317 // width is different.
2318 int width = webview()->GetMainFrame()->contentsPreferredWidth();
2319 if (width != preferred_width_) {
2320 Send(new ViewHostMsg_DidContentsPreferredWidthChange(routing_id_, width));
2321 preferred_width_ = width;
2322 }
2323 }
2324}
2325
[email protected]79dbc662009-09-04 05:42:512326// webkit_glue::WebPluginPageDelegate -----------------------------------------
2327
[email protected]f103ab72009-09-02 17:10:592328webkit_glue::WebPluginDelegate* RenderView::CreatePluginDelegate(
2329 const GURL& url,
2330 const std::string& mime_type,
[email protected]f103ab72009-09-02 17:10:592331 std::string* actual_mime_type) {
2332 if (!PluginChannelHost::IsListening())
2333 return NULL;
2334
2335 GURL policy_url;
2336 WebFrame* main_frame = webview()->GetMainFrame();
2337 if (main_frame)
2338 policy_url = main_frame->url();
2339
2340 FilePath path;
[email protected]610c0892009-09-08 19:46:182341 render_thread_->Send(new ViewHostMsg_GetPluginPath(
2342 url, policy_url, mime_type, &path, actual_mime_type));
[email protected]f103ab72009-09-02 17:10:592343 if (path.value().empty())
2344 return NULL;
2345
2346 const std::string* mime_type_to_use;
2347 if (!actual_mime_type->empty())
2348 mime_type_to_use = actual_mime_type;
2349 else
2350 mime_type_to_use = &mime_type;
2351
[email protected]d032f492009-09-29 00:33:462352 bool in_process_plugin = RenderProcess::current()->in_process_plugins();
2353 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kInternalNaCl)) {
2354 if (mime_type == "application/x-nacl-srpc") {
2355 in_process_plugin = true;
2356 }
2357 }
2358 if (in_process_plugin) {
[email protected]f103ab72009-09-02 17:10:592359#if defined(OS_WIN) // In-proc plugins aren't supported on Linux or Mac.
[email protected]8a3b7962009-09-04 05:53:232360 return WebPluginDelegateImpl::Create(
[email protected]f103ab72009-09-02 17:10:592361 path, *mime_type_to_use, gfx::NativeViewFromId(host_window_));
2362#else
2363 NOTIMPLEMENTED();
2364 return NULL;
2365#endif
2366 }
2367
[email protected]610c0892009-09-08 19:46:182368 return new WebPluginDelegateProxy(*mime_type_to_use, AsWeakPtr());
[email protected]f103ab72009-09-02 17:10:592369}
2370
2371void RenderView::CreatedPluginWindow(gfx::PluginWindowHandle window) {
2372#if defined(OS_LINUX)
2373 RenderThread::current()->Send(new ViewHostMsg_CreatePluginContainer(
2374 routing_id(), window));
2375#endif
2376}
2377
2378void RenderView::WillDestroyPluginWindow(gfx::PluginWindowHandle window) {
2379#if defined(OS_LINUX)
2380 RenderThread::current()->Send(new ViewHostMsg_DestroyPluginContainer(
2381 routing_id(), window));
2382#endif
2383 CleanupWindowInPluginMoves(window);
2384}
2385
2386void RenderView::DidMovePlugin(const webkit_glue::WebPluginGeometry& move) {
2387 SchedulePluginMove(move);
2388}
2389
2390void RenderView::DidStartLoadingForPlugin() {
2391 // TODO(darin): Make is_loading_ be a counter!
[email protected]48c9cf2d2009-09-16 16:47:522392 didStartLoading();
[email protected]f103ab72009-09-02 17:10:592393}
2394
2395void RenderView::DidStopLoadingForPlugin() {
2396 // TODO(darin): Make is_loading_ be a counter!
[email protected]48c9cf2d2009-09-16 16:47:522397 didStopLoading();
[email protected]f103ab72009-09-02 17:10:592398}
2399
2400void RenderView::ShowModalHTMLDialogForPlugin(
2401 const GURL& url,
2402 const gfx::Size& size,
2403 const std::string& json_arguments,
2404 std::string* json_retval) {
[email protected]12636df2009-09-28 22:32:212405 SendAndRunNestedMessageLoop(new ViewHostMsg_ShowModalHTMLDialog(
[email protected]f103ab72009-09-02 17:10:592406 routing_id_, url, size.width(), size.height(), json_arguments,
[email protected]12636df2009-09-28 22:32:212407 json_retval));
[email protected]f103ab72009-09-02 17:10:592408}
2409
initial.commit09911bf2008-07-26 23:55:292410void RenderView::SyncNavigationState() {
2411 if (!webview())
2412 return;
2413
[email protected]dd7daa82009-08-10 05:46:452414 const WebHistoryItem& item = webview()->GetMainFrame()->currentHistoryItem();
[email protected]ca948a22009-06-25 19:36:172415 if (item.isNull())
initial.commit09911bf2008-07-26 23:55:292416 return;
[email protected]ca948a22009-06-25 19:36:172417
2418 Send(new ViewHostMsg_UpdateState(
2419 routing_id_, page_id_, webkit_glue::HistoryItemToString(item)));
initial.commit09911bf2008-07-26 23:55:292420}
2421
2422void RenderView::ShowContextMenu(WebView* webview,
[email protected]581b87eb2009-07-23 23:06:562423 ContextNodeType node_type,
initial.commit09911bf2008-07-26 23:55:292424 int x,
2425 int y,
2426 const GURL& link_url,
[email protected]574a1d62009-07-17 03:23:462427 const GURL& src_url,
initial.commit09911bf2008-07-26 23:55:292428 const GURL& page_url,
2429 const GURL& frame_url,
[email protected]574a1d62009-07-17 03:23:462430 const ContextMenuMediaParams& media_params,
initial.commit09911bf2008-07-26 23:55:292431 const std::wstring& selection_text,
2432 const std::wstring& misspelled_word,
[email protected]6aa376b2008-09-23 18:49:522433 int edit_flags,
[email protected]c9825a42009-05-01 22:51:502434 const std::string& security_info,
2435 const std::string& frame_charset) {
[email protected]e09ba552009-02-05 03:26:292436 ContextMenuParams params;
[email protected]581b87eb2009-07-23 23:06:562437 params.node_type = node_type;
initial.commit09911bf2008-07-26 23:55:292438 params.x = x;
2439 params.y = y;
[email protected]574a1d62009-07-17 03:23:462440 params.src_url = src_url;
initial.commit09911bf2008-07-26 23:55:292441 params.link_url = link_url;
[email protected]e6c79812009-04-22 22:31:422442 params.unfiltered_link_url = link_url;
initial.commit09911bf2008-07-26 23:55:292443 params.page_url = page_url;
2444 params.frame_url = frame_url;
[email protected]574a1d62009-07-17 03:23:462445 params.media_params = media_params;
initial.commit09911bf2008-07-26 23:55:292446 params.selection_text = selection_text;
2447 params.misspelled_word = misspelled_word;
[email protected]be645db2009-02-06 20:36:332448 params.spellcheck_enabled =
[email protected]dd7daa82009-08-10 05:46:452449 webview->GetFocusedFrame()->isContinuousSpellCheckingEnabled();
initial.commit09911bf2008-07-26 23:55:292450 params.edit_flags = edit_flags;
[email protected]6aa376b2008-09-23 18:49:522451 params.security_info = security_info;
[email protected]c9825a42009-05-01 22:51:502452 params.frame_charset = frame_charset;
initial.commit09911bf2008-07-26 23:55:292453 Send(new ViewHostMsg_ContextMenu(routing_id_, params));
2454}
2455
[email protected]b0950a72009-09-29 23:16:172456bool RenderView::DownloadImage(int id, const GURL& image_url, int image_size) {
2457 // Make sure webview was not shut down.
2458 if (!webview())
2459 return false;
2460 // Create an image resource fetcher and assign it with a call back object.
2461 image_fetchers_.insert(new ImageResourceFetcher(
2462 image_url, webview()->GetMainFrame(), id, image_size,
2463 NewCallback(this, &RenderView::DidDownloadImage)));
2464 return true;
2465}
2466
2467void RenderView::DidDownloadImage(ImageResourceFetcher* fetcher,
initial.commit09911bf2008-07-26 23:55:292468 const SkBitmap& image) {
[email protected]b0950a72009-09-29 23:16:172469 // Notify requester of image download status.
2470 Send(new ViewHostMsg_DidDownloadFavIcon(routing_id_,
2471 fetcher->id(),
2472 fetcher->image_url(),
2473 image.isNull(),
2474 image));
2475 // Dispose of the image fetcher.
2476 DCHECK(image_fetchers_.find(fetcher) != image_fetchers_.end());
2477 image_fetchers_.erase(fetcher);
2478 // We're in the callback from the ImageResourceFetcher, best to delay
2479 // deletion.
2480 MessageLoop::current()->DeleteSoon(FROM_HERE, fetcher);
initial.commit09911bf2008-07-26 23:55:292481}
2482
[email protected]bf5c2ff392009-07-08 16:24:332483void RenderView::OnDownloadFavIcon(int id,
2484 const GURL& image_url,
2485 int image_size) {
[email protected]f11ca0732009-04-11 00:09:342486 bool data_image_failed = false;
2487 if (image_url.SchemeIs("data")) {
2488 SkBitmap data_image = ImageFromDataUrl(image_url);
2489 data_image_failed = data_image.empty();
2490 if (!data_image_failed) {
[email protected]bf5c2ff392009-07-08 16:24:332491 Send(new ViewHostMsg_DidDownloadFavIcon(routing_id_, id, image_url, false,
2492 data_image));
[email protected]f11ca0732009-04-11 00:09:342493 }
2494 }
2495
[email protected]bf5c2ff392009-07-08 16:24:332496 if (data_image_failed ||
[email protected]b0950a72009-09-29 23:16:172497 !DownloadImage(id, image_url, image_size)) {
[email protected]bf5c2ff392009-07-08 16:24:332498 Send(new ViewHostMsg_DidDownloadFavIcon(routing_id_, id, image_url, true,
2499 SkBitmap()));
2500 }
initial.commit09911bf2008-07-26 23:55:292501}
2502
[email protected]f11ca0732009-04-11 00:09:342503SkBitmap RenderView::ImageFromDataUrl(const GURL& url) const {
2504 std::string mime_type, char_set, data;
2505 if (net::DataURL::Parse(url, &mime_type, &char_set, &data) && !data.empty()) {
2506 // Decode the favicon using WebKit's image decoder.
2507 webkit_glue::ImageDecoder decoder(gfx::Size(kFavIconSize, kFavIconSize));
2508 const unsigned char* src_data =
2509 reinterpret_cast<const unsigned char*>(&data[0]);
2510
2511 return decoder.Decode(src_data, data.size());
2512 }
2513 return SkBitmap();
2514}
2515
initial.commit09911bf2008-07-26 23:55:292516void RenderView::OnGetApplicationInfo(int page_id) {
2517 webkit_glue::WebApplicationInfo app_info;
2518 if (page_id == page_id_)
2519 webkit_glue::GetApplicationInfo(webview(), &app_info);
2520
2521 // Prune out any data URLs in the set of icons. The browser process expects
2522 // any icon with a data URL to have originated from a favicon. We don't want
2523 // to decode arbitrary data URLs in the browser process. See
2524 // http://b/issue?id=1162972
2525 for (size_t i = 0; i < app_info.icons.size(); ++i) {
[email protected]6de74452009-02-25 18:04:592526 if (app_info.icons[i].url.SchemeIs(chrome::kDataScheme)) {
initial.commit09911bf2008-07-26 23:55:292527 app_info.icons.erase(app_info.icons.begin() + i);
2528 --i;
2529 }
2530 }
2531
2532 Send(new ViewHostMsg_DidGetApplicationInfo(routing_id_, page_id, app_info));
2533}
2534
[email protected]7ccddb8c2009-08-04 17:36:552535GURL RenderView::GetAlternateErrorPageURL(const GURL& failed_url,
initial.commit09911bf2008-07-26 23:55:292536 ErrorPageType error_type) {
[email protected]7ccddb8c2009-08-04 17:36:552537 if (failed_url.SchemeIsSecure()) {
initial.commit09911bf2008-07-26 23:55:292538 // If the URL that failed was secure, then the embedding web page was not
2539 // expecting a network attacker to be able to manipulate its contents. As
2540 // we fetch alternate error pages over HTTP, we would be allowing a network
2541 // attacker to manipulate the contents of the response if we tried to use
2542 // the link doctor here.
2543 return GURL::EmptyGURL();
2544 }
2545
2546 // Grab the base URL from the browser process.
2547 if (!alternate_error_page_url_.is_valid())
2548 return GURL::EmptyGURL();
2549
2550 // Strip query params from the failed URL.
2551 GURL::Replacements remove_params;
2552 remove_params.ClearUsername();
2553 remove_params.ClearPassword();
2554 remove_params.ClearQuery();
2555 remove_params.ClearRef();
[email protected]7ccddb8c2009-08-04 17:36:552556 const GURL url_to_send = failed_url.ReplaceComponents(remove_params);
initial.commit09911bf2008-07-26 23:55:292557
2558 // Construct the query params to send to link doctor.
2559 std::string params(alternate_error_page_url_.query());
2560 params.append("&url=");
2561 params.append(EscapeQueryParamValue(url_to_send.spec()));
2562 params.append("&sourceid=chrome");
2563 params.append("&error=");
2564 switch (error_type) {
2565 case DNS_ERROR:
2566 params.append("dnserror");
2567 break;
2568
2569 case HTTP_404:
2570 params.append("http404");
2571 break;
2572
[email protected]5df266ac2008-10-15 19:50:132573 case CONNECTION_ERROR:
[email protected]e1f934b2009-01-26 20:41:332574 params.append("connectionfailure");
[email protected]5df266ac2008-10-15 19:50:132575 break;
2576
initial.commit09911bf2008-07-26 23:55:292577 default:
2578 NOTREACHED() << "unknown ErrorPageType";
2579 }
2580
2581 // OK, build the final url to return.
2582 GURL::Replacements link_doctor_params;
2583 link_doctor_params.SetQueryStr(params);
2584 GURL url = alternate_error_page_url_.ReplaceComponents(link_doctor_params);
2585 return url;
2586}
2587
[email protected]7ea066a2009-04-06 20:21:592588void RenderView::OnFind(int request_id,
2589 const string16& search_text,
2590 const WebKit::WebFindOptions& options) {
initial.commit09911bf2008-07-26 23:55:292591 WebFrame* main_frame = webview()->GetMainFrame();
2592 WebFrame* frame_after_main = webview()->GetNextFrameAfter(main_frame, true);
2593 WebFrame* focused_frame = webview()->GetFocusedFrame();
2594 WebFrame* search_frame = focused_frame; // start searching focused frame.
2595
2596 bool multi_frame = (frame_after_main != main_frame);
2597
2598 // If we have multiple frames, we don't want to wrap the search within the
2599 // frame, so we check here if we only have main_frame in the chain.
2600 bool wrap_within_frame = !multi_frame;
2601
[email protected]b3f2b912009-04-09 16:18:522602 WebRect selection_rect;
initial.commit09911bf2008-07-26 23:55:292603 bool result = false;
2604
2605 do {
[email protected]dd7daa82009-08-10 05:46:452606 result = search_frame->find(
[email protected]7ea066a2009-04-06 20:21:592607 request_id, search_text, options, wrap_within_frame, &selection_rect);
initial.commit09911bf2008-07-26 23:55:292608
2609 if (!result) {
2610 // don't leave text selected as you move to the next frame.
[email protected]a100d76bb2009-08-14 17:50:222611 search_frame->executeCommand(WebString::fromUTF8("Unselect"));
initial.commit09911bf2008-07-26 23:55:292612
2613 // Find the next frame, but skip the invisible ones.
2614 do {
2615 // What is the next frame to search? (we might be going backwards). Note
2616 // that we specify wrap=true so that search_frame never becomes NULL.
[email protected]7ea066a2009-04-06 20:21:592617 search_frame = options.forward ?
initial.commit09911bf2008-07-26 23:55:292618 webview()->GetNextFrameAfter(search_frame, true) :
2619 webview()->GetPreviousFrameBefore(search_frame, true);
[email protected]dd7daa82009-08-10 05:46:452620 } while (!search_frame->hasVisibleContent() &&
2621 search_frame != focused_frame);
initial.commit09911bf2008-07-26 23:55:292622
[email protected]884db412008-11-24 23:46:502623 // Make sure selection doesn't affect the search operation in new frame.
[email protected]a100d76bb2009-08-14 17:50:222624 search_frame->executeCommand(WebString::fromUTF8("Unselect"));
initial.commit09911bf2008-07-26 23:55:292625
2626 // If we have multiple frames and we have wrapped back around to the
2627 // focused frame, we need to search it once more allowing wrap within
2628 // the frame, otherwise it will report 'no match' if the focused frame has
2629 // reported matches, but no frames after the focused_frame contain a
2630 // match for the search word(s).
2631 if (multi_frame && search_frame == focused_frame) {
[email protected]dd7daa82009-08-10 05:46:452632 result = search_frame->find(
[email protected]7ea066a2009-04-06 20:21:592633 request_id, search_text, options, true, // Force wrapping.
2634 &selection_rect);
initial.commit09911bf2008-07-26 23:55:292635 }
2636 }
2637
initial.commit09911bf2008-07-26 23:55:292638 webview()->SetFocusedFrame(search_frame);
2639 } while (!result && search_frame != focused_frame);
2640
[email protected]7ea066a2009-04-06 20:21:592641 if (options.findNext) {
[email protected]4f3dc372009-02-24 00:10:292642 // Force the main_frame to report the actual count.
[email protected]dd7daa82009-08-10 05:46:452643 main_frame->increaseMatchCount(0, request_id);
[email protected]4f3dc372009-02-24 00:10:292644 } else {
2645 // If nothing is found, set result to "0 of 0", otherwise, set it to
2646 // "-1 of 1" to indicate that we found at least one item, but we don't know
2647 // yet what is active.
2648 int ordinal = result ? -1 : 0; // -1 here means, we might know more later.
2649 int match_count = result ? 1 : 0; // 1 here means possibly more coming.
initial.commit09911bf2008-07-26 23:55:292650
[email protected]4f3dc372009-02-24 00:10:292651 // If we find no matches then this will be our last status update.
2652 // Otherwise the scoping effort will send more results.
2653 bool final_status_update = !result;
initial.commit09911bf2008-07-26 23:55:292654
[email protected]4f3dc372009-02-24 00:10:292655 // Send the search result over to the browser process.
[email protected]4f999132009-03-31 18:08:402656 Send(new ViewHostMsg_Find_Reply(routing_id_,
[email protected]7ea066a2009-04-06 20:21:592657 request_id,
[email protected]4f3dc372009-02-24 00:10:292658 match_count,
2659 selection_rect,
2660 ordinal,
2661 final_status_update));
initial.commit09911bf2008-07-26 23:55:292662
initial.commit09911bf2008-07-26 23:55:292663 // Scoping effort begins, starting with the mainframe.
2664 search_frame = main_frame;
2665
[email protected]dd7daa82009-08-10 05:46:452666 main_frame->resetMatchCount();
initial.commit09911bf2008-07-26 23:55:292667
2668 do {
2669 // Cancel all old scoping requests before starting a new one.
[email protected]dd7daa82009-08-10 05:46:452670 search_frame->cancelPendingScopingEffort();
initial.commit09911bf2008-07-26 23:55:292671
2672 // We don't start another scoping effort unless at least one match has
2673 // been found.
2674 if (result) {
2675 // Start new scoping request. If the scoping function determines that it
2676 // needs to scope, it will defer until later.
[email protected]dd7daa82009-08-10 05:46:452677 search_frame->scopeStringMatches(request_id,
[email protected]7ea066a2009-04-06 20:21:592678 search_text,
2679 options,
initial.commit09911bf2008-07-26 23:55:292680 true); // reset the tickmarks
2681 }
2682
2683 // Iterate to the next frame. The frame will not necessarily scope, for
2684 // example if it is not visible.
2685 search_frame = webview()->GetNextFrameAfter(search_frame, true);
2686 } while (search_frame != main_frame);
2687 }
2688}
2689
[email protected]5c4266922009-07-10 16:41:272690void RenderView::OnDeterminePageText() {
2691 if (!is_loading_) {
2692 if (!webview())
2693 return;
2694 WebFrame* main_frame = webview()->GetMainFrame();
2695 std::wstring contents;
2696 CaptureText(main_frame, &contents);
2697 Send(new ViewMsg_DeterminePageText_Reply(routing_id_, contents));
2698 determine_page_text_after_loading_stops_ = false;
2699 return;
2700 }
2701
2702 // We set |determine_page_text_after_loading_stops_| true here so that,
2703 // after page has been loaded completely, the text in the page is captured.
2704 determine_page_text_after_loading_stops_ = true;
2705}
2706
initial.commit09911bf2008-07-26 23:55:292707void RenderView::ReportFindInPageMatchCount(int count, int request_id,
2708 bool final_update) {
2709 // If we have a message that has been queued up, then we should just replace
2710 // it. The ACK from the browser will make sure it gets sent when the browser
2711 // wants it.
2712 if (queued_find_reply_message_.get()) {
2713 IPC::Message* msg = new ViewHostMsg_Find_Reply(
2714 routing_id_,
2715 request_id,
2716 count,
[email protected]b3f2b912009-04-09 16:18:522717 gfx::Rect(),
initial.commit09911bf2008-07-26 23:55:292718 -1, // Don't update active match ordinal.
2719 final_update);
2720 queued_find_reply_message_.reset(msg);
2721 } else {
2722 // Send the search result over to the browser process.
2723 Send(new ViewHostMsg_Find_Reply(
2724 routing_id_,
2725 request_id,
2726 count,
[email protected]b3f2b912009-04-09 16:18:522727 gfx::Rect(),
initial.commit09911bf2008-07-26 23:55:292728 -1, // // Don't update active match ordinal.
2729 final_update));
2730 }
2731}
2732
2733void RenderView::ReportFindInPageSelection(int request_id,
2734 int active_match_ordinal,
[email protected]b3f2b912009-04-09 16:18:522735 const WebRect& selection_rect) {
initial.commit09911bf2008-07-26 23:55:292736 // Send the search result over to the browser process.
2737 Send(new ViewHostMsg_Find_Reply(routing_id_,
2738 request_id,
2739 -1,
2740 selection_rect,
2741 active_match_ordinal,
2742 false));
2743}
2744
[email protected]ed4bf2d2009-05-05 00:10:062745bool RenderView::WasOpenedByUserGesture() const {
initial.commit09911bf2008-07-26 23:55:292746 return opened_by_user_gesture_;
2747}
2748
initial.commit09911bf2008-07-26 23:55:292749void RenderView::DnsPrefetch(const std::vector<std::string>& host_names) {
2750 Send(new ViewHostMsg_DnsPrefetch(host_names));
2751}
2752
[email protected]630e26b2008-10-14 22:55:172753void RenderView::OnZoom(int function) {
2754 static const bool kZoomIsTextOnly = false;
2755 switch (function) {
2756 case PageZoom::SMALLER:
2757 webview()->ZoomOut(kZoomIsTextOnly);
initial.commit09911bf2008-07-26 23:55:292758 break;
[email protected]630e26b2008-10-14 22:55:172759 case PageZoom::STANDARD:
2760 webview()->ResetZoom();
initial.commit09911bf2008-07-26 23:55:292761 break;
[email protected]630e26b2008-10-14 22:55:172762 case PageZoom::LARGER:
2763 webview()->ZoomIn(kZoomIsTextOnly);
initial.commit09911bf2008-07-26 23:55:292764 break;
2765 default:
2766 NOTREACHED();
2767 }
2768}
2769
[email protected]41fc0322009-09-04 22:23:402770void RenderView::OnSetPageEncoding(const std::string& encoding_name) {
initial.commit09911bf2008-07-26 23:55:292771 webview()->SetPageEncoding(encoding_name);
2772}
2773
[email protected]a697f4c2009-09-14 22:30:182774void RenderView::OnResetPageEncodingToDefault() {
2775 std::string no_encoding;
2776 webview()->SetPageEncoding(no_encoding);
2777}
2778
[email protected]0df30122009-06-03 12:13:082779void RenderView::UpdateInspectorSettings(const std::wstring& raw_settings) {
2780 Send(new ViewHostMsg_UpdateInspectorSettings(routing_id_, raw_settings));
2781}
2782
[email protected]611cad42009-03-16 18:51:342783WebDevToolsAgentDelegate* RenderView::GetWebDevToolsAgentDelegate() {
[email protected]b75b7d072009-04-06 13:47:002784 return devtools_agent_.get();
[email protected]611cad42009-03-16 18:51:342785}
2786
[email protected]dd7daa82009-08-10 05:46:452787WebFrame* RenderView::GetChildFrame(const std::wstring& xpath) const {
2788 if (xpath.empty())
2789 return webview()->GetMainFrame();
2790
2791 // xpath string can represent a frame deep down the tree (across multiple
2792 // frame DOMs).
2793 // Example, /html/body/table/tbody/tr/td/iframe\n/frameset/frame[0]
2794 // should break into 2 xpaths
2795 // /html/body/table/tbody/tr/td/iframe & /frameset/frame[0]
2796
2797 WebFrame* frame = webview()->GetMainFrame();
2798
2799 std::wstring xpath_remaining = xpath;
2800 while (!xpath_remaining.empty()) {
2801 std::wstring::size_type delim_pos = xpath_remaining.find_first_of(L'\n');
2802 std::wstring xpath_child;
2803 if (delim_pos != std::wstring::npos) {
2804 xpath_child = xpath_remaining.substr(0, delim_pos);
2805 xpath_remaining.erase(0, delim_pos + 1);
2806 } else {
2807 xpath_remaining.swap(xpath_child);
2808 }
2809 frame = frame->findChildByExpression(WideToUTF16Hack(xpath_child));
initial.commit09911bf2008-07-26 23:55:292810 }
2811
[email protected]dd7daa82009-08-10 05:46:452812 return frame;
initial.commit09911bf2008-07-26 23:55:292813}
2814
[email protected]f29acf52008-11-03 20:08:332815void RenderView::EvaluateScript(const std::wstring& frame_xpath,
2816 const std::wstring& script) {
initial.commit09911bf2008-07-26 23:55:292817 WebFrame* web_frame = GetChildFrame(frame_xpath);
2818 if (!web_frame)
2819 return;
2820
[email protected]dd7daa82009-08-10 05:46:452821 web_frame->executeScript(WebScriptSource(WideToUTF16Hack(script)));
initial.commit09911bf2008-07-26 23:55:292822}
2823
[email protected]1810e132009-03-24 23:35:482824void RenderView::InsertCSS(const std::wstring& frame_xpath,
[email protected]ffaef0c2009-09-15 17:08:082825 const std::string& css,
2826 const std::string& id) {
[email protected]1810e132009-03-24 23:35:482827 WebFrame* web_frame = GetChildFrame(frame_xpath);
2828 if (!web_frame)
2829 return;
2830
[email protected]ffaef0c2009-09-15 17:08:082831 web_frame->insertStyleText(WebString::fromUTF8(css), WebString::fromUTF8(id));
[email protected]1810e132009-03-24 23:35:482832}
2833
initial.commit09911bf2008-07-26 23:55:292834void RenderView::OnScriptEvalRequest(const std::wstring& frame_xpath,
2835 const std::wstring& jscript) {
[email protected]f29acf52008-11-03 20:08:332836 EvaluateScript(frame_xpath, jscript);
initial.commit09911bf2008-07-26 23:55:292837}
2838
[email protected]1810e132009-03-24 23:35:482839void RenderView::OnCSSInsertRequest(const std::wstring& frame_xpath,
[email protected]ffaef0c2009-09-15 17:08:082840 const std::string& css,
2841 const std::string& id) {
2842 InsertCSS(frame_xpath, css, id);
[email protected]ae461542009-06-19 19:03:412843
2844 // Notify RenderViewHost that css has been inserted into the frame.
2845 Send(new ViewHostMsg_OnCSSInserted(routing_id_));
[email protected]1810e132009-03-24 23:35:482846}
2847
[email protected]7ea066a2009-04-06 20:21:592848void RenderView::OnAddMessageToConsole(
2849 const string16& frame_xpath,
2850 const string16& message,
2851 const WebConsoleMessage::Level& level) {
2852 WebFrame* web_frame = GetChildFrame(UTF16ToWideHack(frame_xpath));
[email protected]0dea3ea2009-03-31 23:30:592853 if (web_frame)
[email protected]dd7daa82009-08-10 05:46:452854 web_frame->addMessageToConsole(WebConsoleMessage(level, message));
initial.commit09911bf2008-07-26 23:55:292855}
2856
[email protected]81e63782009-02-27 19:35:092857void RenderView::OnAllowBindings(int enabled_bindings_flags) {
2858 enabled_bindings_ |= enabled_bindings_flags;
initial.commit09911bf2008-07-26 23:55:292859}
2860
2861void RenderView::OnSetDOMUIProperty(const std::string& name,
2862 const std::string& value) {
[email protected]81e63782009-02-27 19:35:092863 DCHECK(BindingsPolicy::is_dom_ui_enabled(enabled_bindings_));
initial.commit09911bf2008-07-26 23:55:292864 dom_ui_bindings_.SetProperty(name, value);
2865}
2866
2867void RenderView::OnReservePageIDRange(int size_of_range) {
2868 next_page_id_ += size_of_range + 1;
2869}
2870
[email protected]e80c73b2009-04-07 23:24:582871void RenderView::OnDragSourceEndedOrMoved(const gfx::Point& client_point,
2872 const gfx::Point& screen_point,
[email protected]1d9f4132009-09-08 17:29:252873 bool ended,
2874 WebDragOperation op) {
[email protected]5f9ae6c2009-07-08 02:38:032875 if (ended) {
[email protected]1d9f4132009-09-08 17:29:252876 webview()->DragSourceEndedAt(client_point, screen_point, op);
[email protected]5f9ae6c2009-07-08 02:38:032877 } else {
[email protected]e80c73b2009-04-07 23:24:582878 webview()->DragSourceMovedTo(client_point, screen_point);
[email protected]5f9ae6c2009-07-08 02:38:032879 }
initial.commit09911bf2008-07-26 23:55:292880}
2881
2882void RenderView::OnDragSourceSystemDragEnded() {
2883 webview()->DragSourceSystemDragEnded();
2884}
2885
2886void RenderView::OnUploadFileRequest(const ViewMsg_UploadFile_Params& p) {
2887 webkit_glue::FileUploadData* f = new webkit_glue::FileUploadData;
2888 f->file_path = p.file_path;
2889 f->form_name = p.form;
2890 f->file_name = p.file;
2891 f->submit_name = p.submit;
2892
2893 // Build the other form values map.
2894 if (!p.other_values.empty()) {
2895 std::vector<std::wstring> e;
2896 std::vector<std::wstring> kvp;
2897 std::vector<std::wstring>::iterator i;
2898
2899 SplitString(p.other_values, L'\n', &e);
2900 for (i = e.begin(); i != e.end(); ++i) {
2901 SplitString(*i, L'=', &kvp);
2902 if (kvp.size() == 2)
2903 f->other_form_values[kvp[0]] = kvp[1];
2904 kvp.clear();
2905 }
2906 }
2907
2908 pending_upload_data_.reset(f);
2909 ProcessPendingUpload();
2910}
2911
2912void RenderView::ProcessPendingUpload() {
2913 webkit_glue::FileUploadData* f = pending_upload_data_.get();
2914 if (f && webview() && webkit_glue::FillFormToUploadFile(webview(), *f))
2915 ResetPendingUpload();
2916}
2917
2918void RenderView::ResetPendingUpload() {
2919 pending_upload_data_.reset();
2920}
2921
2922void RenderView::OnFormFill(const FormData& form) {
2923 webkit_glue::FillForm(this->webview(), form);
2924}
2925
2926void RenderView::OnFillPasswordForm(
[email protected]daa8c58e2009-06-15 17:21:102927 const webkit_glue::PasswordFormDomManager::FillData& form_data) {
initial.commit09911bf2008-07-26 23:55:292928 webkit_glue::FillPasswordForm(this->webview(), form_data);
2929}
2930
2931void RenderView::OnDragTargetDragEnter(const WebDropData& drop_data,
[email protected]e80c73b2009-04-07 23:24:582932 const gfx::Point& client_point,
[email protected]1d9f4132009-09-08 17:29:252933 const gfx::Point& screen_point,
2934 WebDragOperationsMask ops) {
2935 WebDragOperation operation = webview()->DragTargetDragEnter(
[email protected]e80c73b2009-04-07 23:24:582936 drop_data.ToDragData(),
2937 drop_data.identity,
2938 client_point,
[email protected]1d9f4132009-09-08 17:29:252939 screen_point,
2940 ops);
initial.commit09911bf2008-07-26 23:55:292941
[email protected]1d9f4132009-09-08 17:29:252942 Send(new ViewHostMsg_UpdateDragCursor(routing_id_, operation));
initial.commit09911bf2008-07-26 23:55:292943}
2944
[email protected]e80c73b2009-04-07 23:24:582945void RenderView::OnDragTargetDragOver(const gfx::Point& client_point,
[email protected]1d9f4132009-09-08 17:29:252946 const gfx::Point& screen_point,
2947 WebDragOperationsMask ops) {
2948 WebDragOperation operation = webview()->DragTargetDragOver(
2949 client_point,
2950 screen_point,
2951 ops);
initial.commit09911bf2008-07-26 23:55:292952
[email protected]1d9f4132009-09-08 17:29:252953 Send(new ViewHostMsg_UpdateDragCursor(routing_id_, operation));
initial.commit09911bf2008-07-26 23:55:292954}
2955
2956void RenderView::OnDragTargetDragLeave() {
2957 webview()->DragTargetDragLeave();
2958}
2959
[email protected]e80c73b2009-04-07 23:24:582960void RenderView::OnDragTargetDrop(const gfx::Point& client_point,
2961 const gfx::Point& screen_point) {
2962 webview()->DragTargetDrop(client_point, screen_point);
initial.commit09911bf2008-07-26 23:55:292963}
2964
2965void RenderView::OnUpdateWebPreferences(const WebPreferences& prefs) {
[email protected]2fab253a2009-08-17 23:00:592966 webkit_preferences_ = prefs;
2967 webkit_preferences_.Apply(webview());
initial.commit09911bf2008-07-26 23:55:292968}
2969
2970void RenderView::OnSetAltErrorPageURL(const GURL& url) {
2971 alternate_error_page_url_ = url;
2972}
2973
initial.commit09911bf2008-07-26 23:55:292974void RenderView::OnInstallMissingPlugin() {
2975 // This could happen when the first default plugin is deleted.
[email protected]f103ab72009-09-02 17:10:592976 if (first_default_plugin_)
2977 first_default_plugin_->InstallMissingPlugin();
initial.commit09911bf2008-07-26 23:55:292978}
2979
[email protected]b62d1a8c2009-01-13 23:54:572980void RenderView::OnFileChooserResponse(
[email protected]561abe62009-04-06 18:08:342981 const std::vector<FilePath>& file_names) {
[email protected]8029f5672009-03-20 22:33:362982 // This could happen if we navigated to a different page before the user
2983 // closed the chooser.
2984 if (!file_chooser_.get())
2985 return;
2986
[email protected]b62d1a8c2009-01-13 23:54:572987 file_chooser_->OnFileChoose(file_names);
initial.commit09911bf2008-07-26 23:55:292988 file_chooser_.reset();
2989}
2990
2991void RenderView::OnEnableViewSourceMode() {
2992 if (!webview())
2993 return;
2994 WebFrame* main_frame = webview()->GetMainFrame();
2995 if (!main_frame)
2996 return;
2997
[email protected]dd7daa82009-08-10 05:46:452998 main_frame->enableViewSourceMode(true);
initial.commit09911bf2008-07-26 23:55:292999}
3000
[email protected]0666aef2009-05-13 19:48:083001void RenderView::OnEnableIntrinsicWidthChangedMode() {
3002 send_preferred_width_changes_ = true;
3003}
3004
[email protected]80d96fa2009-06-10 22:34:513005void RenderView::OnSetRendererPrefs(const RendererPreferences& renderer_prefs) {
3006 renderer_preferences_ = renderer_prefs;
[email protected]6e282c92009-07-24 01:19:373007 UpdateFontRenderingFromRendererPrefs();
[email protected]7a74e102009-09-03 00:16:563008#if defined(OS_LINUX)
[email protected]1c83eb42009-09-11 21:08:413009 WebColorName name = WebKit::WebColorWebkitFocusRingColor;
3010 WebKit::setNamedColors(&name, &renderer_prefs.focus_ring_color, 1);
[email protected]7a74e102009-09-03 00:16:563011#endif
[email protected]80d96fa2009-06-10 22:34:513012}
3013
[email protected]581b87eb2009-07-23 23:06:563014void RenderView::OnMediaPlayerActionAt(int x,
3015 int y,
3016 const MediaPlayerAction& action) {
3017 if (!webview())
3018 return;
3019
3020 webview()->MediaPlayerActionAt(x, y, action);
3021}
3022
[email protected]7b291f92009-08-14 05:43:533023void RenderView::OnNotifyRendererViewType(ViewType::Type type) {
[email protected]078b34612009-09-19 19:31:513024 // When this is first set, the bindings aren't fully loaded. We only need
3025 // to call through this API after the page has already been loaded. It's
3026 // also called in didCreateDocumentElement to bootstrap.
3027 if (view_type_ != ViewType::INVALID) {
3028 if (type == ViewType::EXTENSION_MOLE ||
3029 type == ViewType::EXTENSION_TOOLSTRIP) {
3030 ExtensionProcessBindings::SetViewType(webview(), type);
3031 }
3032 }
[email protected]7b291f92009-08-14 05:43:533033 view_type_ = type;
3034}
3035
3036void RenderView::OnUpdateBrowserWindowId(int window_id) {
3037 browser_window_id_ = window_id;
3038}
3039
initial.commit09911bf2008-07-26 23:55:293040void RenderView::OnUpdateBackForwardListCount(int back_list_count,
3041 int forward_list_count) {
3042 history_back_list_count_ = back_list_count;
3043 history_forward_list_count_ = forward_list_count;
3044}
3045
[email protected]266eb6f2008-09-30 23:56:503046void RenderView::OnGetAccessibilityInfo(
[email protected]6a983b42009-03-20 20:12:253047 const webkit_glue::WebAccessibility::InParams& in_params,
3048 webkit_glue::WebAccessibility::OutParams* out_params) {
[email protected]6c8afae52009-01-22 02:24:573049#if defined(OS_WIN)
[email protected]6a983b42009-03-20 20:12:253050 if (!web_accessibility_manager_.get()) {
3051 web_accessibility_manager_.reset(
3052 webkit_glue::WebAccessibilityManager::Create());
3053 }
[email protected]266eb6f2008-09-30 23:56:503054
[email protected]6a983b42009-03-20 20:12:253055 if (!web_accessibility_manager_->GetAccObjInfo(webview(), in_params,
3056 out_params)) {
[email protected]266eb6f2008-09-30 23:56:503057 return;
3058 }
[email protected]6c8afae52009-01-22 02:24:573059#else // defined(OS_WIN)
3060 // TODO(port): accessibility not yet implemented
3061 NOTIMPLEMENTED();
3062#endif
[email protected]266eb6f2008-09-30 23:56:503063}
3064
[email protected]6a983b42009-03-20 20:12:253065void RenderView::OnClearAccessibilityInfo(int acc_obj_id, bool clear_all) {
[email protected]6c8afae52009-01-22 02:24:573066#if defined(OS_WIN)
[email protected]6a983b42009-03-20 20:12:253067 if (!web_accessibility_manager_.get()) {
[email protected]266eb6f2008-09-30 23:56:503068 // If accessibility is not activated, ignore clearing message.
3069 return;
3070 }
[email protected]e846d0d2009-05-20 00:53:063071
[email protected]6a983b42009-03-20 20:12:253072 if (!web_accessibility_manager_->ClearAccObjMap(acc_obj_id, clear_all))
[email protected]266eb6f2008-09-30 23:56:503073 return;
[email protected]e846d0d2009-05-20 00:53:063074
[email protected]6c8afae52009-01-22 02:24:573075#else // defined(OS_WIN)
3076 // TODO(port): accessibility not yet implemented
3077 NOTIMPLEMENTED();
3078#endif
[email protected]266eb6f2008-09-30 23:56:503079}
3080
initial.commit09911bf2008-07-26 23:55:293081void RenderView::OnGetAllSavableResourceLinksForCurrentPage(
3082 const GURL& page_url) {
3083 // Prepare list to storage all savable resource links.
3084 std::vector<GURL> resources_list;
3085 std::vector<GURL> referrers_list;
3086 std::vector<GURL> frames_list;
3087 webkit_glue::SavableResourcesResult result(&resources_list,
3088 &referrers_list,
3089 &frames_list);
3090
3091 if (!webkit_glue::GetAllSavableResourceLinksForCurrentPage(webview(),
3092 page_url,
3093 &result)) {
3094 // If something is wrong when collecting all savable resource links,
3095 // send empty list to embedder(browser) to tell it failed.
3096 referrers_list.clear();
3097 resources_list.clear();
3098 frames_list.clear();
3099 }
3100
3101 // Send result of all savable resource links to embedder.
3102 Send(new ViewHostMsg_SendCurrentPageAllSavableResourceLinks(routing_id_,
3103 resources_list,
3104 referrers_list,
3105 frames_list));
3106}
3107
3108void RenderView::OnGetSerializedHtmlDataForCurrentPageWithLocalLinks(
[email protected]f6b48532009-02-12 01:56:323109 const std::vector<GURL>& links,
[email protected]fde6714d12009-02-18 22:39:313110 const std::vector<FilePath>& local_paths,
3111 const FilePath& local_directory_name) {
initial.commit09911bf2008-07-26 23:55:293112 webkit_glue::DomSerializer dom_serializer(webview()->GetMainFrame(),
3113 true,
3114 this,
3115 links,
3116 local_paths,
3117 local_directory_name);
3118 dom_serializer.SerializeDom();
3119}
3120
3121void RenderView::DidSerializeDataForFrame(const GURL& frame_url,
3122 const std::string& data, PageSavingSerializationStatus status) {
3123 Send(new ViewHostMsg_SendSerializedHtmlData(routing_id_,
3124 frame_url, data, static_cast<int32>(status)));
3125}
3126
[email protected]04b4a6c2008-08-02 00:44:473127void RenderView::OnMsgShouldClose() {
initial.commit09911bf2008-07-26 23:55:293128 bool should_close = webview()->ShouldClose();
[email protected]04b4a6c2008-08-02 00:44:473129 Send(new ViewHostMsg_ShouldClose_ACK(routing_id_, should_close));
initial.commit09911bf2008-07-26 23:55:293130}
3131
[email protected]eb6b87a2009-07-24 15:57:393132void RenderView::OnClosePage(const ViewMsg_ClosePage_Params& params) {
initial.commit09911bf2008-07-26 23:55:293133 // TODO(creis): We'd rather use webview()->Close() here, but that currently
3134 // sets the WebView's delegate_ to NULL, preventing any JavaScript dialogs
3135 // in the onunload handler from appearing. For now, we're bypassing that and
3136 // calling the FrameLoader's CloseURL method directly. This should be
3137 // revisited to avoid having two ways to close a page. Having a single way
3138 // to close that can run onunload is also useful for fixing
3139 // http://b/issue?id=753080.
3140 WebFrame* main_frame = webview()->GetMainFrame();
[email protected]7a9b51f2009-06-29 21:28:293141 if (main_frame) {
[email protected]dd7daa82009-08-10 05:46:453142 const GURL& url = main_frame->url();
[email protected]3d9689372009-09-10 04:29:173143 // TODO(davemoore) this code should be removed once willClose() gets
[email protected]7a9b51f2009-06-29 21:28:293144 // called when a page is destroyed. DumpLoadHistograms() is safe to call
3145 // multiple times for the same frame, but it will simplify things.
[email protected]dd7daa82009-08-10 05:46:453146 if (url.SchemeIs(chrome::kHttpScheme) ||
3147 url.SchemeIs(chrome::kHttpsScheme))
[email protected]7a9b51f2009-06-29 21:28:293148 DumpLoadHistograms();
[email protected]7a9b51f2009-06-29 21:28:293149 }
[email protected]e6fae1b2009-08-06 23:20:353150 webview()->ClosePage();
initial.commit09911bf2008-07-26 23:55:293151
[email protected]eb6b87a2009-07-24 15:57:393152 // Just echo back the params in the ACK.
3153 Send(new ViewHostMsg_ClosePage_ACK(routing_id_, params));
initial.commit09911bf2008-07-26 23:55:293154}
3155
3156void RenderView::OnThemeChanged() {
[email protected]6c8afae52009-01-22 02:24:573157#if defined(OS_WIN)
initial.commit09911bf2008-07-26 23:55:293158 gfx::NativeTheme::instance()->CloseHandles();
3159 gfx::Rect view_rect(0, 0, size_.width(), size_.height());
[email protected]4873c7d2009-07-16 06:36:283160 didInvalidateRect(view_rect);
[email protected]6c8afae52009-01-22 02:24:573161#else // defined(OS_WIN)
3162 // TODO(port): we don't support theming on non-Windows platforms yet
3163 NOTIMPLEMENTED();
3164#endif
initial.commit09911bf2008-07-26 23:55:293165}
3166
[email protected]28790922009-03-09 19:48:373167void RenderView::OnMessageFromExternalHost(const std::string& message,
3168 const std::string& origin,
3169 const std::string& target) {
[email protected]3ac14a052008-08-15 21:22:153170 if (message.empty())
3171 return;
3172
[email protected]28790922009-03-09 19:48:373173 external_host_bindings_.ForwardMessageFromExternalHost(message, origin,
3174 target);
[email protected]3ac14a052008-08-15 21:22:153175}
3176
[email protected]0aa55312008-10-17 21:53:083177void RenderView::OnDisassociateFromPopupCount() {
3178 if (decrement_shared_popup_at_destruction_)
3179 shared_popup_counter_->data--;
3180 shared_popup_counter_ = new SharedRenderViewCounter(0);
3181 decrement_shared_popup_at_destruction_ = false;
3182}
3183
[email protected]15d79e12009-08-02 19:23:453184bool RenderView::MaybeLoadAlternateErrorPage(WebFrame* frame,
3185 const WebURLError& error,
3186 bool replace) {
3187 // We only show alternate error pages in the main frame. They are
3188 // intended to assist the user when navigating, so there is not much
3189 // value in showing them for failed subframes. Ideally, we would be
3190 // able to use the TYPED transition type for this, but that flag is
3191 // not preserved across page reloads.
[email protected]dd7daa82009-08-10 05:46:453192 if (frame->parent())
[email protected]15d79e12009-08-02 19:23:453193 return false;
3194
3195 // Use the alternate error page service if this is a DNS failure or
[email protected]c53976d52009-08-07 18:58:373196 // connection failure.
[email protected]15d79e12009-08-02 19:23:453197 int ec = error.reason;
3198 if (ec != net::ERR_NAME_NOT_RESOLVED &&
3199 ec != net::ERR_CONNECTION_FAILED &&
3200 ec != net::ERR_CONNECTION_REFUSED &&
3201 ec != net::ERR_ADDRESS_UNREACHABLE &&
[email protected]c53976d52009-08-07 18:58:373202 ec != net::ERR_CONNECTION_TIMED_OUT)
[email protected]15d79e12009-08-02 19:23:453203 return false;
3204
3205 const GURL& error_page_url = GetAlternateErrorPageURL(error.unreachableURL,
[email protected]7ccddb8c2009-08-04 17:36:553206 ec == net::ERR_NAME_NOT_RESOLVED ? DNS_ERROR : CONNECTION_ERROR);
[email protected]15d79e12009-08-02 19:23:453207 if (!error_page_url.is_valid())
3208 return false;
3209
3210 // Load an empty page first so there is an immediate response to the error,
3211 // and then kick off a request for the alternate error page.
[email protected]dd7daa82009-08-10 05:46:453212 frame->loadHTMLString(std::string(),
[email protected]15d79e12009-08-02 19:23:453213 GURL(kUnreachableWebDataURL),
3214 error.unreachableURL,
3215 replace);
3216
3217 // Now, create a fetcher for the error page and associate it with the data
3218 // source we just created via the LoadHTMLString call. That way if another
3219 // navigation occurs, the fetcher will get destroyed.
3220 NavigationState* navigation_state =
[email protected]dd7daa82009-08-10 05:46:453221 NavigationState::FromDataSource(frame->provisionalDataSource());
[email protected]15d79e12009-08-02 19:23:453222 navigation_state->set_alt_error_page_fetcher(
3223 new AltErrorPageResourceFetcher(
3224 error_page_url, frame, error,
3225 NewCallback(this, &RenderView::AltErrorPageFinished)));
3226 return true;
3227}
3228
initial.commit09911bf2008-07-26 23:55:293229std::string RenderView::GetAltHTMLForTemplate(
3230 const DictionaryValue& error_strings, int template_resource_id) const {
[email protected]8a16266e2009-09-10 21:08:393231 const base::StringPiece template_html(
initial.commit09911bf2008-07-26 23:55:293232 ResourceBundle::GetSharedInstance().GetRawDataResource(
3233 template_resource_id));
3234
3235 if (template_html.empty()) {
3236 NOTREACHED() << "unable to load template. ID: " << template_resource_id;
3237 return "";
3238 }
[email protected]7cd22a52009-07-14 00:40:253239
initial.commit09911bf2008-07-26 23:55:293240 // "t" is the id of the templates root node.
[email protected]7cd22a52009-07-14 00:40:253241 return jstemplate_builder::GetTemplatesHtml(
initial.commit09911bf2008-07-26 23:55:293242 template_html, &error_strings, "t");
3243}
[email protected]0e79b9e2009-02-13 04:20:483244
[email protected]15d79e12009-08-02 19:23:453245void RenderView::AltErrorPageFinished(WebFrame* frame,
3246 const WebURLError& original_error,
3247 const std::string& html) {
3248 // Here, we replace the blank page we loaded previously.
[email protected]7ccddb8c2009-08-04 17:36:553249
3250 // If we failed to download the alternate error page, fall back to the
3251 // original error page if present. Otherwise, LoadNavigationErrorPage
3252 // will simply display a default error page.
3253 const std::string* html_to_load = &html;
3254 if (html.empty()) {
3255 NavigationState* navigation_state =
[email protected]dd7daa82009-08-10 05:46:453256 NavigationState::FromDataSource(frame->dataSource());
[email protected]7ccddb8c2009-08-04 17:36:553257 html_to_load = &navigation_state->postponed_data();
3258 }
3259 LoadNavigationErrorPage(
3260 frame, WebURLRequest(), original_error, *html_to_load, true);
[email protected]15d79e12009-08-02 19:23:453261}
3262
[email protected]30f75e62009-02-25 22:01:003263void RenderView::OnMoveOrResizeStarted() {
3264 if (webview())
3265 webview()->HideAutofillPopup();
3266}
3267
[email protected]30f75e62009-02-25 22:01:003268void RenderView::OnResize(const gfx::Size& new_size,
3269 const gfx::Rect& resizer_rect) {
3270 if (webview())
3271 webview()->HideAutofillPopup();
3272 RenderWidget::OnResize(new_size, resizer_rect);
3273}
[email protected]0aa477bd2009-03-23 22:21:433274
[email protected]05d478752009-04-08 23:38:163275void RenderView::OnClearFocusedNode() {
3276 if (webview())
3277 webview()->ClearFocusedNode();
3278}
3279
[email protected]699ab0d2009-04-23 23:19:143280void RenderView::OnSetBackground(const SkBitmap& background) {
3281 if (webview())
3282 webview()->SetIsTransparent(!background.empty());
3283
3284 SetBackground(background);
3285}
3286
[email protected]8c66c5a2009-07-22 17:26:343287void RenderView::OnSetActive(bool active) {
3288 if (webview())
3289 webview()->SetActive(active);
3290}
3291
[email protected]309d7a282009-03-24 09:18:273292void RenderView::SendExtensionRequest(const std::string& name,
3293 const std::string& args,
[email protected]c6619182009-05-12 14:59:323294 int request_id,
[email protected]2f25d7b92009-06-10 00:06:473295 bool has_callback) {
[email protected]c6619182009-05-12 14:59:323296 Send(new ViewHostMsg_ExtensionRequest(routing_id_, name, args, request_id,
[email protected]2f25d7b92009-06-10 00:06:473297 has_callback));
[email protected]309d7a282009-03-24 09:18:273298}
3299
[email protected]c6619182009-05-12 14:59:323300void RenderView::OnExtensionResponse(int request_id,
3301 bool success,
3302 const std::string& response,
3303 const std::string& error) {
[email protected]0f6053962009-07-09 19:26:353304 ExtensionProcessBindings::HandleResponse(
3305 request_id, success, response, error);
[email protected]309d7a282009-03-24 09:18:273306}
[email protected]c20210e62009-04-03 21:39:263307
[email protected]078b34612009-09-19 19:31:513308void RenderView::InjectToolstripCSS() {
3309 if (view_type_ != ViewType::EXTENSION_TOOLSTRIP)
3310 return;
3311
3312 static const base::StringPiece toolstrip_css(
3313 ResourceBundle::GetSharedInstance().GetRawDataResource(
3314 IDR_EXTENSION_TOOLSTRIP_CSS));
3315 std::string css = toolstrip_css.as_string();
3316 InsertCSS(L"", css, "ToolstripDefaultCSS");
3317}
3318
[email protected]7120f132009-07-20 21:05:373319void RenderView::OnExtensionMessageInvoke(const std::string& function_name,
3320 const ListValue& args) {
3321 RendererExtensionBindings::Invoke(function_name, args, this);
3322}
3323
[email protected]e7e4f3c2009-04-21 15:24:083324// Dump all load time histograms.
[email protected]c20210e62009-04-03 21:39:263325//
[email protected]7a9b51f2009-06-29 21:28:293326// There are 13 histograms measuring various times.
[email protected]c20210e62009-04-03 21:39:263327// The time points we keep are
3328// request: time document was requested by user
3329// start: time load of document started
[email protected]a2f6bc112009-06-27 16:27:253330// commit: time load of document started
[email protected]7a9b51f2009-06-29 21:28:293331// finish_document: main document loaded, before onload()
[email protected]c20210e62009-04-03 21:39:263332// finish: after onload() and all resources are loaded
[email protected]7a9b51f2009-06-29 21:28:293333// first_paint: first paint performed
3334// first_paint_after_load: first paint performed after load is finished
3335// begin: request if it was user requested, start otherwise
3336//
[email protected]c20210e62009-04-03 21:39:263337// The times that we histogram are
[email protected]a2f6bc112009-06-27 16:27:253338// request->start,
[email protected]7a9b51f2009-06-29 21:28:293339// start->commit,
3340// commit->finish_document,
3341// finish_document->finish,
3342// begin->commit,
3343// begin->finishDoc,
3344// begin->finish,
3345// begin->first_paint,
3346// begin->first_paint_after_load
3347// commit->finishDoc,
3348// commit->first_paint,
3349// commit->first_paint_after_load,
3350// finish->first_paint_after_load,
[email protected]c20210e62009-04-03 21:39:263351//
[email protected]e7e4f3c2009-04-21 15:24:083352// It's possible for the request time not to be set, if a client
3353// redirect had been done (the user never requested the page)
3354// Also, it's possible to load a page without ever laying it out
[email protected]7a9b51f2009-06-29 21:28:293355// so first_paint and first_paint_after_load can be 0.
[email protected]c20210e62009-04-03 21:39:263356void RenderView::DumpLoadHistograms() const {
3357 WebFrame* main_frame = webview()->GetMainFrame();
[email protected]ed3fb032009-06-16 19:50:563358 NavigationState* navigation_state =
[email protected]dd7daa82009-08-10 05:46:453359 NavigationState::FromDataSource(main_frame->dataSource());
[email protected]7a9b51f2009-06-29 21:28:293360 Time finish = navigation_state->finish_load_time();
[email protected]ed3fb032009-06-16 19:50:563361
[email protected]7a9b51f2009-06-29 21:28:293362 // If we've already dumped or we haven't finished loading, do nothing.
3363 if (navigation_state->load_histograms_recorded() || finish.is_null())
3364 return;
[email protected]ed3fb032009-06-16 19:50:563365
[email protected]7a9b51f2009-06-29 21:28:293366 Time request = navigation_state->request_time();
3367 Time start = navigation_state->start_load_time();
3368 Time commit = navigation_state->commit_load_time();
3369 Time finish_doc = navigation_state->finish_document_load_time();
3370 Time first_paint = navigation_state->first_paint_time();
3371 Time first_paint_after_load =
3372 navigation_state->first_paint_after_load_time();
[email protected]c20210e62009-04-03 21:39:263373
[email protected]7a9b51f2009-06-29 21:28:293374 Time begin;
3375 // Client side redirects will have no request time.
3376 if (request.is_null()) {
3377 begin = start;
3378 } else {
3379 begin = request;
3380 UMA_HISTOGRAM_MEDIUM_TIMES("Renderer4.RequestToStart", start - request);
[email protected]e7e4f3c2009-04-21 15:24:083381 }
[email protected]7a9b51f2009-06-29 21:28:293382 UMA_HISTOGRAM_MEDIUM_TIMES("Renderer4.StartToCommit", commit - start);
3383 UMA_HISTOGRAM_MEDIUM_TIMES(
3384 "Renderer4.CommitToFinishDoc", finish_doc - commit);
3385 UMA_HISTOGRAM_MEDIUM_TIMES(
3386 "Renderer4.FinishDocToFinish", finish - finish_doc);
3387
3388 UMA_HISTOGRAM_MEDIUM_TIMES("Renderer4.BeginToCommit", commit - begin);
3389 UMA_HISTOGRAM_MEDIUM_TIMES("Renderer4.BeginToFinishDoc", finish_doc - begin);
[email protected]e695fbd62009-06-30 16:31:543390
3391 static const TimeDelta kBeginToFinishMin(TimeDelta::FromMilliseconds(10));
3392 static const TimeDelta kBeginToFinishMax(TimeDelta::FromMinutes(10));
3393 static const size_t kBeginToFinishBucketCount(100);
3394
3395 UMA_HISTOGRAM_CUSTOM_TIMES("Renderer4.BeginToFinish",
3396 finish - begin, kBeginToFinishMin,
3397 kBeginToFinishMax, kBeginToFinishBucketCount);
[email protected]0a32257a2009-07-09 18:10:413398 UMA_HISTOGRAM_CUSTOM_TIMES("Renderer4.StartToFinish",
3399 finish - start, kBeginToFinishMin,
3400 kBeginToFinishMax, kBeginToFinishBucketCount);
3401 if (!request.is_null())
3402 UMA_HISTOGRAM_CUSTOM_TIMES("Renderer4.RequestToFinish",
3403 finish - request, kBeginToFinishMin,
3404 kBeginToFinishMax, kBeginToFinishBucketCount);
[email protected]e695fbd62009-06-30 16:31:543405
[email protected]36285b52009-06-30 19:10:003406 static bool use_dns_histogram(FieldTrialList::Find("DnsImpact") &&
3407 !FieldTrialList::Find("DnsImpact")->group_name().empty());
[email protected]0a32257a2009-07-09 18:10:413408 if (use_dns_histogram) {
[email protected]36285b52009-06-30 19:10:003409 UMA_HISTOGRAM_CUSTOM_TIMES(
3410 FieldTrial::MakeName("Renderer4.BeginToFinish", "DnsImpact").data(),
3411 finish - begin, kBeginToFinishMin,
3412 kBeginToFinishMax, kBeginToFinishBucketCount);
[email protected]0a32257a2009-07-09 18:10:413413 UMA_HISTOGRAM_CUSTOM_TIMES(
3414 FieldTrial::MakeName("Renderer4.StartToFinish", "DnsImpact").data(),
3415 finish - start, kBeginToFinishMin,
3416 kBeginToFinishMax, kBeginToFinishBucketCount);
3417 if (!request.is_null())
3418 UMA_HISTOGRAM_CUSTOM_TIMES(
3419 FieldTrial::MakeName("Renderer4.RequestToFinish", "DnsImpact").data(),
3420 finish - request, kBeginToFinishMin,
3421 kBeginToFinishMax, kBeginToFinishBucketCount);
3422 }
[email protected]e695fbd62009-06-30 16:31:543423
[email protected]36285b52009-06-30 19:10:003424 static bool use_sdch_histogram(FieldTrialList::Find("GlobalSdch") &&
3425 !FieldTrialList::Find("GlobalSdch")->group_name().empty());
[email protected]0a32257a2009-07-09 18:10:413426 if (use_sdch_histogram) {
[email protected]36285b52009-06-30 19:10:003427 UMA_HISTOGRAM_CUSTOM_TIMES(
3428 FieldTrial::MakeName("Renderer4.BeginToFinish", "GlobalSdch").data(),
3429 finish - begin, kBeginToFinishMin,
3430 kBeginToFinishMax, kBeginToFinishBucketCount);
[email protected]0a32257a2009-07-09 18:10:413431 UMA_HISTOGRAM_CUSTOM_TIMES(
3432 FieldTrial::MakeName("Renderer4.StartToFinish", "GlobalSdch").data(),
3433 finish - start, kBeginToFinishMin,
3434 kBeginToFinishMax, kBeginToFinishBucketCount);
3435 if (!request.is_null())
3436 UMA_HISTOGRAM_CUSTOM_TIMES(
3437 FieldTrial::MakeName("Renderer4.RequestToFinish",
3438 "GlobalSdch").data(),
3439 finish - request, kBeginToFinishMin,
3440 kBeginToFinishMax, kBeginToFinishBucketCount);
3441 }
[email protected]7a9b51f2009-06-29 21:28:293442
[email protected]5fff93f2009-08-02 04:27:343443 static bool use_socket_late_binding_histogram =
3444 FieldTrialList::Find("SocketLateBinding") &&
3445 !FieldTrialList::Find("SocketLateBinding")->group_name().empty();
3446 if (use_socket_late_binding_histogram) {
3447 UMA_HISTOGRAM_CUSTOM_TIMES(
3448 FieldTrial::MakeName("Renderer4.BeginToFinish",
3449 "SocketLateBinding").data(),
3450 finish - begin, kBeginToFinishMin,
3451 kBeginToFinishMax, kBeginToFinishBucketCount);
3452 UMA_HISTOGRAM_CUSTOM_TIMES(
3453 FieldTrial::MakeName("Renderer4.StartToFinish",
3454 "SocketLateBinding").data(),
3455 finish - start, kBeginToFinishMin,
3456 kBeginToFinishMax, kBeginToFinishBucketCount);
3457 if (!request.is_null())
3458 UMA_HISTOGRAM_CUSTOM_TIMES(
3459 FieldTrial::MakeName("Renderer4.RequestToFinish",
3460 "SocketLateBinding").data(),
3461 finish - request, kBeginToFinishMin,
3462 kBeginToFinishMax, kBeginToFinishBucketCount);
3463 }
3464
[email protected]7e05f6c42009-07-11 01:50:483465 static bool use_cache_histogram1(FieldTrialList::Find("CacheSize") &&
3466 !FieldTrialList::Find("CacheSize")->group_name().empty());
3467 if (use_cache_histogram1)
3468 UMA_HISTOGRAM_CUSTOM_TIMES(
3469 FieldTrial::MakeName("Renderer4.StartToFinish", "CacheSize").data(),
3470 finish - start, kBeginToFinishMin,
3471 kBeginToFinishMax, kBeginToFinishBucketCount);
3472
3473 static bool use_cache_histogram2(FieldTrialList::Find("NewEviction") &&
3474 !FieldTrialList::Find("NewEviction")->group_name().empty());
3475 if (use_cache_histogram2)
3476 UMA_HISTOGRAM_CUSTOM_TIMES(
3477 FieldTrial::MakeName("Renderer4.StartToFinish", "NewEviction").data(),
3478 finish - start, kBeginToFinishMin,
3479 kBeginToFinishMax, kBeginToFinishBucketCount);
3480
[email protected]7a9b51f2009-06-29 21:28:293481 UMA_HISTOGRAM_MEDIUM_TIMES("Renderer4.CommitToFinish", finish - commit);
3482
3483 if (!first_paint.is_null()) {
3484 UMA_HISTOGRAM_MEDIUM_TIMES(
3485 "Renderer4.BeginToFirstPaint", first_paint - begin);
3486 UMA_HISTOGRAM_MEDIUM_TIMES(
3487 "Renderer4.CommitToFirstPaint", first_paint - commit);
[email protected]c20210e62009-04-03 21:39:263488 }
[email protected]7a9b51f2009-06-29 21:28:293489
3490 if (!first_paint_after_load.is_null()) {
3491 UMA_HISTOGRAM_MEDIUM_TIMES(
3492 "Renderer4.BeginToFirstPaintAfterLoad", first_paint_after_load - begin);
3493 UMA_HISTOGRAM_MEDIUM_TIMES(
3494 "Renderer4.CommitToFirstPaintAfterLoad",
3495 first_paint_after_load - commit);
3496 UMA_HISTOGRAM_MEDIUM_TIMES(
3497 "Renderer4.FinishToFirstPaintAfterLoad",
3498 first_paint_after_load - finish);
3499 }
3500
3501 navigation_state->set_load_histograms_recorded(true);
[email protected]c20210e62009-04-03 21:39:263502}
[email protected]e846d0d2009-05-20 00:53:063503
3504void RenderView::FocusAccessibilityObject(
3505 WebCore::AccessibilityObject* acc_obj) {
3506#if defined(OS_WIN)
3507 if (!web_accessibility_manager_.get()) {
3508 web_accessibility_manager_.reset(
3509 webkit_glue::WebAccessibilityManager::Create());
3510 }
3511
3512 // Retrieve the accessibility object id of the AccessibilityObject.
3513 int acc_obj_id = web_accessibility_manager_->FocusAccObj(acc_obj);
3514
3515 // If id is valid, alert the browser side that an accessibility focus change
3516 // occurred.
3517 if (acc_obj_id >= 0)
3518 Send(new ViewHostMsg_AccessibilityFocusChange(routing_id_, acc_obj_id));
3519
3520#else // defined(OS_WIN)
3521 // TODO(port): accessibility not yet implemented
3522 NOTIMPLEMENTED();
3523#endif
3524}
[email protected]daa8c58e2009-06-15 17:21:103525
3526void RenderView::SendPasswordForms(WebFrame* frame) {
[email protected]dd7daa82009-08-10 05:46:453527 WebVector<WebForm> forms;
3528 frame->forms(forms);
[email protected]daa8c58e2009-06-15 17:21:103529
3530 std::vector<PasswordForm> password_forms;
3531 for (size_t i = 0; i < forms.size(); ++i) {
3532 const WebForm& form = forms[i];
3533
3534 // Respect autocomplete=off.
3535 if (form.isAutoCompleteEnabled()) {
3536 scoped_ptr<PasswordForm> password_form(
3537 PasswordFormDomManager::CreatePasswordForm(form));
3538 if (password_form.get())
3539 password_forms.push_back(*password_form);
3540 }
3541 }
3542
3543 if (!password_forms.empty())
3544 Send(new ViewHostMsg_PasswordFormsSeen(routing_id_, password_forms));
3545}
[email protected]0fda7272009-06-26 15:49:333546
3547void RenderView::Print(WebFrame* frame, bool script_initiated) {
3548 DCHECK(frame);
3549 if (print_helper_.get() == NULL) {
3550 print_helper_.reset(new PrintWebViewHelper(this));
3551 }
3552 print_helper_->Print(frame, script_initiated);
3553}
[email protected]446705872009-09-10 07:22:483554
3555void RenderView::OnSetEditCommandsForNextKeyEvent(
3556 const EditCommands& edit_commands) {
3557 edit_commands_ = edit_commands;
3558}
3559
[email protected]912256b32009-09-18 09:47:353560void RenderView::OnExecuteCode(int request_id, const std::string& extension_id,
3561 bool is_js_code,
3562 const std::string& code_string) {
3563 if (is_loading_) {
3564 scoped_refptr<CodeExecutionInfo> info = new CodeExecutionInfo(
3565 request_id, extension_id, is_js_code, code_string);
3566 pending_code_execution_queue_.push(info);
3567 return;
3568 }
3569 WebFrame* main_frame = webview() ? webview()->GetMainFrame() : NULL;
3570 if (!main_frame) {
3571 Send(new ViewMsg_ExecuteCodeFinished(routing_id_, request_id, false));
3572 return;
3573 }
3574
3575 if (is_js_code) {
3576 std::vector<WebScriptSource> sources;
3577 sources.push_back(
3578 WebScriptSource(WebString::fromUTF8(code_string)));
3579 UserScriptSlave::InsertInitExtensionCode(&sources, extension_id);
3580 main_frame->executeScriptInNewWorld(&sources.front(), sources.size(),
3581 EXTENSION_GROUP_CONTENT_SCRIPTS);
3582 } else {
3583 main_frame->insertStyleText(WebString::fromUTF8(code_string), WebString());
3584 }
3585
3586 Send(new ViewMsg_ExecuteCodeFinished(routing_id_, request_id, true));
3587}
3588
[email protected]446705872009-09-10 07:22:483589void RenderView::DidHandleKeyEvent() {
3590 edit_commands_.clear();
3591}
3592
[email protected]83dde542009-09-11 20:59:553593void RenderView::EnsureDocumentTag() {
3594 // TODO(darin): There's actually no reason for this to be here. We should
3595 // have the browser side manage the document tag.
3596#if defined(OS_MACOSX)
3597 if (!has_document_tag_) {
3598 // Make the call to get the tag.
3599 Send(new ViewHostMsg_GetDocumentTag(routing_id_, &document_tag_));
3600 has_document_tag_ = true;
3601 }
3602#endif
3603}
[email protected]12636df2009-09-28 22:32:213604
3605bool RenderView::SendAndRunNestedMessageLoop(IPC::SyncMessage* message) {
[email protected]8beff0762009-09-29 02:18:303606 PluginChannelHost::Broadcast(
3607 new PluginMsg_SignalModalDialogEvent(host_window_));
[email protected]12636df2009-09-28 22:32:213608
3609 message->EnableMessagePumping(); // Runs a nested message loop.
3610 bool rv = Send(message);
3611
[email protected]8beff0762009-09-29 02:18:303612 PluginChannelHost::Broadcast(
3613 new PluginMsg_ResetModalDialogEvent(host_window_));
[email protected]12636df2009-09-28 22:32:213614
3615 return rv;
3616}