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

Unified 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, 1 month 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | chrome/browser/extensions/chrome_extension_function_details.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/extensions/api/media_galleries/media_galleries_api.cc
diff --git a/chrome/browser/extensions/api/media_galleries/media_galleries_api.cc b/chrome/browser/extensions/api/media_galleries/media_galleries_api.cc
index 6daf3bdca3e0966d60ec24f60f9b690dc0ac3460..492f8da62a959656cc538b9502ba941d736e4dc5 100644
--- a/chrome/browser/extensions/api/media_galleries/media_galleries_api.cc
+++ b/chrome/browser/extensions/api/media_galleries/media_galleries_api.cc
@@ -41,6 +41,7 @@
#include "chrome/common/pref_names.h"
#include "chrome/grit/generated_resources.h"
#include "components/storage_monitor/storage_info.h"
+#include "components/web_modal/web_contents_modal_dialog_manager.h"
#include "content/public/browser/blob_handle.h"
#include "content/public/browser/browser_context.h"
#include "content/public/browser/browser_thread.h"
@@ -49,6 +50,8 @@
#include "content/public/browser/render_process_host.h"
#include "content/public/browser/render_view_host.h"
#include "content/public/browser/web_contents.h"
+#include "extensions/browser/app_window/app_window.h"
+#include "extensions/browser/app_window/app_window_registry.h"
#include "extensions/browser/blob_holder.h"
#include "extensions/browser/extension_prefs.h"
#include "extensions/browser/extension_system.h"
@@ -262,6 +265,30 @@ class SelectDirectoryDialog : public ui::SelectFileDialog::Listener,
DISALLOW_COPY_AND_ASSIGN(SelectDirectoryDialog);
};
+// Returns a web contents to use as the source for a prompt showing to the user.
+// The web contents has to support modal dialogs, so it can't be the app's
+// background page.
+content::WebContents* GetWebContentsForPrompt(
+ content::WebContents* sender_web_contents,
+ content::BrowserContext* browser_context,
+ const std::string& app_id) {
+ // Check if the sender web contents supports modal dialogs.
+ if (sender_web_contents &&
+ web_modal::WebContentsModalDialogManager::FromWebContents(
+ sender_web_contents)) {
+ return sender_web_contents;
+ }
+ // Otherwise, check for the current app window for the app (app windows
+ // support modal dialogs).
+ if (!app_id.empty()) {
+ AppWindow* window = AppWindowRegistry::Get(browser_context)
+ ->GetCurrentAppWindowForApp(app_id);
+ if (window)
+ return window->web_contents();
+ }
+ return nullptr;
+}
+
} // namespace
MediaGalleriesEventRouter::MediaGalleriesEventRouter(
@@ -445,7 +472,9 @@ void MediaGalleriesGetMediaFileSystemsFunction::ReturnGalleries(
void MediaGalleriesGetMediaFileSystemsFunction::ShowDialog() {
media_galleries::UsageCount(media_galleries::SHOW_DIALOG);
WebContents* contents =
- ChromeExtensionFunctionDetails(this).GetOriginWebContents();
+ GetWebContentsForPrompt(GetSenderWebContents(),
+ browser_context(),
+ extension()->id());
if (!contents) {
SendResponse(false);
return;
@@ -482,10 +511,11 @@ bool MediaGalleriesAddUserSelectedFolderFunction::RunAsync() {
}
void MediaGalleriesAddUserSelectedFolderFunction::OnPreferencesInit() {
- Profile* profile = GetProfile();
const std::string& app_id = extension()->id();
WebContents* contents =
- ChromeExtensionFunctionDetails(this).GetOriginWebContents();
+ GetWebContentsForPrompt(GetSenderWebContents(),
+ browser_context(),
+ app_id);
if (!contents) {
SendResponse(false);
return;
@@ -498,7 +528,7 @@ void MediaGalleriesAddUserSelectedFolderFunction::OnPreferencesInit() {
base::FilePath last_used_path =
extensions::file_system_api::GetLastChooseEntryDirectory(
- extensions::ExtensionPrefs::Get(profile), app_id);
+ extensions::ExtensionPrefs::Get(browser_context()), app_id);
SelectDirectoryDialog::Callback callback = base::Bind(
&MediaGalleriesAddUserSelectedFolderFunction::OnDirectorySelected, this);
scoped_refptr<SelectDirectoryDialog> select_directory_dialog =
« 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