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

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

Issue 6250176: Make RenderView not have to know about how PhishingClassifierDelegate. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 9 years, 10 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') | chrome/renderer/render_view_observer.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) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 <cmath> 8 #include <cmath>
9 #include <string> 9 #include <string>
10 #include <vector> 10 #include <vector>
(...skipping 569 matching lines...) Expand 10 before | Expand all | Expand 10 after
580 pending_app_icon_requests_(0), 580 pending_app_icon_requests_(0),
581 session_storage_namespace_id_(session_storage_namespace_id) { 581 session_storage_namespace_id_(session_storage_namespace_id) {
582 #if defined(OS_MACOSX) 582 #if defined(OS_MACOSX)
583 // On Mac, the select popups are rendered by the browser. 583 // On Mac, the select popups are rendered by the browser.
584 // Note that we don't do this in RenderMain otherwise this would not be called 584 // Note that we don't do this in RenderMain otherwise this would not be called
585 // in single-process mode. 585 // in single-process mode.
586 WebKit::WebView::setUseExternalPopupMenus(true); 586 WebKit::WebView::setUseExternalPopupMenus(true);
587 #endif 587 #endif
588 588
589 ClearBlockedContentSettings(); 589 ClearBlockedContentSettings();
590 if (CommandLine::ForCurrentProcess()->HasSwitch(
591 switches::kEnableClientSidePhishingDetection)) {
592 phishing_delegate_.reset(
593 new safe_browsing::PhishingClassifierDelegate(this, NULL));
594 RenderThread* thread = RenderThread::current();
595 if (thread && thread->phishing_scorer()) {
596 phishing_delegate_->SetPhishingScorer(thread->phishing_scorer());
597 }
598 }
599 590
600 routing_id_ = routing_id; 591 routing_id_ = routing_id;
601 if (opener_id != MSG_ROUTING_NONE) 592 if (opener_id != MSG_ROUTING_NONE)
602 opener_id_ = opener_id; 593 opener_id_ = opener_id;
603 594
604 if (counter) { 595 if (counter) {
605 shared_popup_counter_ = counter; 596 shared_popup_counter_ = counter;
606 shared_popup_counter_->data++; 597 shared_popup_counter_->data++;
607 decrement_shared_popup_at_destruction_ = true; 598 decrement_shared_popup_at_destruction_ = true;
608 } else { 599 } else {
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
650 audio_message_filter_ = new AudioMessageFilter(routing_id_); 641 audio_message_filter_ = new AudioMessageFilter(routing_id_);
651 render_thread_->AddFilter(audio_message_filter_); 642 render_thread_->AddFilter(audio_message_filter_);
652 643
653 PageClickTracker* page_click_tracker = new PageClickTracker(this); 644 PageClickTracker* page_click_tracker = new PageClickTracker(this);
654 // Note that the order of insertion of the listeners is important. 645 // Note that the order of insertion of the listeners is important.
655 // The password_autocomplete_manager takes the first shot at processing the 646 // The password_autocomplete_manager takes the first shot at processing the
656 // notification and can stop the propagation. 647 // notification and can stop the propagation.
657 page_click_tracker->AddListener(password_autofill_manager); 648 page_click_tracker->AddListener(password_autofill_manager);
658 page_click_tracker->AddListener(autofill_agent); 649 page_click_tracker->AddListener(autofill_agent);
659 new TranslateHelper(this); 650 new TranslateHelper(this);
651
652 if (CommandLine::ForCurrentProcess()->HasSwitch(
653 switches::kEnableClientSidePhishingDetection)) {
654 new safe_browsing::PhishingClassifierDelegate(this, NULL);
655 }
660 } 656 }
661 657
662 RenderView::~RenderView() { 658 RenderView::~RenderView() {
663 if (decrement_shared_popup_at_destruction_) 659 if (decrement_shared_popup_at_destruction_)
664 shared_popup_counter_->data--; 660 shared_popup_counter_->data--;
665 661
666 // If file chooser is still waiting for answer, dispatch empty answer. 662 // If file chooser is still waiting for answer, dispatch empty answer.
667 while (!file_chooser_completions_.empty()) { 663 while (!file_chooser_completions_.empty()) {
668 if (file_chooser_completions_.front()->completion) { 664 if (file_chooser_completions_.front()->completion) {
669 file_chooser_completions_.front()->completion->didChooseFile( 665 file_chooser_completions_.front()->completion->didChooseFile(
(...skipping 11 matching lines...) Expand all
681 while (!fake_plugin_window_handles_.empty()) { 677 while (!fake_plugin_window_handles_.empty()) {
682 // Make sure no NULL plugin window handles were inserted into this list. 678 // Make sure no NULL plugin window handles were inserted into this list.
683 DCHECK(*fake_plugin_window_handles_.begin()); 679 DCHECK(*fake_plugin_window_handles_.begin());
684 // DestroyFakePluginWindowHandle modifies fake_plugin_window_handles_. 680 // DestroyFakePluginWindowHandle modifies fake_plugin_window_handles_.
685 DestroyFakePluginWindowHandle(*fake_plugin_window_handles_.begin()); 681 DestroyFakePluginWindowHandle(*fake_plugin_window_handles_.begin());
686 } 682 }
687 #endif 683 #endif
688 684
689 render_thread_->RemoveFilter(audio_message_filter_); 685 render_thread_->RemoveFilter(audio_message_filter_);
690 686
691 // Tell the PhishingClassifierDelegate that the view is going away.
692 if (phishing_delegate_.get())
693 phishing_delegate_->CancelPendingClassification();
694
695 #ifndef NDEBUG 687 #ifndef NDEBUG
696 // Make sure we are no longer referenced by the ViewMap. 688 // Make sure we are no longer referenced by the ViewMap.
697 ViewMap* views = g_view_map.Pointer(); 689 ViewMap* views = g_view_map.Pointer();
698 for (ViewMap::iterator it = views->begin(); it != views->end(); ++it) 690 for (ViewMap::iterator it = views->begin(); it != views->end(); ++it)
699 DCHECK_NE(this, it->second) << "Failed to call Close?"; 691 DCHECK_NE(this, it->second) << "Failed to call Close?";
700 #endif 692 #endif
701 693
702 FOR_EACH_OBSERVER(RenderViewObserver, observers_, set_render_view(NULL)); 694 FOR_EACH_OBSERVER(RenderViewObserver, observers_, set_render_view(NULL));
703 FOR_EACH_OBSERVER(RenderViewObserver, observers_, OnDestruct()); 695 FOR_EACH_OBSERVER(RenderViewObserver, observers_, OnDestruct());
704 } 696 }
(...skipping 537 matching lines...) Expand 10 before | Expand all | Expand 10 after
1242 } 1234 }
1243 1235
1244 // Generate the thumbnail here if the in-browser thumbnailing isn't 1236 // Generate the thumbnail here if the in-browser thumbnailing isn't
1245 // enabled. TODO(satorux): Remove this and related code once 1237 // enabled. TODO(satorux): Remove this and related code once
1246 // crbug.com/65936 is complete. 1238 // crbug.com/65936 is complete.
1247 if (!CommandLine::ForCurrentProcess()->HasSwitch( 1239 if (!CommandLine::ForCurrentProcess()->HasSwitch(
1248 switches::kEnableInBrowserThumbnailing)) { 1240 switches::kEnableInBrowserThumbnailing)) {
1249 OnCaptureThumbnail(); 1241 OnCaptureThumbnail();
1250 } 1242 }
1251 1243
1252 if (phishing_delegate_.get()) 1244 FOR_EACH_OBSERVER(RenderViewObserver, observers_, PageCaptured(contents));
1253 phishing_delegate_->FinishedLoad(&contents);
1254 } 1245 }
1255 1246
1256 void RenderView::CaptureText(WebFrame* frame, string16* contents) { 1247 void RenderView::CaptureText(WebFrame* frame, string16* contents) {
1257 contents->clear(); 1248 contents->clear();
1258 if (!frame) 1249 if (!frame)
1259 return; 1250 return;
1260 1251
1261 #ifdef TIME_TEXT_RETRIEVAL 1252 #ifdef TIME_TEXT_RETRIEVAL
1262 double begin = time_util::GetHighResolutionTimeNow(); 1253 double begin = time_util::GetHighResolutionTimeNow();
1263 #endif 1254 #endif
(...skipping 1412 matching lines...) Expand 10 before | Expand all | Expand 10 after
2676 2667
2677 // NOTE: initial_pos_ may still have its default values at this point, but 2668 // NOTE: initial_pos_ may still have its default values at this point, but
2678 // that's okay. It'll be ignored if disposition is not NEW_POPUP, or the 2669 // that's okay. It'll be ignored if disposition is not NEW_POPUP, or the
2679 // browser process will impose a default position otherwise. 2670 // browser process will impose a default position otherwise.
2680 Send(new ViewHostMsg_ShowView(opener_id_, routing_id_, 2671 Send(new ViewHostMsg_ShowView(opener_id_, routing_id_,
2681 NavigationPolicyToDisposition(policy), initial_pos_, 2672 NavigationPolicyToDisposition(policy), initial_pos_,
2682 opened_by_user_gesture_)); 2673 opened_by_user_gesture_));
2683 SetPendingWindowRect(initial_pos_); 2674 SetPendingWindowRect(initial_pos_);
2684 } 2675 }
2685 2676
2686 void RenderView::closeWidgetSoon() {
2687 // Same for the phishing classifier.
2688 if (phishing_delegate_.get())
2689 phishing_delegate_->CancelPendingClassification();
2690
2691 if (script_can_close_)
2692 RenderWidget::closeWidgetSoon();
2693 }
2694
2695 void RenderView::runModal() { 2677 void RenderView::runModal() {
2696 DCHECK(did_show_) << "should already have shown the view"; 2678 DCHECK(did_show_) << "should already have shown the view";
2697 2679
2698 // We must keep WebKit's shared timer running in this case in order to allow 2680 // We must keep WebKit's shared timer running in this case in order to allow
2699 // showModalDialog to function properly. 2681 // showModalDialog to function properly.
2700 // 2682 //
2701 // TODO(darin): WebKit should really be smarter about suppressing events and 2683 // TODO(darin): WebKit should really be smarter about suppressing events and
2702 // timers so that we do not need to manage the shared timer in such a heavy 2684 // timers so that we do not need to manage the shared timer in such a heavy
2703 // handed manner. 2685 // handed manner.
2704 // 2686 //
(...skipping 580 matching lines...) Expand 10 before | Expand all | Expand 10 after
3285 NavigationGestureUser : NavigationGestureAuto; 3267 NavigationGestureUser : NavigationGestureAuto;
3286 3268
3287 // Make sure redirect tracking state is clear for the new load. 3269 // Make sure redirect tracking state is clear for the new load.
3288 completed_client_redirect_src_ = GURL(); 3270 completed_client_redirect_src_ = GURL();
3289 } else if (frame->parent()->isLoading()) { 3271 } else if (frame->parent()->isLoading()) {
3290 // Take note of AUTO_SUBFRAME loads here, so that we can know how to 3272 // Take note of AUTO_SUBFRAME loads here, so that we can know how to
3291 // load an error page. See didFailProvisionalLoad. 3273 // load an error page. See didFailProvisionalLoad.
3292 navigation_state->set_transition_type(PageTransition::AUTO_SUBFRAME); 3274 navigation_state->set_transition_type(PageTransition::AUTO_SUBFRAME);
3293 } 3275 }
3294 3276
3277 FOR_EACH_OBSERVER(
3278 RenderViewObserver, observers_, DidStartProvisionalLoad(frame));
3279
3295 Send(new ViewHostMsg_DidStartProvisionalLoadForFrame( 3280 Send(new ViewHostMsg_DidStartProvisionalLoadForFrame(
3296 routing_id_, frame->identifier(), is_top_most, ds->request().url())); 3281 routing_id_, frame->identifier(), is_top_most, ds->request().url()));
3297 } 3282 }
3298 3283
3299 void RenderView::didReceiveServerRedirectForProvisionalLoad(WebFrame* frame) { 3284 void RenderView::didReceiveServerRedirectForProvisionalLoad(WebFrame* frame) {
3300 if (frame->parent()) 3285 if (frame->parent())
3301 return; 3286 return;
3302 // Received a redirect on the main frame. 3287 // Received a redirect on the main frame.
3303 WebDataSource* data_source = frame->provisionalDataSource(); 3288 WebDataSource* data_source = frame->provisionalDataSource();
3304 if (!data_source) { 3289 if (!data_source) {
(...skipping 15 matching lines...) Expand all
3320 // 3305 //
3321 // Note: It is important this notification occur before DidStopLoading so the 3306 // Note: It is important this notification occur before DidStopLoading so the
3322 // SSL manager can react to the provisional load failure before being 3307 // SSL manager can react to the provisional load failure before being
3323 // notified the load stopped. 3308 // notified the load stopped.
3324 // 3309 //
3325 WebDataSource* ds = frame->provisionalDataSource(); 3310 WebDataSource* ds = frame->provisionalDataSource();
3326 DCHECK(ds); 3311 DCHECK(ds);
3327 3312
3328 const WebURLRequest& failed_request = ds->request(); 3313 const WebURLRequest& failed_request = ds->request();
3329 3314
3315 FOR_EACH_OBSERVER(
3316 RenderViewObserver, observers_, DidFailProvisionalLoad(frame, error));
3317
3330 bool show_repost_interstitial = 3318 bool show_repost_interstitial =
3331 (error.reason == net::ERR_CACHE_MISS && 3319 (error.reason == net::ERR_CACHE_MISS &&
3332 EqualsASCII(failed_request.httpMethod(), "POST")); 3320 EqualsASCII(failed_request.httpMethod(), "POST"));
3333 Send(new ViewHostMsg_DidFailProvisionalLoadWithError( 3321 Send(new ViewHostMsg_DidFailProvisionalLoadWithError(
3334 routing_id_, frame->identifier(), !frame->parent(), error.reason, 3322 routing_id_, frame->identifier(), !frame->parent(), error.reason,
3335 error.unreachableURL, show_repost_interstitial)); 3323 error.unreachableURL, show_repost_interstitial));
3336 3324
3337 // Don't display an error page if this is simply a cancelled load. Aside 3325 // Don't display an error page if this is simply a cancelled load. Aside
3338 // from being dumb, WebCore doesn't expect it and it will cause a crash. 3326 // from being dumb, WebCore doesn't expect it and it will cause a crash.
3339 if (error.reason == net::ERR_ABORTED) 3327 if (error.reason == net::ERR_ABORTED)
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
3405 3393
3406 navigation_state->set_commit_load_time(Time::Now()); 3394 navigation_state->set_commit_load_time(Time::Now());
3407 if (is_new_navigation) { 3395 if (is_new_navigation) {
3408 // When we perform a new navigation, we need to update the last committed 3396 // When we perform a new navigation, we need to update the last committed
3409 // session history entry with state for the page we are leaving. 3397 // session history entry with state for the page we are leaving.
3410 UpdateSessionHistory(frame); 3398 UpdateSessionHistory(frame);
3411 3399
3412 // We bump our Page ID to correspond with the new session history entry. 3400 // We bump our Page ID to correspond with the new session history entry.
3413 page_id_ = next_page_id_++; 3401 page_id_ = next_page_id_++;
3414 3402
3415 // Let the phishing classifier decide whether to cancel classification.
3416 if (phishing_delegate_.get())
3417 phishing_delegate_->CommittedLoadInFrame(frame);
3418
3419 // Advance our offset in session history, applying the length limit. There 3403 // Advance our offset in session history, applying the length limit. There
3420 // is now no forward history. 3404 // is now no forward history.
3421 history_list_offset_++; 3405 history_list_offset_++;
3422 if (history_list_offset_ >= chrome::kMaxSessionHistoryEntries) 3406 if (history_list_offset_ >= chrome::kMaxSessionHistoryEntries)
3423 history_list_offset_ = chrome::kMaxSessionHistoryEntries - 1; 3407 history_list_offset_ = chrome::kMaxSessionHistoryEntries - 1;
3424 history_list_length_ = history_list_offset_ + 1; 3408 history_list_length_ = history_list_offset_ + 1;
3425 3409
3426 MessageLoop::current()->PostDelayedTask( 3410 MessageLoop::current()->PostDelayedTask(
3427 FROM_HERE, 3411 FROM_HERE,
3428 page_info_method_factory_.NewRunnableMethod( 3412 page_info_method_factory_.NewRunnableMethod(
(...skipping 14 matching lines...) Expand all
3443 navigation_state->pending_page_id() != page_id_ && 3427 navigation_state->pending_page_id() != page_id_ &&
3444 !navigation_state->request_committed()) { 3428 !navigation_state->request_committed()) {
3445 // This is a successful session history navigation! 3429 // This is a successful session history navigation!
3446 UpdateSessionHistory(frame); 3430 UpdateSessionHistory(frame);
3447 page_id_ = navigation_state->pending_page_id(); 3431 page_id_ = navigation_state->pending_page_id();
3448 3432
3449 history_list_offset_ = navigation_state->pending_history_list_offset(); 3433 history_list_offset_ = navigation_state->pending_history_list_offset();
3450 } 3434 }
3451 } 3435 }
3452 3436
3437 FOR_EACH_OBSERVER(RenderViewObserver, observers_,
3438 DidCommitProvisionalLoad(frame, is_new_navigation));
3439
3453 // Remember that we've already processed this request, so we don't update 3440 // Remember that we've already processed this request, so we don't update
3454 // the session history again. We do this regardless of whether this is 3441 // the session history again. We do this regardless of whether this is
3455 // a session history navigation, because if we attempted a session history 3442 // a session history navigation, because if we attempted a session history
3456 // navigation without valid HistoryItem state, WebCore will think it is a 3443 // navigation without valid HistoryItem state, WebCore will think it is a
3457 // new navigation. 3444 // new navigation.
3458 navigation_state->set_request_committed(true); 3445 navigation_state->set_request_committed(true);
3459 3446
3460 UpdateURL(frame); 3447 UpdateURL(frame);
3461 3448
3462 // If this committed load was initiated by a client redirect, we're 3449 // If this committed load was initiated by a client redirect, we're
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
3517 } 3504 }
3518 3505
3519 void RenderView::didFinishDocumentLoad(WebFrame* frame) { 3506 void RenderView::didFinishDocumentLoad(WebFrame* frame) {
3520 WebDataSource* ds = frame->dataSource(); 3507 WebDataSource* ds = frame->dataSource();
3521 NavigationState* navigation_state = NavigationState::FromDataSource(ds); 3508 NavigationState* navigation_state = NavigationState::FromDataSource(ds);
3522 DCHECK(navigation_state); 3509 DCHECK(navigation_state);
3523 navigation_state->set_finish_document_load_time(Time::Now()); 3510 navigation_state->set_finish_document_load_time(Time::Now());
3524 3511
3525 Send(new ViewHostMsg_DocumentLoadedInFrame(routing_id_, frame->identifier())); 3512 Send(new ViewHostMsg_DocumentLoadedInFrame(routing_id_, frame->identifier()));
3526 3513
3527 FOR_EACH_OBSERVER( 3514 FOR_EACH_OBSERVER(RenderViewObserver, observers_,
3528 RenderViewObserver, observers_, DidFinishDocumentLoad(frame)); 3515 DidFinishDocumentLoad(frame));
3529 3516
3530 // Check whether we have new encoding name. 3517 // Check whether we have new encoding name.
3531 UpdateEncoding(frame, frame->view()->pageEncoding().utf8()); 3518 UpdateEncoding(frame, frame->view()->pageEncoding().utf8());
3532 3519
3533 if (RenderThread::current()) { // Will be NULL during unit tests. 3520 if (RenderThread::current()) { // Will be NULL during unit tests.
3534 RenderThread::current()->user_script_slave()->InjectScripts( 3521 RenderThread::current()->user_script_slave()->InjectScripts(
3535 frame, UserScript::DOCUMENT_END); 3522 frame, UserScript::DOCUMENT_END);
3536 } 3523 }
3537 3524
3538 // InjectScripts() can end up creating a new NavigationState if it triggers a 3525 // InjectScripts() can end up creating a new NavigationState if it triggers a
(...skipping 20 matching lines...) Expand all
3559 } 3546 }
3560 3547
3561 void RenderView::didHandleOnloadEvents(WebFrame* frame) { 3548 void RenderView::didHandleOnloadEvents(WebFrame* frame) {
3562 if (webview()->mainFrame() == frame) { 3549 if (webview()->mainFrame() == frame) {
3563 Send(new ViewHostMsg_DocumentOnLoadCompletedInMainFrame(routing_id_, 3550 Send(new ViewHostMsg_DocumentOnLoadCompletedInMainFrame(routing_id_,
3564 page_id_)); 3551 page_id_));
3565 } 3552 }
3566 } 3553 }
3567 3554
3568 void RenderView::didFailLoad(WebFrame* frame, const WebURLError& error) { 3555 void RenderView::didFailLoad(WebFrame* frame, const WebURLError& error) {
3569 // Ignore 3556 FOR_EACH_OBSERVER(RenderViewObserver, observers_, DidFailLoad(frame, error));
3570 } 3557 }
3571 3558
3572 void RenderView::didFinishLoad(WebFrame* frame) { 3559 void RenderView::didFinishLoad(WebFrame* frame) {
3573 WebDataSource* ds = frame->dataSource(); 3560 WebDataSource* ds = frame->dataSource();
3574 NavigationState* navigation_state = NavigationState::FromDataSource(ds); 3561 NavigationState* navigation_state = NavigationState::FromDataSource(ds);
3575 DCHECK(navigation_state); 3562 DCHECK(navigation_state);
3576 navigation_state->set_finish_load_time(Time::Now()); 3563 navigation_state->set_finish_load_time(Time::Now());
3577 navigation_state->user_script_idle_scheduler()->DidFinishLoad(); 3564 navigation_state->user_script_idle_scheduler()->DidFinishLoad();
3578 3565
3579 FOR_EACH_OBSERVER(RenderViewObserver, observers_, DidFinishLoad(frame)); 3566 FOR_EACH_OBSERVER(RenderViewObserver, observers_, DidFinishLoad(frame));
(...skipping 2202 matching lines...) Expand 10 before | Expand all | Expand 10 after
5782 } 5769 }
5783 } 5770 }
5784 5771
5785 void RenderView::OnContextMenuClosed( 5772 void RenderView::OnContextMenuClosed(
5786 const webkit_glue::CustomContextMenuContext& custom_context) { 5773 const webkit_glue::CustomContextMenuContext& custom_context) {
5787 if (custom_context.is_pepper_menu) 5774 if (custom_context.is_pepper_menu)
5788 pepper_delegate_.OnContextMenuClosed(custom_context); 5775 pepper_delegate_.OnContextMenuClosed(custom_context);
5789 else 5776 else
5790 context_menu_node_.reset(); 5777 context_menu_node_.reset();
5791 } 5778 }
OLDNEW
« no previous file with comments | « chrome/renderer/render_view.h ('k') | chrome/renderer/render_view_observer.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698