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

Unified Diff: chrome/browser/extensions/extension_function.cc

Issue 10021071: Remove Browser dependency in ExtensionFunctionDispatcher (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebase Created 8 years, 8 months 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
Index: chrome/browser/extensions/extension_function.cc
diff --git a/chrome/browser/extensions/extension_function.cc b/chrome/browser/extensions/extension_function.cc
index f2348c65b5b5fe96f176f03d4edd9a9cf7bd49a4..e21ff3b71967ec5fe4d88a739356860be289a70a 100644
--- a/chrome/browser/extensions/extension_function.cc
+++ b/chrome/browser/extensions/extension_function.cc
@@ -8,8 +8,11 @@
#include "base/logging.h"
#include "chrome/browser/extensions/extension_function_dispatcher.h"
#include "chrome/browser/extensions/extension_service.h"
+#include "chrome/browser/extensions/extension_window_controller.h"
+#include "chrome/browser/extensions/extension_window_list.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/renderer_host/chrome_render_message_filter.h"
+#include "chrome/browser/ui/browser_list.h"
#include "chrome/common/extensions/extension_messages.h"
#include "content/public/browser/notification_source.h"
#include "content/public/browser/notification_types.h"
@@ -179,8 +182,49 @@ void UIThreadExtensionFunction::SetRenderViewHost(
new RenderViewHostTracker(this, render_view_host) : NULL);
}
+// TODO(stevenjb): Replace this with GetExtensionWindowController().
Browser* UIThreadExtensionFunction::GetCurrentBrowser() {
- return dispatcher()->GetCurrentBrowser(render_view_host_, include_incognito_);
+ // If the delegate has an associated browser, return it.
+ ExtensionWindowController* window_controller =
+ dispatcher()->delegate()->GetExtensionWindowController();
+ if (window_controller) {
+ Browser* browser = window_controller->GetBrowser();
+ if (browser)
+ return browser;
+ }
+
+ // Otherwise, try to default to a reasonable browser. If |include_incognito_|
+ // is true, we will also search browsers in the incognito version of this
+ // profile. Note that the profile may already be incognito, in which case
+ // we will search the incognito version only, regardless of the value of
+ // |include_incognito|.
+ Profile* profile = Profile::FromBrowserContext(
+ render_view_host_->GetProcess()->GetBrowserContext());
+ Browser* browser = BrowserList::FindAnyBrowser(profile, include_incognito_);
+
+ // NOTE(rafaelw): This can return NULL in some circumstances. In particular,
+ // a background_page onload chrome.tabs api call can make it into here
+ // before the browser is sufficiently initialized to return here.
+ // A similar situation may arise during shutdown.
+ // TODO(rafaelw): Delay creation of background_page until the browser
+ // is available. http://code.google.com/p/chromium/issues/detail?id=13284
+ return browser;
+}
+
+ExtensionWindowController*
+UIThreadExtensionFunction::GetExtensionWindowController() {
+ // If the delegate has an associated window controller, return it.
+ ExtensionWindowController* window_controller =
+ dispatcher()->delegate()->GetExtensionWindowController();
+ if (window_controller)
+ return window_controller;
+
+ Profile* profile = Profile::FromBrowserContext(
+ render_view_host_->GetProcess()->GetBrowserContext());
+ ExtensionWindowList::ProfileMatchType match_type = include_incognito_
+ ? ExtensionWindowController::MATCH_INCOGNITO
+ : ExtensionWindowController::MATCH_NORMAL_ONLY;
+ return ExtensionWindowList::GetInstance()->CurrentWindow(profile, match_type);
}
void UIThreadExtensionFunction::SendResponse(bool success) {

Powered by Google App Engine
This is Rietveld 408576698