OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/file_select_helper.h" | 5 #include "chrome/browser/file_select_helper.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 | 8 |
9 #include <string> | 9 #include <string> |
10 #include <utility> | 10 #include <utility> |
(...skipping 610 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
621 return; | 621 return; |
622 | 622 |
623 render_frame_host_ = nullptr; | 623 render_frame_host_ = nullptr; |
624 web_contents_ = nullptr; | 624 web_contents_ = nullptr; |
625 Release(); | 625 Release(); |
626 } | 626 } |
627 | 627 |
628 void FileSelectHelper::EnumerateDirectory(int request_id, | 628 void FileSelectHelper::EnumerateDirectory(int request_id, |
629 RenderViewHost* render_view_host, | 629 RenderViewHost* render_view_host, |
630 const base::FilePath& path) { | 630 const base::FilePath& path) { |
631 | |
632 // Because this class returns notifications to the RenderViewHost, it is | 631 // Because this class returns notifications to the RenderViewHost, it is |
633 // difficult for callers to know how long to keep a reference to this | 632 // difficult for callers to know how long to keep a reference to this |
634 // instance. We AddRef() here to keep the instance alive after we return | 633 // instance. We AddRef() here to keep the instance alive after we return |
635 // to the caller, until the last callback is received from the enumeration | 634 // to the caller, until the last callback is received from the enumeration |
636 // code. At that point, we must call EnumerateDirectoryEnd(). | 635 // code. At that point, we must call EnumerateDirectoryEnd(). |
637 AddRef(); | 636 AddRef(); |
638 StartNewEnumeration(path, request_id, render_view_host); | 637 StartNewEnumeration(path, request_id, render_view_host); |
639 } | 638 } |
640 | 639 |
641 // This method is called when we receive the last callback from the enumeration | 640 // This method is called when we receive the last callback from the enumeration |
642 // code. Perform any cleanup and release the reference we added in | 641 // code. Perform any cleanup and release the reference we added in |
643 // EnumerateDirectory(). | 642 // EnumerateDirectory(). |
644 void FileSelectHelper::EnumerateDirectoryEnd() { | 643 void FileSelectHelper::EnumerateDirectoryEnd() { |
645 Release(); | 644 Release(); |
646 } | 645 } |
647 | 646 |
648 void FileSelectHelper::Observe(int type, | 647 void FileSelectHelper::Observe(int type, |
649 const content::NotificationSource& source, | 648 const content::NotificationSource& source, |
650 const content::NotificationDetails& details) { | 649 const content::NotificationDetails& details) { |
651 switch (type) { | 650 DCHECK_EQ(content::NOTIFICATION_RENDER_WIDGET_HOST_DESTROYED, type); |
652 case content::NOTIFICATION_RENDER_WIDGET_HOST_DESTROYED: { | 651 DCHECK_EQ(content::Source<RenderWidgetHost>(source).ptr(), |
653 DCHECK(content::Source<RenderWidgetHost>(source).ptr() == | 652 render_frame_host_->GetRenderViewHost()->GetWidget()); |
654 render_frame_host_->GetRenderViewHost()->GetWidget()); | 653 render_frame_host_ = nullptr; |
655 render_frame_host_ = NULL; | |
656 break; | |
657 } | |
658 default: | |
659 NOTREACHED(); | |
660 } | |
661 } | 654 } |
662 | 655 |
663 void FileSelectHelper::RenderViewHostChanged(RenderViewHost* old_host, | 656 void FileSelectHelper::RenderViewHostChanged(RenderViewHost* old_host, |
664 RenderViewHost* new_host) { | 657 RenderViewHost* new_host) { |
665 CleanUpOnRenderViewHostChange(); | 658 CleanUpOnRenderViewHostChange(); |
666 } | 659 } |
667 | 660 |
668 void FileSelectHelper::WebContentsDestroyed() { | 661 void FileSelectHelper::WebContentsDestroyed() { |
669 web_contents_ = nullptr; | 662 web_contents_ = nullptr; |
670 CleanUpOnRenderViewHostChange(); | 663 CleanUpOnRenderViewHostChange(); |
(...skipping 16 matching lines...) Expand all Loading... |
687 | 680 |
688 // static | 681 // static |
689 base::FilePath FileSelectHelper::GetSanitizedFileName( | 682 base::FilePath FileSelectHelper::GetSanitizedFileName( |
690 const base::FilePath& suggested_filename) { | 683 const base::FilePath& suggested_filename) { |
691 if (suggested_filename.empty()) | 684 if (suggested_filename.empty()) |
692 return base::FilePath(); | 685 return base::FilePath(); |
693 return net::GenerateFileName( | 686 return net::GenerateFileName( |
694 GURL(), std::string(), std::string(), suggested_filename.AsUTF8Unsafe(), | 687 GURL(), std::string(), std::string(), suggested_filename.AsUTF8Unsafe(), |
695 std::string(), l10n_util::GetStringUTF8(IDS_DEFAULT_DOWNLOAD_FILENAME)); | 688 std::string(), l10n_util::GetStringUTF8(IDS_DEFAULT_DOWNLOAD_FILENAME)); |
696 } | 689 } |
OLD | NEW |