summaryrefslogtreecommitdiffstats
path: root/chrome/browser/extensions/extension_function.cc
diff options
context:
space:
mode:
authorstevenjb@chromium.org <stevenjb@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-05-05 22:01:43 +0000
committerstevenjb@chromium.org <stevenjb@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-05-05 22:01:43 +0000
commitb51f3562b28c3e685bd8a0241efd70d5215a11f1 (patch)
tree5dda218b975525ef5f0e550ed83ae66bf702a237 /chrome/browser/extensions/extension_function.cc
parent607f1367aa4d3dfa55713a8f1a772a574b1688f3 (diff)
downloadchromium_src-b51f3562b28c3e685bd8a0241efd70d5215a11f1.zip
chromium_src-b51f3562b28c3e685bd8a0241efd70d5215a11f1.tar.gz
chromium_src-b51f3562b28c3e685bd8a0241efd70d5215a11f1.tar.bz2
Remove Browser dependency in ExtensionFunctionDispatcher
Part 2/4 for chrome.tabs support for non browser windows. BUG=115532 TEST=All browser tests pass. Review URL: http://codereview.chromium.org/10021071 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@135562 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/extensions/extension_function.cc')
-rw-r--r--chrome/browser/extensions/extension_function.cc46
1 files changed, 45 insertions, 1 deletions
diff --git a/chrome/browser/extensions/extension_function.cc b/chrome/browser/extensions/extension_function.cc
index ef09e34..6f77fa8 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"
@@ -178,8 +181,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) {