summaryrefslogtreecommitdiffstats
path: root/chrome/browser/extensions
diff options
context:
space:
mode:
authorrafaelw@chromium.org <rafaelw@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-04-15 19:05:07 +0000
committerrafaelw@chromium.org <rafaelw@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-04-15 19:05:07 +0000
commit9aa2eaaeadd97c8ed9018a63ca701a42eb731c9b (patch)
treeedffb1492a5c26585cd0c666e8eea312f719c25e /chrome/browser/extensions
parent3cf7b304ca304dde742f6362a90dbafad5986bc9 (diff)
downloadchromium_src-9aa2eaaeadd97c8ed9018a63ca701a42eb731c9b.zip
chromium_src-9aa2eaaeadd97c8ed9018a63ca701a42eb731c9b.tar.gz
chromium_src-9aa2eaaeadd97c8ed9018a63ca701a42eb731c9b.tar.bz2
Add ExtensionFunctionDispatcher::Delegate::GetAssociatedTabContents.
Following work from: http://codereview.chromium.org/1521032/show, based on comments from aa here: http://codereview.chromium.org/1521032/diff/4002/9004#newcode639 BUG=40428 TEST=All tests should pass Review URL: http://codereview.chromium.org/1627024 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@44680 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/extensions')
-rw-r--r--chrome/browser/extensions/extension_dom_ui.h2
-rw-r--r--chrome/browser/extensions/extension_function_dispatcher.h7
-rw-r--r--chrome/browser/extensions/extension_host.cc3
-rw-r--r--chrome/browser/extensions/extension_host.h11
-rw-r--r--chrome/browser/extensions/extension_infobar_delegate.cc1
-rw-r--r--chrome/browser/extensions/extension_tabs_module.cc35
6 files changed, 25 insertions, 34 deletions
diff --git a/chrome/browser/extensions/extension_dom_ui.h b/chrome/browser/extensions/extension_dom_ui.h
index 87f57fc..7f60e2f 100644
--- a/chrome/browser/extensions/extension_dom_ui.h
+++ b/chrome/browser/extensions/extension_dom_ui.h
@@ -47,7 +47,7 @@ class ExtensionDOMUI
virtual Browser* GetBrowser() const;
virtual gfx::NativeView GetNativeViewOfHost();
virtual gfx::NativeWindow GetCustomFrameNativeWindow();
-
+ virtual TabContents* associated_tab_contents() { return tab_contents(); }
virtual Profile* GetProfile();
virtual ExtensionBookmarkManagerEventRouter*
diff --git a/chrome/browser/extensions/extension_function_dispatcher.h b/chrome/browser/extensions/extension_function_dispatcher.h
index fc50c17..8f1f6d9 100644
--- a/chrome/browser/extensions/extension_function_dispatcher.h
+++ b/chrome/browser/extensions/extension_function_dispatcher.h
@@ -21,6 +21,7 @@ class ExtensionHost;
class Profile;
class RenderViewHost;
class RenderViewHostDelegate;
+class TabContents;
class Value;
// A factory function for creating new ExtensionFunction instances.
@@ -48,6 +49,12 @@ class ExtensionFunctionDispatcher {
return NULL;
}
+ // Asks the delegate for any relevant TabContents associated with this
+ // context. For example, the TabContents in which an infobar or
+ // chrome-extension://<id> URL are being shown. Callers must check for a
+ // NULL return value (as in the case of a background page).
+ virtual TabContents* associated_tab_contents() = 0;
+
protected:
virtual ~Delegate() {}
};
diff --git a/chrome/browser/extensions/extension_host.cc b/chrome/browser/extensions/extension_host.cc
index 7e15d48..78a3e5b 100644
--- a/chrome/browser/extensions/extension_host.cc
+++ b/chrome/browser/extensions/extension_host.cc
@@ -126,7 +126,8 @@ ExtensionHost::ExtensionHost(Extension* extension, SiteInstance* site_instance,
did_stop_loading_(false),
document_element_available_(false),
url_(url),
- extension_host_type_(host_type) {
+ extension_host_type_(host_type),
+ associated_tab_contents_(NULL) {
int64 session_storage_namespace_id = profile_->GetWebKitContext()->
dom_storage_context()->AllocateSessionStorageNamespaceId();
render_view_host_ = new RenderViewHost(site_instance, this, MSG_ROUTING_NONE,
diff --git a/chrome/browser/extensions/extension_host.h b/chrome/browser/extensions/extension_host.h
index f30593c..da3cdd0 100644
--- a/chrome/browser/extensions/extension_host.h
+++ b/chrome/browser/extensions/extension_host.h
@@ -82,6 +82,14 @@ class ExtensionHost : public RenderViewHostDelegate,
ViewType::Type extension_host_type() const { return extension_host_type_; }
+ // ExtensionFunctionDispatcher::Delegate
+ virtual TabContents* associated_tab_contents() {
+ return associated_tab_contents_;
+ }
+ void set_associated_tab_contents(TabContents* associated_tab_contents) {
+ associated_tab_contents_ = associated_tab_contents;
+ }
+
// Sets the the ViewType of this host (e.g. mole, toolstrip).
void SetRenderViewType(ViewType::Type type);
@@ -253,6 +261,9 @@ class ExtensionHost : public RenderViewHostDelegate,
// are used here, others are not hosted by ExtensionHost.
ViewType::Type extension_host_type_;
+ // The relevant TabContents associated with this ExtensionHost, if any.
+ TabContents* associated_tab_contents_;
+
// Used to measure how long it's been since the host was created.
PerfTimer since_created_;
diff --git a/chrome/browser/extensions/extension_infobar_delegate.cc b/chrome/browser/extensions/extension_infobar_delegate.cc
index 32236ed..09cd233 100644
--- a/chrome/browser/extensions/extension_infobar_delegate.cc
+++ b/chrome/browser/extensions/extension_infobar_delegate.cc
@@ -24,6 +24,7 @@ ExtensionInfoBarDelegate::ExtensionInfoBarDelegate(Browser* browser,
ExtensionProcessManager* manager =
browser->profile()->GetExtensionProcessManager();
extension_host_.reset(manager->CreateInfobar(url, browser));
+ extension_host_->set_associated_tab_contents(tab_contents);
registrar_.Add(this, NotificationType::EXTENSION_HOST_VIEW_SHOULD_CLOSE,
Source<Profile>(browser->profile()));
diff --git a/chrome/browser/extensions/extension_tabs_module.cc b/chrome/browser/extensions/extension_tabs_module.cc
index f575ba2..17058af 100644
--- a/chrome/browser/extensions/extension_tabs_module.cc
+++ b/chrome/browser/extensions/extension_tabs_module.cc
@@ -622,40 +622,11 @@ bool GetTabFunction::RunImpl() {
}
bool GetCurrentTabFunction::RunImpl() {
- DCHECK(dispatcher() && dispatcher()->render_view_host());
+ DCHECK(dispatcher());
- RenderViewHostDelegate* rvh_delegate =
- dispatcher()->render_view_host()->delegate();
-
- TabContents* contents = rvh_delegate->GetAsTabContents();
- if (contents) {
- // Caller is running inside a TabContents.
+ TabContents* contents = dispatcher()->delegate()->associated_tab_contents();
+ if (contents)
result_.reset(ExtensionTabUtil::CreateTabValue(contents));
- return true;
- }
-
- ExtensionHost* host = reinterpret_cast<ExtensionHost*>(rvh_delegate);
- Browser* browser = GetCurrentBrowser();
- if (browser && ViewType::EXTENSION_INFOBAR == host->extension_host_type()) {
- // Unfortunately, now we have to iterate over each TabContents and each
- // Infobar to try to find the one corresponding to this ExtensionHost.
- TabStripModel* tab_strip = browser->tabstrip_model();
- int tab_count = tab_strip->count();
- for (int tab_index = 0; tab_index < tab_count; ++tab_index) {
- contents = tab_strip->GetTabContentsAt(tab_index);
- int infobar_count = contents->infobar_delegate_count();
- for (int infobar_index = 0; infobar_index < infobar_count;
- ++infobar_index) {
- ExtensionInfoBarDelegate* infobar_delegate =
- contents->GetInfoBarDelegateAt(infobar_index)
- ->AsExtensionInfoBarDelegate();
- if (infobar_delegate && infobar_delegate->extension_host() == host) {
- result_.reset(ExtensionTabUtil::CreateTabValue(contents));
- return true;
- }
- }
- }
- }
return true;
}