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

Unified Diff: chrome/browser/extensions/chrome_extension_function_details.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 | « chrome/browser/extensions/chrome_extension_function_details.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/extensions/chrome_extension_function_details.cc
diff --git a/chrome/browser/extensions/chrome_extension_function_details.cc b/chrome/browser/extensions/chrome_extension_function_details.cc
index daccbc4ca456bf42829f67db4270990fe1cb1d41..70f624414d2a013fd30c6a41e1bf2ff871e9f4d3 100644
--- a/chrome/browser/extensions/chrome_extension_function_details.cc
+++ b/chrome/browser/extensions/chrome_extension_function_details.cc
@@ -104,45 +104,6 @@ ChromeExtensionFunctionDetails::GetAssociatedWebContents() {
return browser->tab_strip_model()->GetActiveWebContents();
}
-content::WebContents* ChromeExtensionFunctionDetails::GetOriginWebContents() {
- WebContents* contents = function_->GetSenderWebContents();
- if (!contents)
- return nullptr;
-
- // Hack: use the existence of a WebContentsModalDialogManager to decide
- // whether the sender web contents is visible.
- web_modal::WebContentsModalDialogManager* web_contents_modal_dialog_manager =
- web_modal::WebContentsModalDialogManager::FromWebContents(contents);
- if (web_contents_modal_dialog_manager)
- return contents;
-
- // If there is no WebContentsModalDialogManager, then this contents is
- // probably the background page for an extension or app.
- contents = nullptr;
-
- int source_tab_id = function_->source_tab_id();
- if (source_tab_id != TabStripModel::kNoTab) {
- // When the request originated from a background page, but there is no
- // app window open, check to see if it originated from a tab and display
- // the dialog in that tab.
- if (extensions::ExtensionTabUtil::GetTabById(
- source_tab_id, GetProfile(), true /* include_incognito */, nullptr,
- nullptr, &contents, nullptr))
- return contents;
- }
-
- // Try to find an app window and get its web contents.
- const extensions::Extension* extension = function_->extension();
- if (extension) {
- extensions::AppWindow* window =
- extensions::AppWindowRegistry::Get(GetProfile())
- ->GetCurrentAppWindowForApp(extension->id());
- if (window)
- return window->web_contents();
- }
- return contents;
-}
-
gfx::NativeWindow ChromeExtensionFunctionDetails::GetNativeWindowForUI() {
// Try to use WindowControllerList first because WebContents's
// GetTopLevelNativeWindow() can't return the top level window when the tab
@@ -153,11 +114,26 @@ gfx::NativeWindow ChromeExtensionFunctionDetails::GetNativeWindowForUI() {
if (controller)
return controller->window()->GetNativeWindow();
- // CurrentWindowForFunction() can't find app's window.
- WebContents* contents = GetOriginWebContents();
- if (contents)
- return contents->GetTopLevelNativeWindow();
+ // Next, check the sender web contents for if it supports modal dialogs.
+ // TODO(devlin): This seems weird. Why wouldn't we check this first?
+ content::WebContents* sender_web_contents = function_->GetSenderWebContents();
+ if (sender_web_contents &&
+ web_modal::WebContentsModalDialogManager::FromWebContents(
+ sender_web_contents)) {
+ return sender_web_contents->GetTopLevelNativeWindow();
+ }
+
+ // Then, check for any app windows that are open.
+ if (function_->extension() &&
+ function_->extension()->is_app()) {
+ extensions::AppWindow* window =
+ extensions::AppWindowRegistry::Get(function_->browser_context())
+ ->GetCurrentAppWindowForApp(function_->extension()->id());
+ if (window)
+ return window->web_contents()->GetTopLevelNativeWindow();
+ }
+ // As a last resort, find a browser.
Browser* browser = chrome::FindBrowserWithProfile(GetProfile());
return browser->window()->GetNativeWindow();
}
« no previous file with comments | « chrome/browser/extensions/chrome_extension_function_details.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698