Commit afc4b1b1 authored by gbillock@chromium.org's avatar gbillock@chromium.org

[Web Intents] Add ability to dispatch intents from extension-caused code (i.e. context menus)

R=ben@chromium.org,groby@chromium.org
BUG=109425,128964


Review URL: https://chromiumcodereview.appspot.com/10830102

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@150876 0039d316-1c4b-4281-b951-d872f2087c98
parent 2071d86d
......@@ -45,6 +45,7 @@
#include "content/public/browser/site_instance.h"
#include "content/public/browser/web_contents.h"
#include "content/public/browser/web_contents_view.h"
#include "content/public/browser/web_intents_dispatcher.h"
#include "grit/browser_resources.h"
#include "grit/chromium_strings.h"
#include "grit/generated_resources.h"
......@@ -418,6 +419,28 @@ void ExtensionHost::OnStartDownload(
OnStartDownload(source, download);
}
void ExtensionHost::WebIntentDispatch(
content::WebContents* web_contents,
content::WebIntentsDispatcher* intents_dispatcher) {
#if !defined(OS_ANDROID)
scoped_ptr<content::WebIntentsDispatcher> dispatcher(intents_dispatcher);
Browser* browser = view() ? view()->browser()
: browser::FindBrowserWithWebContents(web_contents);
// For background scripts/pages, there will be no view(). In this case, we
// want to treat the intent as a browser-initiated one and deliver it into the
// current browser. It probably came from a context menu click or similar.
if (!browser)
browser = web_intents::GetBrowserForBackgroundWebIntentDelivery(profile());
if (browser) {
static_cast<WebContentsDelegate*>(browser)->
WebIntentDispatch(NULL, dispatcher.release());
}
#endif
}
void ExtensionHost::WillRunJavaScriptDialog() {
ExtensionProcessManager* pm =
ExtensionSystem::Get(profile_)->process_manager();
......
......@@ -36,6 +36,7 @@ namespace content {
class RenderProcessHost;
class RenderWidgetHostView;
class SiteInstance;
class WebIntentsDispatcher;
}
namespace extensions {
......@@ -166,6 +167,9 @@ class ExtensionHost : public content::WebContentsDelegate,
virtual void CloseContents(content::WebContents* contents) OVERRIDE;
virtual void OnStartDownload(content::WebContents* source,
content::DownloadItem* download) OVERRIDE;
virtual void WebIntentDispatch(
content::WebContents* web_contents,
content::WebIntentsDispatcher* intents_dispatcher) OVERRIDE;
// content::NotificationObserver
virtual void Observe(int type,
......
......@@ -28,4 +28,11 @@ bool IsWebIntentsEnabledForProfile(Profile* profile) {
return IsWebIntentsEnabled(profile->GetPrefs());
}
Browser* GetBrowserForBackgroundWebIntentDelivery(Profile* profile) {
Browser* browser = BrowserList::GetLastActive();
if (browser && profile && browser->profile() != profile)
return NULL;
return browser;
}
} // namespace web_intents
......@@ -5,6 +5,7 @@
#ifndef CHROME_BROWSER_INTENTS_WEB_INTENTS_UTIL_H_
#define CHROME_BROWSER_INTENTS_WEB_INTENTS_UTIL_H_
class Browser;
class Profile;
class PrefService;
......@@ -20,6 +21,11 @@ bool IsWebIntentsEnabled(PrefService* prefs);
// the Profile to check that WebIntents are enabled for.
bool IsWebIntentsEnabledForProfile(Profile* profile);
// In a context where we are generating a web intent based on internal events,
// or from an extension background page, get the browser in which to show the
// intent picker to the user.
Browser* GetBrowserForBackgroundWebIntentDelivery(Profile* profile);
} // namespace web_intents
#endif // CHROME_BROWSER_INTENTS_WEB_INTENTS_UTIL_H_
......@@ -40,6 +40,10 @@ namespace content {
class WebContents;
}
namespace web_intents {
Browser* GetBrowserForBackgroundWebIntentDelivery(Profile*);
}
#if defined(USE_ASH)
content::WebContents* GetActiveWebContents();
#endif
......@@ -102,6 +106,8 @@ class BrowserList {
friend class TaskManager;
friend class WindowSizer;
friend class browser::BrowserActivityObserver;
friend Browser* web_intents::GetBrowserForBackgroundWebIntentDelivery(
Profile*);
#if defined(OS_CHROMEOS)
friend class chromeos::ScreenLocker;
#endif
......
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