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 // Implements the Chrome Extensions Media Galleries API. | 5 // Implements the Chrome Extensions Media Galleries API. |
6 | 6 |
7 #include "chrome/browser/extensions/api/media_galleries/media_galleries_api.h" | 7 #include "chrome/browser/extensions/api/media_galleries/media_galleries_api.h" |
8 | 8 |
9 #include <set> | 9 #include <set> |
10 #include <string> | 10 #include <string> |
11 #include <vector> | 11 #include <vector> |
12 | 12 |
13 #include "apps/shell_window.h" | 13 #include "apps/shell_window.h" |
14 #include "apps/shell_window_registry.h" | 14 #include "apps/shell_window_registry.h" |
15 #include "base/lazy_instance.h" | 15 #include "base/lazy_instance.h" |
16 #include "base/platform_file.h" | 16 #include "base/platform_file.h" |
17 #include "base/stl_util.h" | 17 #include "base/stl_util.h" |
18 #include "base/strings/string_number_conversions.h" | 18 #include "base/strings/string_number_conversions.h" |
19 #include "base/strings/utf_string_conversions.h" | 19 #include "base/strings/utf_string_conversions.h" |
20 #include "base/values.h" | 20 #include "base/values.h" |
21 #include "chrome/browser/browser_process.h" | 21 #include "chrome/browser/browser_process.h" |
22 #include "chrome/browser/extensions/api/file_system/file_system_api.h" | 22 #include "chrome/browser/extensions/api/file_system/file_system_api.h" |
23 #include "chrome/browser/extensions/blob_reader.h" | 23 #include "chrome/browser/extensions/blob_reader.h" |
| 24 #include "chrome/browser/extensions/extension_tab_util.h" |
24 #include "chrome/browser/media_galleries/media_file_system_registry.h" | 25 #include "chrome/browser/media_galleries/media_file_system_registry.h" |
25 #include "chrome/browser/media_galleries/media_galleries_dialog_controller.h" | 26 #include "chrome/browser/media_galleries/media_galleries_dialog_controller.h" |
26 #include "chrome/browser/media_galleries/media_galleries_histograms.h" | 27 #include "chrome/browser/media_galleries/media_galleries_histograms.h" |
27 #include "chrome/browser/media_galleries/media_galleries_preferences.h" | 28 #include "chrome/browser/media_galleries/media_galleries_preferences.h" |
28 #include "chrome/browser/media_galleries/media_galleries_scan_result_dialog_cont
roller.h" | 29 #include "chrome/browser/media_galleries/media_galleries_scan_result_dialog_cont
roller.h" |
29 #include "chrome/browser/media_galleries/media_scan_manager.h" | 30 #include "chrome/browser/media_galleries/media_scan_manager.h" |
30 #include "chrome/browser/platform_util.h" | 31 #include "chrome/browser/platform_util.h" |
31 #include "chrome/browser/profiles/profile.h" | 32 #include "chrome/browser/profiles/profile.h" |
32 #include "chrome/browser/storage_monitor/storage_info.h" | 33 #include "chrome/browser/storage_monitor/storage_info.h" |
33 #include "chrome/browser/ui/chrome_select_file_policy.h" | 34 #include "chrome/browser/ui/chrome_select_file_policy.h" |
(...skipping 498 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
532 media_galleries::UsageCount(media_galleries::ADD_USER_SELECTED_FOLDER); | 533 media_galleries::UsageCount(media_galleries::ADD_USER_SELECTED_FOLDER); |
533 return Setup(GetProfile(), &error_, base::Bind( | 534 return Setup(GetProfile(), &error_, base::Bind( |
534 &MediaGalleriesAddUserSelectedFolderFunction::OnPreferencesInit, this)); | 535 &MediaGalleriesAddUserSelectedFolderFunction::OnPreferencesInit, this)); |
535 } | 536 } |
536 | 537 |
537 void MediaGalleriesAddUserSelectedFolderFunction::OnPreferencesInit() { | 538 void MediaGalleriesAddUserSelectedFolderFunction::OnPreferencesInit() { |
538 Profile* profile = GetProfile(); | 539 Profile* profile = GetProfile(); |
539 const std::string& app_id = GetExtension()->id(); | 540 const std::string& app_id = GetExtension()->id(); |
540 WebContents* contents = GetWebContents(render_view_host(), profile, app_id); | 541 WebContents* contents = GetWebContents(render_view_host(), profile, app_id); |
541 if (!contents) { | 542 if (!contents) { |
542 SendResponse(false); | 543 // When the request originated from a background page, but there is no app |
543 return; | 544 // window open, check to see if it originated from a tab and display the |
| 545 // dialog in that tab. |
| 546 bool found_tab = extensions::ExtensionTabUtil::GetTabById( |
| 547 source_tab_id(), profile, profile->IsOffTheRecord(), |
| 548 NULL, NULL, &contents, NULL); |
| 549 if (!found_tab || !contents) { |
| 550 SendResponse(false); |
| 551 return; |
| 552 } |
544 } | 553 } |
545 | 554 |
546 if (!user_gesture()) { | 555 if (!user_gesture()) { |
547 OnDirectorySelected(base::FilePath()); | 556 OnDirectorySelected(base::FilePath()); |
548 return; | 557 return; |
549 } | 558 } |
550 | 559 |
551 base::FilePath last_used_path = | 560 base::FilePath last_used_path = |
552 extensions::file_system_api::GetLastChooseEntryDirectory( | 561 extensions::file_system_api::GetLastChooseEntryDirectory( |
553 extensions::ExtensionPrefs::Get(profile), app_id); | 562 extensions::ExtensionPrefs::Get(profile), app_id); |
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
684 if (!user_gesture()) | 693 if (!user_gesture()) |
685 return false; | 694 return false; |
686 | 695 |
687 return Setup(GetProfile(), &error_, base::Bind( | 696 return Setup(GetProfile(), &error_, base::Bind( |
688 &MediaGalleriesAddScanResultsFunction::OnPreferencesInit, this)); | 697 &MediaGalleriesAddScanResultsFunction::OnPreferencesInit, this)); |
689 } | 698 } |
690 | 699 |
691 void MediaGalleriesAddScanResultsFunction::OnPreferencesInit() { | 700 void MediaGalleriesAddScanResultsFunction::OnPreferencesInit() { |
692 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); | 701 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); |
693 const Extension* extension = GetExtension(); | 702 const Extension* extension = GetExtension(); |
694 MediaGalleriesPreferences * preferences = | 703 MediaGalleriesPreferences* preferences = |
695 media_file_system_registry()->GetPreferences(GetProfile()); | 704 media_file_system_registry()->GetPreferences(GetProfile()); |
696 if (MediaGalleriesScanResultDialogController::ScanResultCountForExtension( | 705 if (MediaGalleriesScanResultDialogController::ScanResultCountForExtension( |
697 preferences, extension) == 0) { | 706 preferences, extension) == 0) { |
698 GetAndReturnGalleries(); | 707 GetAndReturnGalleries(); |
699 return; | 708 return; |
700 } | 709 } |
701 | 710 |
702 WebContents* contents = | 711 WebContents* contents = |
703 GetWebContents(render_view_host(), GetProfile(), extension->id()); | 712 GetWebContents(render_view_host(), GetProfile(), extension->id()); |
704 if (!contents) { | 713 if (!contents) { |
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
788 if (mime_type_sniffed) | 797 if (mime_type_sniffed) |
789 metadata.mime_type = mime_type; | 798 metadata.mime_type = mime_type; |
790 | 799 |
791 // TODO(tommycli): Kick off SafeMediaMetadataParser if |mime_type_only| false. | 800 // TODO(tommycli): Kick off SafeMediaMetadataParser if |mime_type_only| false. |
792 | 801 |
793 SetResult(metadata.ToValue().release()); | 802 SetResult(metadata.ToValue().release()); |
794 SendResponse(true); | 803 SendResponse(true); |
795 } | 804 } |
796 | 805 |
797 } // namespace extensions | 806 } // namespace extensions |
OLD | NEW |