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

Side by Side Diff: chrome/browser/password_manager/chrome_password_manager_client.cc

Issue 2947413002: Restrict CM API interface request and message dispatch. (Closed)
Patch Set: Reworked tests, added error handler in renderer. Created 3 years, 5 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
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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/browser/password_manager/chrome_password_manager_client.h" 5 #include "chrome/browser/password_manager/chrome_password_manager_client.h"
6 6
7 #include <string> 7 #include <string>
8 #include <utility> 8 #include <utility>
9 9
10 #include "base/bind.h" 10 #include "base/bind.h"
(...skipping 355 matching lines...) Expand 10 before | Expand all | Expand 10 after
366 possible_auto_sign_in_->origin == form.origin) { 366 possible_auto_sign_in_->origin == form.origin) {
367 PromptUserToEnableAutosigninIfNecessary(); 367 PromptUserToEnableAutosigninIfNecessary();
368 } 368 }
369 possible_auto_sign_in_.reset(); 369 possible_auto_sign_in_.reset();
370 } 370 }
371 371
372 void ChromePasswordManagerClient::NotifyStorePasswordCalled() { 372 void ChromePasswordManagerClient::NotifyStorePasswordCalled() {
373 // If a site stores a credential the autofill password manager shouldn't kick 373 // If a site stores a credential the autofill password manager shouldn't kick
374 // in. 374 // in.
375 password_manager_.DropFormManagers(); 375 password_manager_.DropFormManagers();
376 was_store_ever_called_ = true;
376 } 377 }
377 378
378 void ChromePasswordManagerClient::AutomaticPasswordSave( 379 void ChromePasswordManagerClient::AutomaticPasswordSave(
379 std::unique_ptr<password_manager::PasswordFormManager> saved_form) { 380 std::unique_ptr<password_manager::PasswordFormManager> saved_form) {
380 #if defined(OS_ANDROID) 381 #if defined(OS_ANDROID)
381 GeneratedPasswordSavedInfoBarDelegateAndroid::Create(web_contents()); 382 GeneratedPasswordSavedInfoBarDelegateAndroid::Create(web_contents());
382 #else 383 #else
383 PasswordsClientUIDelegate* manage_passwords_ui_controller = 384 PasswordsClientUIDelegate* manage_passwords_ui_controller =
384 PasswordsClientUIDelegateFromWebContents(web_contents()); 385 PasswordsClientUIDelegateFromWebContents(web_contents());
385 manage_passwords_ui_controller->OnAutomaticPasswordSave( 386 manage_passwords_ui_controller->OnAutomaticPasswordSave(
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
447 // web contents), once the UKM framework provides a mechanism for that. 448 // web contents), once the UKM framework provides a mechanism for that.
448 if (!ukm_source_id_) { 449 if (!ukm_source_id_) {
449 ukm_source_id_ = ukm::UkmRecorder::GetNewSourceID(); 450 ukm_source_id_ = ukm::UkmRecorder::GetNewSourceID();
450 ukm::UkmRecorder* ukm_recorder = GetUkmRecorder(); 451 ukm::UkmRecorder* ukm_recorder = GetUkmRecorder();
451 if (ukm_recorder) 452 if (ukm_recorder)
452 ukm_recorder->UpdateSourceURL(*ukm_source_id_, GetMainFrameURL()); 453 ukm_recorder->UpdateSourceURL(*ukm_source_id_, GetMainFrameURL());
453 } 454 }
454 return *ukm_source_id_; 455 return *ukm_source_id_;
455 } 456 }
456 457
457 // TODO(crbug.com/706392): Fix password reuse detection for Android.
458 #if !defined(OS_ANDROID)
459 void ChromePasswordManagerClient::DidFinishNavigation( 458 void ChromePasswordManagerClient::DidFinishNavigation(
460 content::NavigationHandle* navigation_handle) { 459 content::NavigationHandle* navigation_handle) {
461 if (!navigation_handle->IsInMainFrame() || !navigation_handle->HasCommitted()) 460 if (!navigation_handle->IsInMainFrame() || !navigation_handle->HasCommitted())
462 return; 461 return;
463 462
464 if (!navigation_handle->IsSameDocument()) 463 if (!navigation_handle->IsSameDocument())
dcheng 2017/06/28 19:04:49 How about combining all the non-same document clea
engedy 2017/06/30 19:41:54 Hmm, that line wasn't there before the last rebase
465 ukm_source_id_.reset(); 464 ukm_source_id_.reset();
vasilii 2017/06/29 11:59:58 As a side effect that line now runs on Android. I
engedy 2017/06/30 19:41:54 Rebase artifact. After discussing with Dominic, we
466 465
466 // From this point on, the CredentialManagerImpl will service API calls in the
467 // context of the new WebContents::GetLastCommittedURL, which may very well be
468 // cross-origin. Disconnect existing client, and drop pending requests.
469 if (!navigation_handle->IsSameDocument())
470 credential_manager_impl_.DisconnectBinding();
471
472 // TODO(crbug.com/706392): Fix password reuse detection for Android.
473 #if !defined(OS_ANDROID)
467 password_reuse_detection_manager_.DidNavigateMainFrame(GetMainFrameURL()); 474 password_reuse_detection_manager_.DidNavigateMainFrame(GetMainFrameURL());
468 // After some navigations RenderViewHost persists and just adding the observer 475 // After some navigations RenderViewHost persists and just adding the observer
469 // will cause multiple call of OnInputEvent. Since Widget API doesn't allow to 476 // will cause multiple call of OnInputEvent. Since Widget API doesn't allow to
470 // check whether the observer is already added, the observer is removed and 477 // check whether the observer is already added, the observer is removed and
471 // added again, to ensure that it is added only once. 478 // added again, to ensure that it is added only once.
472 web_contents()->GetRenderViewHost()->GetWidget()->RemoveInputEventObserver( 479 web_contents()->GetRenderViewHost()->GetWidget()->RemoveInputEventObserver(
473 this); 480 this);
474 web_contents()->GetRenderViewHost()->GetWidget()->AddInputEventObserver(this); 481 web_contents()->GetRenderViewHost()->GetWidget()->AddInputEventObserver(this);
482 #endif
475 } 483 }
476 484
485 #if !defined(OS_ANDROID)
477 void ChromePasswordManagerClient::OnInputEvent( 486 void ChromePasswordManagerClient::OnInputEvent(
478 const blink::WebInputEvent& event) { 487 const blink::WebInputEvent& event) {
479 if (event.GetType() != blink::WebInputEvent::kChar) 488 if (event.GetType() != blink::WebInputEvent::kChar)
480 return; 489 return;
481 const blink::WebKeyboardEvent& key_event = 490 const blink::WebKeyboardEvent& key_event =
482 static_cast<const blink::WebKeyboardEvent&>(event); 491 static_cast<const blink::WebKeyboardEvent&>(event);
483 password_reuse_detection_manager_.OnKeyPressed(key_event.text); 492 password_reuse_detection_manager_.OnKeyPressed(key_event.text);
484 } 493 }
485 #endif 494 #endif
486 495
(...skipping 231 matching lines...) Expand 10 before | Expand all | Expand 10 after
718 password_manager::mojom::CredentialManagerRequest request, 727 password_manager::mojom::CredentialManagerRequest request,
719 content::RenderFrameHost* render_frame_host) { 728 content::RenderFrameHost* render_frame_host) {
720 // Only valid for the main frame. 729 // Only valid for the main frame.
721 if (render_frame_host->GetParent()) 730 if (render_frame_host->GetParent())
722 return; 731 return;
723 732
724 content::WebContents* web_contents = 733 content::WebContents* web_contents =
725 content::WebContents::FromRenderFrameHost(render_frame_host); 734 content::WebContents::FromRenderFrameHost(render_frame_host);
726 DCHECK(web_contents); 735 DCHECK(web_contents);
727 736
737 // Only valid for the currently committed RenderFrameHost, and not, e.g. old
738 // zombie RFH's being swapped out following cross-origin navigations.
739 if (web_contents->GetMainFrame() != render_frame_host)
740 return;
741
728 ChromePasswordManagerClient* instance = 742 ChromePasswordManagerClient* instance =
729 ChromePasswordManagerClient::FromWebContents(web_contents); 743 ChromePasswordManagerClient::FromWebContents(web_contents);
730 744
731 // Try to bind to the driver, but if driver is not available for this render 745 // Try to bind to the driver, but if driver is not available for this render
732 // frame host, the request will be just dropped. This will cause the message 746 // frame host, the request will be just dropped. This will cause the message
733 // pipe to be closed, which will raise a connection error on the peer side. 747 // pipe to be closed, which will raise a connection error on the peer side.
734 if (!instance) 748 if (!instance)
735 return; 749 return;
736 750
737 instance->credential_manager_impl_.BindRequest(std::move(request)); 751 instance->credential_manager_impl_.BindRequest(std::move(request));
738 } 752 }
739 753
740 // static 754 // static
741 bool ChromePasswordManagerClient::CanShowBubbleOnURL(const GURL& url) { 755 bool ChromePasswordManagerClient::CanShowBubbleOnURL(const GURL& url) {
742 std::string scheme = url.scheme(); 756 std::string scheme = url.scheme();
743 return (content::ChildProcessSecurityPolicy::GetInstance()->IsWebSafeScheme( 757 return (content::ChildProcessSecurityPolicy::GetInstance()->IsWebSafeScheme(
744 scheme) && 758 scheme) &&
745 #if BUILDFLAG(ENABLE_EXTENSIONS) 759 #if BUILDFLAG(ENABLE_EXTENSIONS)
746 scheme != extensions::kExtensionScheme && 760 scheme != extensions::kExtensionScheme &&
747 #endif 761 #endif
748 scheme != content::kChromeDevToolsScheme); 762 scheme != content::kChromeDevToolsScheme);
749 } 763 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698