This source file includes following definitions.
- GetProfile
- CanOperateOnWindow
- GetCurrentBrowser
- GetExtensionWindowController
- GetAssociatedWebContents
- Run
#include "chrome/browser/extensions/chrome_extension_function.h"
#include "chrome/browser/extensions/window_controller.h"
#include "chrome/browser/extensions/window_controller_list.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/ui/browser.h"
#include "chrome/browser/ui/browser_finder.h"
#include "chrome/browser/ui/tabs/tab_strip_model.h"
#include "content/public/browser/render_process_host.h"
#include "content/public/browser/render_view_host.h"
#include "extensions/browser/extension_function_dispatcher.h"
using content::RenderViewHost;
using content::WebContents;
ChromeAsyncExtensionFunction::ChromeAsyncExtensionFunction() {}
Profile* ChromeAsyncExtensionFunction::GetProfile() const {
return Profile::FromBrowserContext(context_);
}
bool ChromeAsyncExtensionFunction::CanOperateOnWindow(
const extensions::WindowController* window_controller) const {
const extensions::Extension* extension = GetExtension();
if (extension != NULL && !window_controller->IsVisibleToExtension(extension))
return false;
if (GetProfile() == window_controller->profile())
return true;
if (!include_incognito())
return false;
return GetProfile()->HasOffTheRecordProfile() &&
GetProfile()->GetOffTheRecordProfile() == window_controller->profile();
}
Browser* ChromeAsyncExtensionFunction::GetCurrentBrowser() {
if (dispatcher()) {
extensions::WindowController* window_controller =
dispatcher()->delegate()->GetExtensionWindowController();
if (window_controller) {
Browser* browser = window_controller->GetBrowser();
if (browser)
return browser;
}
}
if (render_view_host_) {
Profile* profile = Profile::FromBrowserContext(
render_view_host_->GetProcess()->GetBrowserContext());
Browser* browser = chrome::FindAnyBrowser(
profile, include_incognito_, chrome::GetActiveDesktop());
if (browser)
return browser;
}
return NULL;
}
extensions::WindowController*
ChromeAsyncExtensionFunction::GetExtensionWindowController() {
if (dispatcher()) {
extensions::WindowController* window_controller =
dispatcher()->delegate()->GetExtensionWindowController();
if (window_controller)
return window_controller;
}
return extensions::WindowControllerList::GetInstance()
->CurrentWindowForFunction(this);
}
content::WebContents* ChromeAsyncExtensionFunction::GetAssociatedWebContents() {
content::WebContents* web_contents =
UIThreadExtensionFunction::GetAssociatedWebContents();
if (web_contents)
return web_contents;
Browser* browser = GetCurrentBrowser();
if (!browser)
return NULL;
return browser->tab_strip_model()->GetActiveWebContents();
}
ChromeAsyncExtensionFunction::~ChromeAsyncExtensionFunction() {}
ChromeSyncExtensionFunction::ChromeSyncExtensionFunction() {}
void ChromeSyncExtensionFunction::Run() { SendResponse(RunImpl()); }
ChromeSyncExtensionFunction::~ChromeSyncExtensionFunction() {}