Commit 9c82aae1 authored by Devlin Cronin's avatar Devlin Cronin Committed by Commit Bot

[Extensions] (Mostly) remove GetAssociatedWebContentsDeprecated()

All callers except the fileManagerPrivate API have been updated to not
rely on GetAssociatedWebContentsDeprecated(). The fileManagerPrivate
issue is being tracked separately. Remove the function
GetAssociatedWebContentsDeprecated() and move it to be directly in the
fileManagerPrivate API to avoid having usage spread.

Bug: 461394, 844654
Change-Id: I69adc7f3534d4908497bf73d3fcab0f7443450e7
Reviewed-on: https://chromium-review.googlesource.com/1066733Reviewed-by: default avatarIstiaque Ahmed <lazyboy@chromium.org>
Commit-Queue: Devlin <rdevlin.cronin@chromium.org>
Cr-Commit-Position: refs/heads/master@{#560171}
parent ac1f5614
...@@ -7,9 +7,12 @@ ...@@ -7,9 +7,12 @@
#include <stddef.h> #include <stddef.h>
#include "chrome/browser/chromeos/extensions/file_manager/private_api_util.h" #include "chrome/browser/chromeos/extensions/file_manager/private_api_util.h"
#include "chrome/browser/ui/browser.h"
#include "chrome/browser/ui/tabs/tab_strip_model.h"
#include "chrome/browser/ui/views/select_file_dialog_extension.h" #include "chrome/browser/ui/views/select_file_dialog_extension.h"
#include "chrome/common/extensions/api/file_manager_private.h" #include "chrome/common/extensions/api/file_manager_private.h"
#include "content/public/browser/browser_thread.h" #include "content/public/browser/browser_thread.h"
#include "extensions/browser/extension_function_dispatcher.h"
#include "ui/shell_dialogs/selected_file_info.h" #include "ui/shell_dialogs/selected_file_info.h"
using content::BrowserThread; using content::BrowserThread;
...@@ -18,11 +21,29 @@ namespace extensions { ...@@ -18,11 +21,29 @@ namespace extensions {
namespace { namespace {
// TODO(https://crbug.com/844654): This should be using something more
// deterministic.
content::WebContents* GetAssociatedWebContentsDeprecated(
ChromeAsyncExtensionFunction* function) {
if (function->dispatcher()) {
content::WebContents* web_contents =
function->dispatcher()->GetAssociatedWebContents();
if (web_contents)
return web_contents;
}
Browser* browser =
ChromeExtensionFunctionDetails(function).GetCurrentBrowser();
if (!browser)
return nullptr;
return browser->tab_strip_model()->GetActiveWebContents();
}
// Computes the routing ID for SelectFileDialogExtension from the |function|. // Computes the routing ID for SelectFileDialogExtension from the |function|.
SelectFileDialogExtension::RoutingID GetFileDialogRoutingID( SelectFileDialogExtension::RoutingID GetFileDialogRoutingID(
ChromeAsyncExtensionFunction* function) { ChromeAsyncExtensionFunction* function) {
return SelectFileDialogExtension::GetRoutingIDFromWebContents( return SelectFileDialogExtension::GetRoutingIDFromWebContents(
function->GetAssociatedWebContentsDeprecated()); GetAssociatedWebContentsDeprecated(function));
} }
} // namespace } // namespace
......
...@@ -29,11 +29,6 @@ void ChromeAsyncExtensionFunction::SetError(const std::string& error) { ...@@ -29,11 +29,6 @@ void ChromeAsyncExtensionFunction::SetError(const std::string& error) {
error_ = error; error_ = error;
} }
content::WebContents*
ChromeAsyncExtensionFunction::GetAssociatedWebContentsDeprecated() {
return chrome_details_.GetAssociatedWebContentsDeprecated();
}
const std::string& ChromeAsyncExtensionFunction::GetError() const { const std::string& ChromeAsyncExtensionFunction::GetError() const {
return error_.empty() ? UIThreadExtensionFunction::GetError() : error_; return error_.empty() ? UIThreadExtensionFunction::GetError() : error_;
} }
......
...@@ -11,10 +11,6 @@ ...@@ -11,10 +11,6 @@
class Profile; class Profile;
namespace content {
class WebContents;
}
// A chrome specific analog to AsyncExtensionFunction. This has access to a // A chrome specific analog to AsyncExtensionFunction. This has access to a
// chrome Profile. // chrome Profile.
// //
...@@ -29,8 +25,6 @@ class ChromeAsyncExtensionFunction : public UIThreadExtensionFunction { ...@@ -29,8 +25,6 @@ class ChromeAsyncExtensionFunction : public UIThreadExtensionFunction {
void SetError(const std::string& error); void SetError(const std::string& error);
// ExtensionFunction:
content::WebContents* GetAssociatedWebContentsDeprecated() override;
const std::string& GetError() const override; const std::string& GetError() const override;
protected: protected:
......
...@@ -70,21 +70,6 @@ Browser* ChromeExtensionFunctionDetails::GetCurrentBrowser() const { ...@@ -70,21 +70,6 @@ Browser* ChromeExtensionFunctionDetails::GetCurrentBrowser() const {
return NULL; return NULL;
} }
content::WebContents*
ChromeExtensionFunctionDetails::GetAssociatedWebContentsDeprecated() {
if (function_->dispatcher()) {
content::WebContents* web_contents =
function_->dispatcher()->GetAssociatedWebContents();
if (web_contents)
return web_contents;
}
Browser* browser = GetCurrentBrowser();
if (!browser)
return NULL;
return browser->tab_strip_model()->GetActiveWebContents();
}
gfx::NativeWindow ChromeExtensionFunctionDetails::GetNativeWindowForUI() { gfx::NativeWindow ChromeExtensionFunctionDetails::GetNativeWindowForUI() {
// Try to use WindowControllerList first because WebContents's // Try to use WindowControllerList first because WebContents's
// GetTopLevelNativeWindow() can't return the top level window when the tab // GetTopLevelNativeWindow() can't return the top level window when the tab
......
...@@ -12,10 +12,6 @@ class Browser; ...@@ -12,10 +12,6 @@ class Browser;
class Profile; class Profile;
class UIThreadExtensionFunction; class UIThreadExtensionFunction;
namespace content {
class WebContents;
}
// Provides Chrome-specific details to UIThreadExtensionFunction // Provides Chrome-specific details to UIThreadExtensionFunction
// implementations. // implementations.
class ChromeExtensionFunctionDetails { class ChromeExtensionFunctionDetails {
...@@ -50,10 +46,6 @@ class ChromeExtensionFunctionDetails { ...@@ -50,10 +46,6 @@ class ChromeExtensionFunctionDetails {
// use ExtensionFunction::GetSenderWebContents(). We should get rid of this. // use ExtensionFunction::GetSenderWebContents(). We should get rid of this.
Browser* GetCurrentBrowser() const; Browser* GetCurrentBrowser() const;
// Do not use.
// See comments on ExtensionFunction::GetAssociatedWebContentsDeprecated().
content::WebContents* GetAssociatedWebContentsDeprecated();
// Find a UI surface to display any UI (like a permission prompt) for the // Find a UI surface to display any UI (like a permission prompt) for the
// extension calling this function. This will check, in order of preference, // extension calling this function. This will check, in order of preference,
// - The current window for the function (as defined by // - The current window for the function (as defined by
......
...@@ -564,15 +564,6 @@ void UIThreadExtensionFunction::SetRenderFrameHost( ...@@ -564,15 +564,6 @@ void UIThreadExtensionFunction::SetRenderFrameHost(
render_frame_host ? new RenderFrameHostTracker(this) : nullptr); render_frame_host ? new RenderFrameHostTracker(this) : nullptr);
} }
content::WebContents*
UIThreadExtensionFunction::GetAssociatedWebContentsDeprecated() {
content::WebContents* web_contents = NULL;
if (dispatcher())
web_contents = dispatcher()->GetAssociatedWebContents();
return web_contents;
}
content::WebContents* UIThreadExtensionFunction::GetSenderWebContents() { content::WebContents* UIThreadExtensionFunction::GetSenderWebContents() {
return render_frame_host_ ? return render_frame_host_ ?
content::WebContents::FromRenderFrameHost(render_frame_host_) : nullptr; content::WebContents::FromRenderFrameHost(render_frame_host_) : nullptr;
......
...@@ -538,15 +538,6 @@ class UIThreadExtensionFunction : public ExtensionFunction { ...@@ -538,15 +538,6 @@ class UIThreadExtensionFunction : public ExtensionFunction {
service_worker_version_id_ = version_id; service_worker_version_id_ = version_id;
} }
// Gets the "current" web contents if any. If there is no associated web
// contents then defaults to the foremost one.
// DEPRECATED: "current" can mean different things in different contexts. This
// function is unpredictable and unreliable, and should not be used. You
// probably want to use GetSenderWebContents() instead. If that is
// insufficient - which should be rare - find the appropriate web contents
// directly.
virtual content::WebContents* GetAssociatedWebContentsDeprecated();
// Returns the web contents associated with the sending |render_frame_host_|. // Returns the web contents associated with the sending |render_frame_host_|.
// This can be null. // This can be null.
content::WebContents* GetSenderWebContents(); content::WebContents* GetSenderWebContents();
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment