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

Side by Side Diff: chrome/browser/extensions/api/media_galleries/media_galleries_api.cc

Issue 2521363002: [Extensions] Remove ChromeExtensionFunctionDetails::GetOriginWebContents (Closed)
Patch Set: lazyboy's Created 4 years 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
« no previous file with comments | « no previous file | chrome/browser/extensions/chrome_extension_function_details.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) 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 <stddef.h> 9 #include <stddef.h>
10 10
(...skipping 23 matching lines...) Expand all
34 #include "chrome/browser/media_galleries/media_galleries_histograms.h" 34 #include "chrome/browser/media_galleries/media_galleries_histograms.h"
35 #include "chrome/browser/media_galleries/media_galleries_permission_controller.h " 35 #include "chrome/browser/media_galleries/media_galleries_permission_controller.h "
36 #include "chrome/browser/media_galleries/media_galleries_preferences.h" 36 #include "chrome/browser/media_galleries/media_galleries_preferences.h"
37 #include "chrome/browser/platform_util.h" 37 #include "chrome/browser/platform_util.h"
38 #include "chrome/browser/profiles/profile.h" 38 #include "chrome/browser/profiles/profile.h"
39 #include "chrome/browser/ui/chrome_select_file_policy.h" 39 #include "chrome/browser/ui/chrome_select_file_policy.h"
40 #include "chrome/common/extensions/api/media_galleries.h" 40 #include "chrome/common/extensions/api/media_galleries.h"
41 #include "chrome/common/pref_names.h" 41 #include "chrome/common/pref_names.h"
42 #include "chrome/grit/generated_resources.h" 42 #include "chrome/grit/generated_resources.h"
43 #include "components/storage_monitor/storage_info.h" 43 #include "components/storage_monitor/storage_info.h"
44 #include "components/web_modal/web_contents_modal_dialog_manager.h"
44 #include "content/public/browser/blob_handle.h" 45 #include "content/public/browser/blob_handle.h"
45 #include "content/public/browser/browser_context.h" 46 #include "content/public/browser/browser_context.h"
46 #include "content/public/browser/browser_thread.h" 47 #include "content/public/browser/browser_thread.h"
47 #include "content/public/browser/child_process_security_policy.h" 48 #include "content/public/browser/child_process_security_policy.h"
48 #include "content/public/browser/render_frame_host.h" 49 #include "content/public/browser/render_frame_host.h"
49 #include "content/public/browser/render_process_host.h" 50 #include "content/public/browser/render_process_host.h"
50 #include "content/public/browser/render_view_host.h" 51 #include "content/public/browser/render_view_host.h"
51 #include "content/public/browser/web_contents.h" 52 #include "content/public/browser/web_contents.h"
53 #include "extensions/browser/app_window/app_window.h"
54 #include "extensions/browser/app_window/app_window_registry.h"
52 #include "extensions/browser/blob_holder.h" 55 #include "extensions/browser/blob_holder.h"
53 #include "extensions/browser/extension_prefs.h" 56 #include "extensions/browser/extension_prefs.h"
54 #include "extensions/browser/extension_system.h" 57 #include "extensions/browser/extension_system.h"
55 #include "extensions/common/extension.h" 58 #include "extensions/common/extension.h"
56 #include "extensions/common/permissions/api_permission.h" 59 #include "extensions/common/permissions/api_permission.h"
57 #include "extensions/common/permissions/media_galleries_permission.h" 60 #include "extensions/common/permissions/media_galleries_permission.h"
58 #include "extensions/common/permissions/permissions_data.h" 61 #include "extensions/common/permissions/permissions_data.h"
59 #include "net/base/mime_sniffer.h" 62 #include "net/base/mime_sniffer.h"
60 #include "storage/browser/blob/blob_data_handle.h" 63 #include "storage/browser/blob/blob_data_handle.h"
61 #include "ui/base/l10n/l10n_util.h" 64 #include "ui/base/l10n/l10n_util.h"
(...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after
255 friend class base::RefCounted<SelectDirectoryDialog>; 258 friend class base::RefCounted<SelectDirectoryDialog>;
256 ~SelectDirectoryDialog() override {} 259 ~SelectDirectoryDialog() override {}
257 260
258 scoped_refptr<ui::SelectFileDialog> select_file_dialog_; 261 scoped_refptr<ui::SelectFileDialog> select_file_dialog_;
259 WebContents* web_contents_; 262 WebContents* web_contents_;
260 Callback callback_; 263 Callback callback_;
261 264
262 DISALLOW_COPY_AND_ASSIGN(SelectDirectoryDialog); 265 DISALLOW_COPY_AND_ASSIGN(SelectDirectoryDialog);
263 }; 266 };
264 267
268 // Returns a web contents to use as the source for a prompt showing to the user.
269 // The web contents has to support modal dialogs, so it can't be the app's
270 // background page.
271 content::WebContents* GetWebContentsForPrompt(
272 content::WebContents* sender_web_contents,
273 content::BrowserContext* browser_context,
274 const std::string& app_id) {
275 // Check if the sender web contents supports modal dialogs.
276 if (sender_web_contents &&
277 web_modal::WebContentsModalDialogManager::FromWebContents(
278 sender_web_contents)) {
279 return sender_web_contents;
280 }
281 // Otherwise, check for the current app window for the app (app windows
282 // support modal dialogs).
283 if (!app_id.empty()) {
284 AppWindow* window = AppWindowRegistry::Get(browser_context)
285 ->GetCurrentAppWindowForApp(app_id);
286 if (window)
287 return window->web_contents();
288 }
289 return nullptr;
290 }
291
265 } // namespace 292 } // namespace
266 293
267 MediaGalleriesEventRouter::MediaGalleriesEventRouter( 294 MediaGalleriesEventRouter::MediaGalleriesEventRouter(
268 content::BrowserContext* context) 295 content::BrowserContext* context)
269 : profile_(Profile::FromBrowserContext(context)), weak_ptr_factory_(this) { 296 : profile_(Profile::FromBrowserContext(context)), weak_ptr_factory_(this) {
270 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); 297 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
271 DCHECK(profile_); 298 DCHECK(profile_);
272 299
273 EventRouter::Get(profile_)->RegisterObserver( 300 EventRouter::Get(profile_)->RegisterObserver(
274 this, MediaGalleries::OnGalleryChanged::kEventName); 301 this, MediaGalleries::OnGalleryChanged::kEventName);
(...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after
438 } 465 }
439 466
440 // The custom JS binding will use this list to create DOMFileSystem objects. 467 // The custom JS binding will use this list to create DOMFileSystem objects.
441 SetResult(std::move(list)); 468 SetResult(std::move(list));
442 SendResponse(true); 469 SendResponse(true);
443 } 470 }
444 471
445 void MediaGalleriesGetMediaFileSystemsFunction::ShowDialog() { 472 void MediaGalleriesGetMediaFileSystemsFunction::ShowDialog() {
446 media_galleries::UsageCount(media_galleries::SHOW_DIALOG); 473 media_galleries::UsageCount(media_galleries::SHOW_DIALOG);
447 WebContents* contents = 474 WebContents* contents =
448 ChromeExtensionFunctionDetails(this).GetOriginWebContents(); 475 GetWebContentsForPrompt(GetSenderWebContents(),
476 browser_context(),
477 extension()->id());
449 if (!contents) { 478 if (!contents) {
450 SendResponse(false); 479 SendResponse(false);
451 return; 480 return;
452 } 481 }
453 482
454 // Controller will delete itself. 483 // Controller will delete itself.
455 base::Closure cb = base::Bind( 484 base::Closure cb = base::Bind(
456 &MediaGalleriesGetMediaFileSystemsFunction::GetAndReturnGalleries, this); 485 &MediaGalleriesGetMediaFileSystemsFunction::GetAndReturnGalleries, this);
457 new MediaGalleriesPermissionController(contents, *extension(), cb); 486 new MediaGalleriesPermissionController(contents, *extension(), cb);
458 } 487 }
(...skipping 16 matching lines...) Expand all
475 MediaGalleriesAddUserSelectedFolderFunction:: 504 MediaGalleriesAddUserSelectedFolderFunction::
476 ~MediaGalleriesAddUserSelectedFolderFunction() {} 505 ~MediaGalleriesAddUserSelectedFolderFunction() {}
477 506
478 bool MediaGalleriesAddUserSelectedFolderFunction::RunAsync() { 507 bool MediaGalleriesAddUserSelectedFolderFunction::RunAsync() {
479 media_galleries::UsageCount(media_galleries::ADD_USER_SELECTED_FOLDER); 508 media_galleries::UsageCount(media_galleries::ADD_USER_SELECTED_FOLDER);
480 return Setup(GetProfile(), &error_, base::Bind( 509 return Setup(GetProfile(), &error_, base::Bind(
481 &MediaGalleriesAddUserSelectedFolderFunction::OnPreferencesInit, this)); 510 &MediaGalleriesAddUserSelectedFolderFunction::OnPreferencesInit, this));
482 } 511 }
483 512
484 void MediaGalleriesAddUserSelectedFolderFunction::OnPreferencesInit() { 513 void MediaGalleriesAddUserSelectedFolderFunction::OnPreferencesInit() {
485 Profile* profile = GetProfile();
486 const std::string& app_id = extension()->id(); 514 const std::string& app_id = extension()->id();
487 WebContents* contents = 515 WebContents* contents =
488 ChromeExtensionFunctionDetails(this).GetOriginWebContents(); 516 GetWebContentsForPrompt(GetSenderWebContents(),
517 browser_context(),
518 app_id);
489 if (!contents) { 519 if (!contents) {
490 SendResponse(false); 520 SendResponse(false);
491 return; 521 return;
492 } 522 }
493 523
494 if (!user_gesture()) { 524 if (!user_gesture()) {
495 OnDirectorySelected(base::FilePath()); 525 OnDirectorySelected(base::FilePath());
496 return; 526 return;
497 } 527 }
498 528
499 base::FilePath last_used_path = 529 base::FilePath last_used_path =
500 extensions::file_system_api::GetLastChooseEntryDirectory( 530 extensions::file_system_api::GetLastChooseEntryDirectory(
501 extensions::ExtensionPrefs::Get(profile), app_id); 531 extensions::ExtensionPrefs::Get(browser_context()), app_id);
502 SelectDirectoryDialog::Callback callback = base::Bind( 532 SelectDirectoryDialog::Callback callback = base::Bind(
503 &MediaGalleriesAddUserSelectedFolderFunction::OnDirectorySelected, this); 533 &MediaGalleriesAddUserSelectedFolderFunction::OnDirectorySelected, this);
504 scoped_refptr<SelectDirectoryDialog> select_directory_dialog = 534 scoped_refptr<SelectDirectoryDialog> select_directory_dialog =
505 new SelectDirectoryDialog(contents, callback); 535 new SelectDirectoryDialog(contents, callback);
506 select_directory_dialog->Show(last_used_path); 536 select_directory_dialog->Show(last_used_path);
507 } 537 }
508 538
509 void MediaGalleriesAddUserSelectedFolderFunction::OnDirectorySelected( 539 void MediaGalleriesAddUserSelectedFolderFunction::OnDirectorySelected(
510 const base::FilePath& selected_directory) { 540 const base::FilePath& selected_directory) {
511 if (selected_directory.empty()) { 541 if (selected_directory.empty()) {
(...skipping 359 matching lines...) Expand 10 before | Expand all | Expand 10 after
871 SendResponse(false); 901 SendResponse(false);
872 return; 902 return;
873 } 903 }
874 904
875 gallery_watch_manager()->RemoveWatch( 905 gallery_watch_manager()->RemoveWatch(
876 GetProfile(), extension_id(), gallery_pref_id); 906 GetProfile(), extension_id(), gallery_pref_id);
877 SendResponse(true); 907 SendResponse(true);
878 } 908 }
879 909
880 } // namespace extensions 910 } // namespace extensions
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/extensions/chrome_extension_function_details.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698