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 "content/browser/download/download_item_impl.h" | 5 #include "content/browser/download/download_item_impl.h" |
6 | 6 |
7 #include <vector> | 7 #include <vector> |
8 | 8 |
9 #include "base/basictypes.h" | 9 #include "base/basictypes.h" |
10 #include "base/bind.h" | 10 #include "base/bind.h" |
11 #include "base/file_util.h" | 11 #include "base/file_util.h" |
12 #include "base/format_macros.h" | 12 #include "base/format_macros.h" |
13 #include "base/i18n/case_conversion.h" | 13 #include "base/i18n/case_conversion.h" |
14 #include "base/i18n/string_search.h" | 14 #include "base/i18n/string_search.h" |
15 #include "base/logging.h" | 15 #include "base/logging.h" |
16 #include "base/metrics/histogram.h" | 16 #include "base/metrics/histogram.h" |
17 #include "base/stl_util.h" | 17 #include "base/stl_util.h" |
18 #include "base/stringprintf.h" | 18 #include "base/stringprintf.h" |
19 #include "base/utf_string_conversions.h" | 19 #include "base/utf_string_conversions.h" |
20 #include "content/browser/download/download_create_info.h" | 20 #include "content/browser/download/download_create_info.h" |
21 #include "content/browser/download/download_file.h" | 21 #include "content/browser/download/download_file.h" |
22 #include "content/browser/download/download_file_manager.h" | 22 #include "content/browser/download/download_file_manager.h" |
23 #include "content/browser/download/download_interrupt_reasons_impl.h" | 23 #include "content/browser/download/download_interrupt_reasons_impl.h" |
24 #include "content/browser/download/download_request_handle.h" | 24 #include "content/browser/download/download_request_handle.h" |
25 #include "content/browser/download/download_stats.h" | 25 #include "content/browser/download/download_stats.h" |
| 26 #include "content/browser/intents/internal_web_intents_dispatcher.h" |
26 #include "content/browser/tab_contents/tab_contents.h" | 27 #include "content/browser/tab_contents/tab_contents.h" |
27 #include "content/public/browser/browser_thread.h" | 28 #include "content/public/browser/browser_thread.h" |
28 #include "content/public/browser/content_browser_client.h" | 29 #include "content/public/browser/content_browser_client.h" |
29 #include "content/public/browser/download_persistent_store_info.h" | 30 #include "content/public/browser/download_persistent_store_info.h" |
| 31 #include "content/public/browser/resource_context.h" |
| 32 #include "content/public/browser/web_contents_delegate.h" |
| 33 #include "content/public/browser/web_intents_dispatcher.h" |
30 #include "net/base/net_util.h" | 34 #include "net/base/net_util.h" |
| 35 #include "webkit/blob/blob_data.h" |
| 36 #include "webkit/blob/blob_storage_controller.h" |
| 37 #include "webkit/glue/web_intent_data.h" |
31 | 38 |
32 using content::BrowserThread; | 39 using content::BrowserThread; |
33 using content::DownloadFile; | 40 using content::DownloadFile; |
34 using content::DownloadId; | 41 using content::DownloadId; |
35 using content::DownloadItem; | 42 using content::DownloadItem; |
36 using content::DownloadManager; | 43 using content::DownloadManager; |
37 using content::DownloadPersistentStoreInfo; | 44 using content::DownloadPersistentStoreInfo; |
38 using content::WebContents; | 45 using content::WebContents; |
39 | 46 |
40 // A DownloadItem normally goes through the following states: | 47 // A DownloadItem normally goes through the following states: |
(...skipping 723 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
764 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 771 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
765 | 772 |
766 VLOG(20) << __FUNCTION__ << "()" | 773 VLOG(20) << __FUNCTION__ << "()" |
767 << " full_path = \"" << full_path.value() << "\"" | 774 << " full_path = \"" << full_path.value() << "\"" |
768 << " needed rename = " << NeedsRename() | 775 << " needed rename = " << NeedsRename() |
769 << " " << DebugString(false); | 776 << " " << DebugString(false); |
770 DCHECK(NeedsRename()); | 777 DCHECK(NeedsRename()); |
771 | 778 |
772 Rename(full_path); | 779 Rename(full_path); |
773 | 780 |
| 781 if (delegate_->ShouldOpenWithWebIntent(this)) { |
| 782 DispatchAsWebIntent(); |
| 783 Completed(); |
| 784 return; |
| 785 } |
| 786 |
774 if (delegate_->ShouldOpenDownload(this)) { | 787 if (delegate_->ShouldOpenDownload(this)) { |
775 Completed(); | 788 Completed(); |
776 } else { | 789 } else { |
777 delegate_delayed_complete_ = true; | 790 delegate_delayed_complete_ = true; |
778 } | 791 } |
779 } | 792 } |
780 | 793 |
| 794 void DownloadItemImpl::DispatchAsWebIntent() { |
| 795 // TODO(gbillock): should this read non-binary files and pass them |
| 796 // as unserialized text? Probably so... |
| 797 webkit_glue::WebIntentData intent_data( |
| 798 ASCIIToUTF16("http://webintents.org/view"), |
| 799 ASCIIToUTF16(GetMimeType()), |
| 800 GetFullPath().AsUTF8Unsafe(), |
| 801 GetReceivedBytes()); |
| 802 intent_data.extra_data.insert(make_pair( |
| 803 ASCIIToUTF16("url"), ASCIIToUTF16(GetURL().spec()))); |
| 804 |
| 805 // TODO(gbillock): need to ChildProcessSecurityPolicy::GrantReadFile(someone) |
| 806 // here? Or on the receiving end? |
| 807 |
| 808 content::WebIntentsDispatcher* dispatcher = |
| 809 new InternalWebIntentsDispatcher(intent_data); |
| 810 GetWebContents()->GetDelegate()->WebIntentDispatch(GetWebContents(), |
| 811 dispatcher); |
| 812 } |
| 813 |
781 bool DownloadItemImpl::MatchesQuery(const string16& query) const { | 814 bool DownloadItemImpl::MatchesQuery(const string16& query) const { |
782 if (query.empty()) | 815 if (query.empty()) |
783 return true; | 816 return true; |
784 | 817 |
785 DCHECK_EQ(query, base::i18n::ToLower(query)); | 818 DCHECK_EQ(query, base::i18n::ToLower(query)); |
786 | 819 |
787 string16 url_raw(UTF8ToUTF16(GetURL().spec())); | 820 string16 url_raw(UTF8ToUTF16(GetURL().spec())); |
788 if (base::i18n::StringSearchIgnoringCaseAndAccents(query, url_raw)) | 821 if (base::i18n::StringSearchIgnoringCaseAndAccents(query, url_raw)) |
789 return true; | 822 return true; |
790 | 823 |
(...skipping 355 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1146 std::map<const void*, ExternalData*>::iterator it = | 1179 std::map<const void*, ExternalData*>::iterator it = |
1147 external_data_map_.find(key); | 1180 external_data_map_.find(key); |
1148 | 1181 |
1149 if (it == external_data_map_.end()) { | 1182 if (it == external_data_map_.end()) { |
1150 external_data_map_[key] = data; | 1183 external_data_map_[key] = data; |
1151 } else if (it->second != data) { | 1184 } else if (it->second != data) { |
1152 delete it->second; | 1185 delete it->second; |
1153 it->second = data; | 1186 it->second = data; |
1154 } | 1187 } |
1155 } | 1188 } |
OLD | NEW |