Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(51)

Side by Side Diff: chrome/renderer/render_view.cc

Issue 196128: Hook up WebViewClient, part 1.... (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: '' Created 11 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « chrome/renderer/render_view.h ('k') | webkit/api/public/WebViewClient.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/renderer/render_view.h" 5 #include "chrome/renderer/render_view.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <string> 8 #include <string>
9 #include <vector> 9 #include <vector>
10 10
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after
116 using WebKit::WebForm; 116 using WebKit::WebForm;
117 using WebKit::WebFrame; 117 using WebKit::WebFrame;
118 using WebKit::WebHistoryItem; 118 using WebKit::WebHistoryItem;
119 using WebKit::WebMediaPlayer; 119 using WebKit::WebMediaPlayer;
120 using WebKit::WebMediaPlayerClient; 120 using WebKit::WebMediaPlayerClient;
121 using WebKit::WebNavigationPolicy; 121 using WebKit::WebNavigationPolicy;
122 using WebKit::WebNavigationType; 122 using WebKit::WebNavigationType;
123 using WebKit::WebNode; 123 using WebKit::WebNode;
124 using WebKit::WebPlugin; 124 using WebKit::WebPlugin;
125 using WebKit::WebPluginParams; 125 using WebKit::WebPluginParams;
126 using WebKit::WebPoint;
126 using WebKit::WebPopupMenuInfo; 127 using WebKit::WebPopupMenuInfo;
127 using WebKit::WebRange; 128 using WebKit::WebRange;
128 using WebKit::WebRect; 129 using WebKit::WebRect;
129 using WebKit::WebScriptSource; 130 using WebKit::WebScriptSource;
130 using WebKit::WebSettings; 131 using WebKit::WebSettings;
131 using WebKit::WebSize; 132 using WebKit::WebSize;
132 using WebKit::WebString; 133 using WebKit::WebString;
133 using WebKit::WebTextAffinity; 134 using WebKit::WebTextAffinity;
134 using WebKit::WebTextDirection; 135 using WebKit::WebTextDirection;
135 using WebKit::WebURL; 136 using WebKit::WebURL;
(...skipping 958 matching lines...) Expand 10 before | Expand all | Expand 10 after
1094 Send(new ViewHostMsg_OpenURL( 1095 Send(new ViewHostMsg_OpenURL(
1095 routing_id_, url, referrer, NavigationPolicyToDisposition(policy))); 1096 routing_id_, url, referrer, NavigationPolicyToDisposition(policy)));
1096 } 1097 }
1097 1098
1098 // WebViewDelegate ------------------------------------------------------------ 1099 // WebViewDelegate ------------------------------------------------------------
1099 1100
1100 bool RenderView::CanAcceptLoadDrops() const { 1101 bool RenderView::CanAcceptLoadDrops() const {
1101 return renderer_preferences_.can_accept_load_drops; 1102 return renderer_preferences_.can_accept_load_drops;
1102 } 1103 }
1103 1104
1104 void RenderView::DidStartLoading(WebView* webview) {
1105 if (is_loading_) {
1106 DLOG(WARNING) << "DidStartLoading called while loading";
1107 return;
1108 }
1109
1110 is_loading_ = true;
1111 // Clear the pointer so that we can assign it only when there is an unknown
1112 // plugin on a page.
1113 first_default_plugin_.reset();
1114
1115 Send(new ViewHostMsg_DidStartLoading(routing_id_));
1116 }
1117
1118 void RenderView::DidStopLoading(WebView* webview) {
1119 if (!is_loading_) {
1120 DLOG(WARNING) << "DidStopLoading called while not loading";
1121 return;
1122 }
1123
1124 is_loading_ = false;
1125
1126 // NOTE: For now we're doing the safest thing, and sending out notification
1127 // when done loading. This currently isn't an issue as the favicon is only
1128 // displayed when done loading. Ideally we would send notification when
1129 // finished parsing the head, but webkit doesn't support that yet.
1130 // The feed discovery code would also benefit from access to the head.
1131 GURL favicon_url(webview->GetMainFrame()->favIconURL());
1132 if (!favicon_url.is_empty())
1133 Send(new ViewHostMsg_UpdateFavIconURL(routing_id_, page_id_, favicon_url));
1134
1135 AddGURLSearchProvider(webview->GetMainFrame()->openSearchDescriptionURL(),
1136 true); // autodetected
1137
1138 Send(new ViewHostMsg_DidStopLoading(routing_id_));
1139
1140 MessageLoop::current()->PostDelayedTask(FROM_HERE,
1141 method_factory_.NewRunnableMethod(&RenderView::CapturePageInfo, page_id_,
1142 false),
1143 kDelayForCaptureMs);
1144
1145 // The page is loaded. Try to process the file we need to upload if any.
1146 ProcessPendingUpload();
1147
1148 // Since the page is done loading, we are sure we don't need to try
1149 // again.
1150 ResetPendingUpload();
1151 }
1152
1153 void RenderView::DidPaint() { 1105 void RenderView::DidPaint() {
1154 WebFrame* main_frame = webview()->GetMainFrame(); 1106 WebFrame* main_frame = webview()->GetMainFrame();
1155 1107
1156 if (main_frame->provisionalDataSource()) { 1108 if (main_frame->provisionalDataSource()) {
1157 // If we have a provisional frame we are between the start 1109 // If we have a provisional frame we are between the start
1158 // and commit stages of loading...ignore this paint. 1110 // and commit stages of loading...ignore this paint.
1159 return; 1111 return;
1160 } 1112 }
1161 1113
1162 WebDataSource* ds = main_frame->dataSource(); 1114 WebDataSource* ds = main_frame->dataSource();
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
1220 } 1172 }
1221 1173
1222 void RenderView::DidDestroyScriptContextForFrame(WebFrame* webframe) { 1174 void RenderView::DidDestroyScriptContextForFrame(WebFrame* webframe) {
1223 EventBindings::HandleContextDestroyed(webframe); 1175 EventBindings::HandleContextDestroyed(webframe);
1224 } 1176 }
1225 1177
1226 void RenderView::DidCreateIsolatedScriptContext(WebFrame* webframe) { 1178 void RenderView::DidCreateIsolatedScriptContext(WebFrame* webframe) {
1227 EventBindings::HandleContextCreated(webframe, true); 1179 EventBindings::HandleContextCreated(webframe, true);
1228 } 1180 }
1229 1181
1230 void RenderView::RunJavaScriptAlert(WebFrame* webframe,
1231 const std::wstring& message) {
1232 RunJavaScriptMessage(MessageBoxFlags::kIsJavascriptAlert,
1233 message,
1234 std::wstring(),
1235 webframe->url(),
1236 NULL);
1237 }
1238
1239 bool RenderView::RunJavaScriptConfirm(WebFrame* webframe,
1240 const std::wstring& message) {
1241 return RunJavaScriptMessage(MessageBoxFlags::kIsJavascriptConfirm,
1242 message,
1243 std::wstring(),
1244 webframe->url(),
1245 NULL);
1246 }
1247
1248 bool RenderView::RunJavaScriptPrompt(WebFrame* webframe,
1249 const std::wstring& message,
1250 const std::wstring& default_value,
1251 std::wstring* result) {
1252 return RunJavaScriptMessage(MessageBoxFlags::kIsJavascriptPrompt,
1253 message,
1254 default_value,
1255 webframe->url(),
1256 result);
1257 }
1258
1259 bool RenderView::RunJavaScriptMessage(int type, 1182 bool RenderView::RunJavaScriptMessage(int type,
1260 const std::wstring& message, 1183 const std::wstring& message,
1261 const std::wstring& default_value, 1184 const std::wstring& default_value,
1262 const GURL& frame_url, 1185 const GURL& frame_url,
1263 std::wstring* result) { 1186 std::wstring* result) {
1264 bool success = false; 1187 bool success = false;
1265 std::wstring result_temp; 1188 std::wstring result_temp;
1266 if (!result) 1189 if (!result)
1267 result = &result_temp; 1190 result = &result_temp;
1268 IPC::SyncMessage* msg = new ViewHostMsg_RunJavaScriptMessage( 1191 IPC::SyncMessage* msg = new ViewHostMsg_RunJavaScriptMessage(
1269 routing_id_, message, default_value, frame_url, type, &success, result); 1192 routing_id_, message, default_value, frame_url, type, &success, result);
1270 1193
1271 msg->set_pump_messages_event(modal_dialog_event_.get()); 1194 msg->set_pump_messages_event(modal_dialog_event_.get());
1272 Send(msg); 1195 Send(msg);
1273 1196
1274 return success; 1197 return success;
1275 } 1198 }
1276 1199
1277 void RenderView::AddGURLSearchProvider(const GURL& osd_url, bool autodetected) { 1200 void RenderView::AddGURLSearchProvider(const GURL& osd_url, bool autodetected) {
1278 if (!osd_url.is_empty()) 1201 if (!osd_url.is_empty())
1279 Send(new ViewHostMsg_PageHasOSDD(routing_id_, page_id_, osd_url, 1202 Send(new ViewHostMsg_PageHasOSDD(routing_id_, page_id_, osd_url,
1280 autodetected)); 1203 autodetected));
1281 } 1204 }
1282 1205
1283 bool RenderView::RunBeforeUnloadConfirm(WebFrame* webframe,
1284 const std::wstring& message) {
1285 bool success = false;
1286 // This is an ignored return value, but is included so we can accept the same
1287 // response as RunJavaScriptMessage.
1288 std::wstring ignored_result;
1289 IPC::SyncMessage* msg = new ViewHostMsg_RunBeforeUnloadConfirm(
1290 routing_id_, webframe->url(), message, &success, &ignored_result);
1291
1292 msg->set_pump_messages_event(modal_dialog_event_.get());
1293 Send(msg);
1294
1295 return success;
1296 }
1297
1298 void RenderView::QueryFormFieldAutofill(const std::wstring& field_name, 1206 void RenderView::QueryFormFieldAutofill(const std::wstring& field_name,
1299 const std::wstring& text, 1207 const std::wstring& text,
1300 int64 node_id) { 1208 int64 node_id) {
1301 static int message_id_counter = 0; 1209 static int message_id_counter = 0;
1302 form_field_autofill_request_id_ = message_id_counter++; 1210 form_field_autofill_request_id_ = message_id_counter++;
1303 Send(new ViewHostMsg_QueryFormFieldAutofill(routing_id_, 1211 Send(new ViewHostMsg_QueryFormFieldAutofill(routing_id_,
1304 field_name, text, 1212 field_name, text,
1305 node_id, 1213 node_id,
1306 form_field_autofill_request_id_)); 1214 form_field_autofill_request_id_));
1307 } 1215 }
(...skipping 18 matching lines...) Expand all
1326 void RenderView::OnPopupNotificationVisibilityChanged(bool visible) { 1234 void RenderView::OnPopupNotificationVisibilityChanged(bool visible) {
1327 popup_notification_visible_ = visible; 1235 popup_notification_visible_ = visible;
1328 } 1236 }
1329 1237
1330 uint32 RenderView::GetCPBrowsingContext() { 1238 uint32 RenderView::GetCPBrowsingContext() {
1331 uint32 context = 0; 1239 uint32 context = 0;
1332 Send(new ViewHostMsg_GetCPBrowsingContext(&context)); 1240 Send(new ViewHostMsg_GetCPBrowsingContext(&context));
1333 return context; 1241 return context;
1334 } 1242 }
1335 1243
1336 // Tell the browser to display a destination link.
1337 void RenderView::UpdateTargetURL(WebView* webview, const GURL& url) {
1338 if (url != target_url_) {
1339 if (target_url_status_ == TARGET_INFLIGHT ||
1340 target_url_status_ == TARGET_PENDING) {
1341 // If we have a request in-flight, save the URL to be sent when we
1342 // receive an ACK to the in-flight request. We can happily overwrite
1343 // any existing pending sends.
1344 pending_target_url_ = url;
1345 target_url_status_ = TARGET_PENDING;
1346 } else {
1347 Send(new ViewHostMsg_UpdateTargetURL(routing_id_, page_id_, url));
1348 target_url_ = url;
1349 target_url_status_ = TARGET_INFLIGHT;
1350 }
1351 }
1352 }
1353
1354 void RenderView::RunFileChooser(bool multi_select, 1244 void RenderView::RunFileChooser(bool multi_select,
1355 const string16& title, 1245 const string16& title,
1356 const FilePath& default_filename, 1246 const FilePath& default_filename,
1357 WebFileChooserCallback* file_chooser) { 1247 WebFileChooserCallback* file_chooser) {
1358 if (file_chooser_.get()) { 1248 if (file_chooser_.get()) {
1359 // TODO(brettw): bug 1235154: This should be a synchronous message to deal 1249 // TODO(brettw): bug 1235154: This should be a synchronous message to deal
1360 // with the fact that web pages can programatically trigger this. With the 1250 // with the fact that web pages can programatically trigger this. With the
1361 // asnychronous messages, we can get an additional call when one is pending, 1251 // asnychronous messages, we can get an additional call when one is pending,
1362 // which this test is for. For now, we just ignore the additional file 1252 // which this test is for. For now, we just ignore the additional file
1363 // chooser request. WebKit doesn't do anything to expect the callback, so 1253 // chooser request. WebKit doesn't do anything to expect the callback, so
1364 // we can just ignore calling it. 1254 // we can just ignore calling it.
1365 delete file_chooser; 1255 delete file_chooser;
1366 return; 1256 return;
1367 } 1257 }
1368 file_chooser_.reset(file_chooser); 1258 file_chooser_.reset(file_chooser);
1369 Send(new ViewHostMsg_RunFileChooser(routing_id_, multi_select, title, 1259 Send(new ViewHostMsg_RunFileChooser(routing_id_, multi_select, title,
1370 default_filename)); 1260 default_filename));
1371 } 1261 }
1372 1262
1373 void RenderView::AddMessageToConsole(WebView* webview,
1374 const std::wstring& message,
1375 unsigned int line_no,
1376 const std::wstring& source_id) {
1377 Send(new ViewHostMsg_AddMessageToConsole(routing_id_, message,
1378 static_cast<int32>(line_no),
1379 source_id));
1380 }
1381
1382 void RenderView::AddSearchProvider(const std::string& url) { 1263 void RenderView::AddSearchProvider(const std::string& url) {
1383 AddGURLSearchProvider(GURL(url), 1264 AddGURLSearchProvider(GURL(url),
1384 false); // not autodetected 1265 false); // not autodetected
1385 } 1266 }
1386 1267
1387 WebView* RenderView::CreateWebView(WebView* webview, 1268 void RenderView::OnMissingPluginStatus(
1388 bool user_gesture, 1269 WebPluginDelegateProxy* delegate,
1389 const GURL& creator_url) { 1270 int status) {
1271 #if defined(OS_WIN)
1272 if (!first_default_plugin_) {
1273 // Show the InfoBar for the first available plugin.
1274 if (status == default_plugin::MISSING_PLUGIN_AVAILABLE) {
1275 first_default_plugin_ = delegate->AsWeakPtr();
1276 Send(new ViewHostMsg_MissingPluginStatus(routing_id_, status));
1277 }
1278 } else {
1279 // Closes the InfoBar if user clicks on the plugin (instead of the InfoBar)
1280 // to start the download/install.
1281 if (status == default_plugin::MISSING_PLUGIN_USER_STARTED_DOWNLOAD) {
1282 Send(new ViewHostMsg_MissingPluginStatus(routing_id_, status));
1283 }
1284 }
1285 #else
1286 // TODO(port): plugins current not supported
1287 NOTIMPLEMENTED();
1288 #endif
1289 }
1290
1291 // WebKit::WebViewClient ------------------------------------------------------
1292
1293 WebView* RenderView::createView(WebFrame* creator) {
1390 // Check to make sure we aren't overloading on popups. 1294 // Check to make sure we aren't overloading on popups.
1391 if (shared_popup_counter_->data > kMaximumNumberOfUnacknowledgedPopups) 1295 if (shared_popup_counter_->data > kMaximumNumberOfUnacknowledgedPopups)
1392 return NULL; 1296 return NULL;
1393 1297
1394 // This window can't be closed from a window.close() call until we receive a 1298 // This window can't be closed from a window.close() call until we receive a
1395 // message from the Browser process explicitly allowing it. 1299 // message from the Browser process explicitly allowing it.
1396 popup_notification_visible_ = true; 1300 popup_notification_visible_ = true;
1397 1301
1398 int32 routing_id = MSG_ROUTING_NONE; 1302 int32 routing_id = MSG_ROUTING_NONE;
1303 bool user_gesture = creator->isProcessingUserGesture();
1399 1304
1400 ModalDialogEvent modal_dialog_event; 1305 ModalDialogEvent modal_dialog_event;
1401 render_thread_->Send( 1306 render_thread_->Send(
1402 new ViewHostMsg_CreateWindow(routing_id_, user_gesture, &routing_id, 1307 new ViewHostMsg_CreateWindow(routing_id_, user_gesture, &routing_id,
1403 &modal_dialog_event)); 1308 &modal_dialog_event));
1404 if (routing_id == MSG_ROUTING_NONE) { 1309 if (routing_id == MSG_ROUTING_NONE) {
1405 return NULL; 1310 return NULL;
1406 } 1311 }
1407 1312
1408 // The WebView holds a reference to this new RenderView 1313 // The WebView holds a reference to this new RenderView
1409 base::WaitableEvent* waitable_event = new base::WaitableEvent 1314 base::WaitableEvent* waitable_event = new base::WaitableEvent(
1410 #if defined(OS_WIN) 1315 #if defined(OS_WIN)
1411 (modal_dialog_event.event); 1316 modal_dialog_event.event);
1412 #else 1317 #else
1413 (true, false); 1318 true, false);
1414 #endif 1319 #endif
1415 RenderView* view = RenderView::Create(render_thread_, 1320 RenderView* view = RenderView::Create(render_thread_,
1416 NULL, waitable_event, routing_id_, 1321 NULL, waitable_event, routing_id_,
1417 renderer_preferences_, 1322 renderer_preferences_,
1418 webkit_preferences_, 1323 webkit_preferences_,
1419 shared_popup_counter_, routing_id); 1324 shared_popup_counter_, routing_id);
1420 view->opened_by_user_gesture_ = user_gesture; 1325 view->opened_by_user_gesture_ = user_gesture;
1326
1327 // Record the security origin of the creator.
1328 GURL creator_url(creator->securityOrigin().utf8());
1329 if (!creator_url.is_valid() || !creator_url.IsStandard())
1330 creator_url = GURL();
1421 view->creator_url_ = creator_url; 1331 view->creator_url_ = creator_url;
1422 1332
1423 // Copy over the alternate error page URL so we can have alt error pages in 1333 // Copy over the alternate error page URL so we can have alt error pages in
1424 // the new render view (we don't need the browser to send the URL back down). 1334 // the new render view (we don't need the browser to send the URL back down).
1425 view->alternate_error_page_url_ = alternate_error_page_url_; 1335 view->alternate_error_page_url_ = alternate_error_page_url_;
1426 1336
1427 return view->webview(); 1337 return view->webview();
1428 } 1338 }
1429 1339
1430 WebWidget* RenderView::CreatePopupWidget(WebView* webview, 1340 WebWidget* RenderView::createPopupMenu(bool activatable) {
1431 bool activatable) {
1432 RenderWidget* widget = RenderWidget::Create(routing_id_, 1341 RenderWidget* widget = RenderWidget::Create(routing_id_,
1433 render_thread_, 1342 render_thread_,
1434 activatable); 1343 activatable);
1435 return widget->webwidget(); 1344 return widget->webwidget();
1436 } 1345 }
1437 1346
1438 WebWidget* RenderView::CreatePopupWidgetWithInfo(WebView* webview, 1347 WebWidget* RenderView::createPopupMenu(const WebPopupMenuInfo& info) {
1439 const WebPopupMenuInfo& info) {
1440 RenderWidget* widget = RenderWidget::Create(routing_id_, 1348 RenderWidget* widget = RenderWidget::Create(routing_id_,
1441 render_thread_, 1349 render_thread_,
1442 true); 1350 true);
1443 widget->ConfigureAsExternalPopupMenu(info); 1351 widget->ConfigureAsExternalPopupMenu(info);
1444 return widget->webwidget(); 1352 return widget->webwidget();
1445 } 1353 }
1446 1354
1447 void RenderView::OnMissingPluginStatus( 1355 void RenderView::didAddMessageToConsole(
1448 WebPluginDelegateProxy* delegate, 1356 const WebConsoleMessage& message, const WebString& source_name,
1449 int status) { 1357 unsigned source_line) {
1450 #if defined(OS_WIN) 1358 Send(new ViewHostMsg_AddMessageToConsole(routing_id_,
1451 if (!first_default_plugin_) { 1359 UTF16ToWideHack(message.text),
1452 // Show the InfoBar for the first available plugin. 1360 static_cast<int32>(source_line),
1453 if (status == default_plugin::MISSING_PLUGIN_AVAILABLE) { 1361 UTF16ToWideHack(source_name)));
1454 first_default_plugin_ = delegate->AsWeakPtr(); 1362 }
1455 Send(new ViewHostMsg_MissingPluginStatus(routing_id_, status)); 1363
1456 } 1364 void RenderView::printPage(WebFrame* frame) {
1365 DCHECK(webview());
1366 if (webview()) {
1367 // Print the full page - not just the frame the javascript is running from.
1368 Print(webview()->GetMainFrame(), true);
1369 }
1370 }
1371
1372 void 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
1386 void 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
1421 void RenderView::runModalAlertDialog(
1422 WebFrame* frame, const WebString& message) {
1423 RunJavaScriptMessage(MessageBoxFlags::kIsJavascriptAlert,
1424 UTF16ToWideHack(message),
1425 std::wstring(),
1426 frame->url(),
1427 NULL);
1428 }
1429
1430 bool RenderView::runModalConfirmDialog(
1431 WebFrame* frame, const WebString& message) {
1432 return RunJavaScriptMessage(MessageBoxFlags::kIsJavascriptConfirm,
1433 UTF16ToWideHack(message),
1434 std::wstring(),
1435 frame->url(),
1436 NULL);
1437 }
1438
1439 bool RenderView::runModalPromptDialog(
1440 WebFrame* frame, const WebString& message, const WebString& default_value,
1441 WebString* actual_value) {
1442 std::wstring result;
1443 bool ok = RunJavaScriptMessage(MessageBoxFlags::kIsJavascriptPrompt,
1444 UTF16ToWideHack(message),
1445 UTF16ToWideHack(default_value),
1446 frame->url(),
1447 &result);
1448 if (ok)
1449 actual_value->assign(WideToUTF16Hack(result));
1450 return ok;
1451 }
1452
1453 bool RenderView::runModalBeforeUnloadDialog(
1454 WebFrame* frame, const WebString& message) {
1455 bool success = false;
1456 // This is an ignored return value, but is included so we can accept the same
1457 // response as RunJavaScriptMessage.
1458 std::wstring ignored_result;
1459 IPC::SyncMessage* msg = new ViewHostMsg_RunBeforeUnloadConfirm(
1460 routing_id_, frame->url(), UTF16ToWideHack(message), &success,
1461 &ignored_result);
1462
1463 msg->set_pump_messages_event(modal_dialog_event_.get());
1464 Send(msg);
1465
1466 return success;
1467 }
1468
1469 void RenderView::setStatusText(const WebString& text) {
1470 }
1471
1472 void RenderView::setMouseOverURL(const WebURL& url) {
1473 GURL latest_url;
1474 if (latest_url == target_url_)
1475 return;
1476 // Tell the browser to display a destination link.
1477 if (target_url_status_ == TARGET_INFLIGHT ||
1478 target_url_status_ == TARGET_PENDING) {
1479 // If we have a request in-flight, save the URL to be sent when we
1480 // receive an ACK to the in-flight request. We can happily overwrite
1481 // any existing pending sends.
1482 pending_target_url_ = latest_url;
1483 target_url_status_ = TARGET_PENDING;
1457 } else { 1484 } else {
1458 // Closes the InfoBar if user clicks on the plugin (instead of the InfoBar) 1485 Send(new ViewHostMsg_UpdateTargetURL(routing_id_, page_id_, latest_url));
1459 // to start the download/install. 1486 target_url_ = latest_url;
1460 if (status == default_plugin::MISSING_PLUGIN_USER_STARTED_DOWNLOAD) { 1487 target_url_status_ = TARGET_INFLIGHT;
1461 Send(new ViewHostMsg_MissingPluginStatus(routing_id_, status));
1462 }
1463 } 1488 }
1464 #else 1489 }
1465 // TODO(port): plugins current not supported 1490
1466 NOTIMPLEMENTED(); 1491 void RenderView::setToolTipText(const WebString& text, WebTextDirection hint) {
1467 #endif 1492 Send(new ViewHostMsg_SetTooltipText(routing_id_, UTF16ToWideHack(text),
1493 hint));
1494 }
1495
1496 void RenderView::startDragging(const WebPoint& from, const WebDragData& data,
1497 WebDragOperationsMask allowed_ops) {
1498 Send(new ViewHostMsg_StartDragging(routing_id_,
1499 WebDropData(data),
1500 allowed_ops));
1501 }
1502
1503 void RenderView::focusNext() {
1504 Send(new ViewHostMsg_TakeFocus(routing_id_, false));
1505 }
1506
1507 void RenderView::focusPrevious() {
1508 Send(new ViewHostMsg_TakeFocus(routing_id_, true));
1509 }
1510
1511 void RenderView::navigateBackForwardSoon(int offset) {
1512 history_back_list_count_ += offset;
1513 history_forward_list_count_ -= offset;
1514
1515 Send(new ViewHostMsg_GoToEntryAtOffset(routing_id_, offset));
1516 }
1517
1518 int RenderView::historyBackListCount() {
1519 return history_back_list_count_;
1520 }
1521
1522 int RenderView::historyForwardListCount() {
1523 return history_forward_list_count_;
1524 }
1525
1526 void RenderView::didAddHistoryItem() {
1527 // We don't want to update the history length for the start page
1528 // navigation.
1529 WebFrame* main_frame = webview()->GetMainFrame();
1530 DCHECK(main_frame != NULL);
1531
1532 WebDataSource* ds = main_frame->dataSource();
1533 DCHECK(ds != NULL);
1534
1535 NavigationState* navigation_state = NavigationState::FromDataSource(ds);
1536 DCHECK(navigation_state);
1537 if (navigation_state->transition_type() == PageTransition::START_PAGE)
1538 return;
1539
1540 history_back_list_count_++;
1541 history_forward_list_count_ = 0;
1468 } 1542 }
1469 1543
1470 // WebKit::WebWidgetClient ---------------------------------------------------- 1544 // WebKit::WebWidgetClient ----------------------------------------------------
1471 1545
1472 // We are supposed to get a single call to Show for a newly created RenderView 1546 // We are supposed to get a single call to Show for a newly created RenderView
1473 // that was created via RenderView::CreateWebView. So, we wait until this 1547 // that was created via RenderView::CreateWebView. So, we wait until this
1474 // point to dispatch the ShowView message. 1548 // point to dispatch the ShowView message.
1475 // 1549 //
1476 // This method provides us with the information about how to display the newly 1550 // This method provides us with the information about how to display the newly
1477 // created RenderView (i.e., as a constrained popup or as a new tab). 1551 // created RenderView (i.e., as a constrained popup or as a new tab).
(...skipping 245 matching lines...) Expand 10 before | Expand all | Expand 10 after
1723 // 1797 //
1724 // We use the following heuristic to decide whether to fork a new page in its 1798 // We use the following heuristic to decide whether to fork a new page in its
1725 // own process: 1799 // own process:
1726 // The parent page must open a new tab to about:blank, set the new tab's 1800 // The parent page must open a new tab to about:blank, set the new tab's
1727 // window.opener to null, and then redirect the tab to a cross-site URL using 1801 // window.opener to null, and then redirect the tab to a cross-site URL using
1728 // JavaScript. 1802 // JavaScript.
1729 bool is_fork = 1803 bool is_fork =
1730 // Must start from a tab showing about:blank, which is later redirected. 1804 // Must start from a tab showing about:blank, which is later redirected.
1731 GURL(frame->url()) == GURL("about:blank") && 1805 GURL(frame->url()) == GURL("about:blank") &&
1732 // Must be the first real navigation of the tab. 1806 // Must be the first real navigation of the tab.
1733 GetHistoryBackListCount() < 1 && 1807 historyBackListCount() < 1 &&
1734 GetHistoryForwardListCount() < 1 && 1808 historyForwardListCount() < 1 &&
1735 // The parent page must have set the child's window.opener to null before 1809 // The parent page must have set the child's window.opener to null before
1736 // redirecting to the desired URL. 1810 // redirecting to the desired URL.
1737 frame->opener() == NULL && 1811 frame->opener() == NULL &&
1738 // Must be a top-level frame. 1812 // Must be a top-level frame.
1739 frame->parent() == NULL && 1813 frame->parent() == NULL &&
1740 // Must not have issued the request from this page. 1814 // Must not have issued the request from this page.
1741 is_content_initiated && 1815 is_content_initiated &&
1742 // Must be targeted at the current tab. 1816 // Must be targeted at the current tab.
1743 default_policy == WebKit::WebNavigationPolicyCurrentTab && 1817 default_policy == WebKit::WebNavigationPolicyCurrentTab &&
1744 // Must be a JavaScript navigation, which appears as "other". 1818 // Must be a JavaScript navigation, which appears as "other".
(...skipping 489 matching lines...) Expand 10 before | Expand all | Expand 10 after
2234 #endif 2308 #endif
2235 CleanupWindowInPluginMoves(window); 2309 CleanupWindowInPluginMoves(window);
2236 } 2310 }
2237 2311
2238 void RenderView::DidMovePlugin(const webkit_glue::WebPluginGeometry& move) { 2312 void RenderView::DidMovePlugin(const webkit_glue::WebPluginGeometry& move) {
2239 SchedulePluginMove(move); 2313 SchedulePluginMove(move);
2240 } 2314 }
2241 2315
2242 void RenderView::DidStartLoadingForPlugin() { 2316 void RenderView::DidStartLoadingForPlugin() {
2243 // TODO(darin): Make is_loading_ be a counter! 2317 // TODO(darin): Make is_loading_ be a counter!
2244 DidStartLoading(webview()); 2318 didStartLoading();
2245 } 2319 }
2246 2320
2247 void RenderView::DidStopLoadingForPlugin() { 2321 void RenderView::DidStopLoadingForPlugin() {
2248 // TODO(darin): Make is_loading_ be a counter! 2322 // TODO(darin): Make is_loading_ be a counter!
2249 DidStopLoading(webview()); 2323 didStopLoading();
2250 } 2324 }
2251 2325
2252 void RenderView::ShowModalHTMLDialogForPlugin( 2326 void RenderView::ShowModalHTMLDialogForPlugin(
2253 const GURL& url, 2327 const GURL& url,
2254 const gfx::Size& size, 2328 const gfx::Size& size,
2255 const std::string& json_arguments, 2329 const std::string& json_arguments,
2256 std::string* json_retval) { 2330 std::string* json_retval) {
2257 IPC::SyncMessage* msg = new ViewHostMsg_ShowModalHTMLDialog( 2331 IPC::SyncMessage* msg = new ViewHostMsg_ShowModalHTMLDialog(
2258 routing_id_, url, size.width(), size.height(), json_arguments, 2332 routing_id_, url, size.width(), size.height(), json_arguments,
2259 json_retval); 2333 json_retval);
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
2301 params.selection_text = selection_text; 2375 params.selection_text = selection_text;
2302 params.misspelled_word = misspelled_word; 2376 params.misspelled_word = misspelled_word;
2303 params.spellcheck_enabled = 2377 params.spellcheck_enabled =
2304 webview->GetFocusedFrame()->isContinuousSpellCheckingEnabled(); 2378 webview->GetFocusedFrame()->isContinuousSpellCheckingEnabled();
2305 params.edit_flags = edit_flags; 2379 params.edit_flags = edit_flags;
2306 params.security_info = security_info; 2380 params.security_info = security_info;
2307 params.frame_charset = frame_charset; 2381 params.frame_charset = frame_charset;
2308 Send(new ViewHostMsg_ContextMenu(routing_id_, params)); 2382 Send(new ViewHostMsg_ContextMenu(routing_id_, params));
2309 } 2383 }
2310 2384
2311 void RenderView::StartDragging(WebView* webview,
2312 const WebKit::WebPoint &mouseCoords,
2313 const WebDragData& drag_data,
2314 WebDragOperationsMask allowed_ops) {
2315 Send(new ViewHostMsg_StartDragging(routing_id_,
2316 WebDropData(drag_data),
2317 allowed_ops));
2318 }
2319
2320 void RenderView::TakeFocus(WebView* webview, bool reverse) {
2321 Send(new ViewHostMsg_TakeFocus(routing_id_, reverse));
2322 }
2323
2324 void RenderView::DidDownloadImage(int id, 2385 void RenderView::DidDownloadImage(int id,
2325 const GURL& image_url, 2386 const GURL& image_url,
2326 bool errored, 2387 bool errored,
2327 const SkBitmap& image) { 2388 const SkBitmap& image) {
2328 Send(new ViewHostMsg_DidDownloadFavIcon(routing_id_, id, image_url, errored, 2389 Send(new ViewHostMsg_DidDownloadFavIcon(routing_id_, id, image_url, errored,
2329 image)); 2390 image));
2330 } 2391 }
2331 2392
2332 void RenderView::OnDownloadFavIcon(int id, 2393 void RenderView::OnDownloadFavIcon(int id,
2333 const GURL& image_url, 2394 const GURL& image_url,
(...skipping 283 matching lines...) Expand 10 before | Expand all | Expand 10 after
2617 2678
2618 void RenderView::ShowSpellingUI(bool show) { 2679 void RenderView::ShowSpellingUI(bool show) {
2619 Send(new ViewHostMsg_ShowSpellingPanel(routing_id_, show)); 2680 Send(new ViewHostMsg_ShowSpellingPanel(routing_id_, show));
2620 } 2681 }
2621 2682
2622 void RenderView::UpdateSpellingUIWithMisspelledWord(const std::wstring& word) { 2683 void RenderView::UpdateSpellingUIWithMisspelledWord(const std::wstring& word) {
2623 Send(new ViewHostMsg_UpdateSpellingPanelWithMisspelledWord( 2684 Send(new ViewHostMsg_UpdateSpellingPanelWithMisspelledWord(
2624 routing_id_, word)); 2685 routing_id_, word));
2625 } 2686 }
2626 2687
2627 void RenderView::ScriptedPrint(WebFrame* frame) {
2628 DCHECK(webview());
2629 if (webview()) {
2630 // Print the full page - not just the frame the javascript is running from.
2631 Print(webview()->GetMainFrame(), true);
2632 }
2633 }
2634
2635 void RenderView::UserMetricsRecordAction(const std::wstring& action) { 2688 void RenderView::UserMetricsRecordAction(const std::wstring& action) {
2636 Send(new ViewHostMsg_UserMetricsRecordAction(routing_id_, action)); 2689 Send(new ViewHostMsg_UserMetricsRecordAction(routing_id_, action));
2637 } 2690 }
2638 2691
2639 void RenderView::DnsPrefetch(const std::vector<std::string>& host_names) { 2692 void RenderView::DnsPrefetch(const std::vector<std::string>& host_names) {
2640 Send(new ViewHostMsg_DnsPrefetch(host_names)); 2693 Send(new ViewHostMsg_DnsPrefetch(host_names));
2641 } 2694 }
2642 2695
2643 void RenderView::OnZoom(int function) { 2696 void RenderView::OnZoom(int function) {
2644 static const bool kZoomIsTextOnly = false; 2697 static const bool kZoomIsTextOnly = false;
(...skipping 14 matching lines...) Expand all
2659 2712
2660 void RenderView::OnSetPageEncoding(const std::string& encoding_name) { 2713 void RenderView::OnSetPageEncoding(const std::string& encoding_name) {
2661 webview()->SetPageEncoding(encoding_name); 2714 webview()->SetPageEncoding(encoding_name);
2662 } 2715 }
2663 2716
2664 void RenderView::OnResetPageEncodingToDefault() { 2717 void RenderView::OnResetPageEncodingToDefault() {
2665 std::string no_encoding; 2718 std::string no_encoding;
2666 webview()->SetPageEncoding(no_encoding); 2719 webview()->SetPageEncoding(no_encoding);
2667 } 2720 }
2668 2721
2669 void RenderView::NavigateBackForwardSoon(int offset) {
2670 history_back_list_count_ += offset;
2671 history_forward_list_count_ -= offset;
2672
2673 Send(new ViewHostMsg_GoToEntryAtOffset(routing_id_, offset));
2674 }
2675
2676 int RenderView::GetHistoryBackListCount() {
2677 return history_back_list_count_;
2678 }
2679
2680 int RenderView::GetHistoryForwardListCount() {
2681 return history_forward_list_count_;
2682 }
2683
2684 void RenderView::SetTooltipText(WebView* webview,
2685 const std::wstring& tooltip_text,
2686 WebTextDirection text_direction_hint) {
2687 Send(new ViewHostMsg_SetTooltipText(routing_id_, tooltip_text,
2688 text_direction_hint));
2689 }
2690
2691 void RenderView::UpdateInspectorSettings(const std::wstring& raw_settings) { 2722 void RenderView::UpdateInspectorSettings(const std::wstring& raw_settings) {
2692 Send(new ViewHostMsg_UpdateInspectorSettings(routing_id_, raw_settings)); 2723 Send(new ViewHostMsg_UpdateInspectorSettings(routing_id_, raw_settings));
2693 } 2724 }
2694 2725
2695 WebDevToolsAgentDelegate* RenderView::GetWebDevToolsAgentDelegate() { 2726 WebDevToolsAgentDelegate* RenderView::GetWebDevToolsAgentDelegate() {
2696 return devtools_agent_.get(); 2727 return devtools_agent_.get();
2697 } 2728 }
2698 2729
2699 WebFrame* RenderView::GetChildFrame(const std::wstring& xpath) const { 2730 WebFrame* RenderView::GetChildFrame(const std::wstring& xpath) const {
2700 if (xpath.empty()) 2731 if (xpath.empty())
(...skipping 359 matching lines...) Expand 10 before | Expand all | Expand 10 after
3060 #if defined(OS_WIN) 3091 #if defined(OS_WIN)
3061 gfx::NativeTheme::instance()->CloseHandles(); 3092 gfx::NativeTheme::instance()->CloseHandles();
3062 gfx::Rect view_rect(0, 0, size_.width(), size_.height()); 3093 gfx::Rect view_rect(0, 0, size_.width(), size_.height());
3063 didInvalidateRect(view_rect); 3094 didInvalidateRect(view_rect);
3064 #else // defined(OS_WIN) 3095 #else // defined(OS_WIN)
3065 // TODO(port): we don't support theming on non-Windows platforms yet 3096 // TODO(port): we don't support theming on non-Windows platforms yet
3066 NOTIMPLEMENTED(); 3097 NOTIMPLEMENTED();
3067 #endif 3098 #endif
3068 } 3099 }
3069 3100
3070 void RenderView::DidAddHistoryItem() {
3071 // We don't want to update the history length for the start page
3072 // navigation.
3073 WebFrame* main_frame = webview()->GetMainFrame();
3074 DCHECK(main_frame != NULL);
3075
3076 WebDataSource* ds = main_frame->dataSource();
3077 DCHECK(ds != NULL);
3078
3079 NavigationState* navigation_state = NavigationState::FromDataSource(ds);
3080 DCHECK(navigation_state);
3081 if (navigation_state->transition_type() == PageTransition::START_PAGE)
3082 return;
3083
3084 history_back_list_count_++;
3085 history_forward_list_count_ = 0;
3086 }
3087
3088 void RenderView::OnMessageFromExternalHost(const std::string& message, 3101 void RenderView::OnMessageFromExternalHost(const std::string& message,
3089 const std::string& origin, 3102 const std::string& origin,
3090 const std::string& target) { 3103 const std::string& target) {
3091 if (message.empty()) 3104 if (message.empty())
3092 return; 3105 return;
3093 3106
3094 external_host_bindings_.ForwardMessageFromExternalHost(message, origin, 3107 external_host_bindings_.ForwardMessageFromExternalHost(message, origin,
3095 target); 3108 target);
3096 } 3109 }
3097 3110
(...skipping 397 matching lines...) Expand 10 before | Expand all | Expand 10 after
3495 // TODO(darin): There's actually no reason for this to be here. We should 3508 // TODO(darin): There's actually no reason for this to be here. We should
3496 // have the browser side manage the document tag. 3509 // have the browser side manage the document tag.
3497 #if defined(OS_MACOSX) 3510 #if defined(OS_MACOSX)
3498 if (!has_document_tag_) { 3511 if (!has_document_tag_) {
3499 // Make the call to get the tag. 3512 // Make the call to get the tag.
3500 Send(new ViewHostMsg_GetDocumentTag(routing_id_, &document_tag_)); 3513 Send(new ViewHostMsg_GetDocumentTag(routing_id_, &document_tag_));
3501 has_document_tag_ = true; 3514 has_document_tag_ = true;
3502 } 3515 }
3503 #endif 3516 #endif
3504 } 3517 }
OLDNEW
« no previous file with comments | « chrome/renderer/render_view.h ('k') | webkit/api/public/WebViewClient.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698