summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authoraa@chromium.org <aa@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-03-24 19:59:41 +0000
committeraa@chromium.org <aa@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-03-24 19:59:41 +0000
commit0ec9203dac6b11c664adda8a39b77f3f00eb6072 (patch)
tree65e5cff3f9e04da87e32e9436ddc795a7811c278
parent630d1b047c8c4ea54eef06fa24a89ad516457875 (diff)
downloadchromium_src-0ec9203dac6b11c664adda8a39b77f3f00eb6072.zip
chromium_src-0ec9203dac6b11c664adda8a39b77f3f00eb6072.tar.gz
chromium_src-0ec9203dac6b11c664adda8a39b77f3f00eb6072.tar.bz2
Generalize the ExtensionFunctionDispatcher::Delegate interface a bit more. In particular remove GetExtensionHost() and GetExtensionDOMUI(). I'm going to add a new type of EFD::Delegate soon that is neither of these, and I don't think it makes sense to have the code assume that EFD::Delegate must be one of the two of them.
Some code still does RTTI stuff through RenderViewHostDelegate::GetRenderViewType(), but in that case it is more clear that there are a long list of potential view types, and that the caller must be more careful. Review URL: http://codereview.chromium.org/1149003 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@42519 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--chrome/browser/extensions/execute_code_in_tab_function.cc2
-rw-r--r--chrome/browser/extensions/extension_bookmark_manager_api.cc40
-rw-r--r--chrome/browser/extensions/extension_dom_ui.cc36
-rw-r--r--chrome/browser/extensions/extension_dom_ui.h8
-rw-r--r--chrome/browser/extensions/extension_function.h20
-rw-r--r--chrome/browser/extensions/extension_function_dispatcher.cc61
-rw-r--r--chrome/browser/extensions/extension_function_dispatcher.h49
-rw-r--r--chrome/browser/extensions/extension_host.cc55
-rw-r--r--chrome/browser/extensions/extension_host.h17
-rw-r--r--chrome/browser/extensions/extension_infobar_module.cc2
-rw-r--r--chrome/browser/extensions/extension_popup_api.cc82
-rw-r--r--chrome/browser/extensions/extension_popup_api.h4
-rw-r--r--chrome/browser/extensions/extension_tabs_module.cc16
-rw-r--r--chrome/browser/extensions/extension_toolstrip_api.cc17
-rw-r--r--chrome/browser/extensions/extensions_ui.cc6
15 files changed, 189 insertions, 226 deletions
diff --git a/chrome/browser/extensions/execute_code_in_tab_function.cc b/chrome/browser/extensions/execute_code_in_tab_function.cc
index a7ac42a..fca1a17 100644
--- a/chrome/browser/extensions/execute_code_in_tab_function.cc
+++ b/chrome/browser/extensions/execute_code_in_tab_function.cc
@@ -48,7 +48,7 @@ bool ExecuteCodeInTabFunction::RunImpl() {
Value* tab_value = NULL;
EXTENSION_FUNCTION_VALIDATE(args->Get(0, &tab_value));
if (tab_value->IsType(Value::TYPE_NULL)) {
- browser = GetBrowser();
+ browser = GetCurrentBrowser();
if (!browser) {
error_ = keys::kNoCurrentWindowError;
return false;
diff --git a/chrome/browser/extensions/extension_bookmark_manager_api.cc b/chrome/browser/extensions/extension_bookmark_manager_api.cc
index c480766..ff29fab 100644
--- a/chrome/browser/extensions/extension_bookmark_manager_api.cc
+++ b/chrome/browser/extensions/extension_bookmark_manager_api.cc
@@ -21,6 +21,7 @@
#include "chrome/browser/importer/importer.h"
#include "chrome/browser/importer/importer_data_types.h"
#include "chrome/browser/profile.h"
+#include "chrome/browser/renderer_host/render_view_host.h"
#include "chrome/browser/tab_contents/tab_contents.h"
#include "grit/generated_resources.h"
@@ -396,10 +397,18 @@ bool StartDragBookmarkManagerFunction::RunImpl() {
EXTENSION_FUNCTION_VALIDATE(
GetNodesFromArguments(model, args_as_list(), &nodes));
- bookmark_utils::DragBookmarks(profile(), nodes,
- dispatcher()->GetExtensionDOMUI()->tab_contents()->GetNativeView());
+ if (dispatcher()->render_view_host()->delegate()->GetRenderViewType() ==
+ ViewType::TAB_CONTENTS) {
+ ExtensionDOMUI* dom_ui =
+ static_cast<ExtensionDOMUI*>(dispatcher()->delegate());
+ bookmark_utils::DragBookmarks(
+ profile(), nodes, dom_ui->tab_contents()->GetNativeView());
- return true;
+ return true;
+ } else {
+ NOTREACHED();
+ return false;
+ }
}
bool DropBookmarkManagerFunction::RunImpl() {
@@ -432,15 +441,24 @@ bool DropBookmarkManagerFunction::RunImpl() {
else
drop_index = drop_parent->GetChildCount();
- ExtensionBookmarkManagerEventRouter* router = dispatcher()->
- GetExtensionDOMUI()->extension_bookmark_manager_event_router();
+ if (dispatcher()->render_view_host()->delegate()->GetRenderViewType() ==
+ ViewType::TAB_CONTENTS) {
+ ExtensionDOMUI* dom_ui =
+ static_cast<ExtensionDOMUI*>(dispatcher()->delegate());
+ ExtensionBookmarkManagerEventRouter* router =
+ dom_ui->extension_bookmark_manager_event_router();
- DCHECK(router);
+ DCHECK(router);
- bookmark_utils::PerformBookmarkDrop(profile(), *router->GetBookmarkDragData(),
- drop_parent, drop_index);
+ bookmark_utils::PerformBookmarkDrop(profile(),
+ *router->GetBookmarkDragData(),
+ drop_parent, drop_index);
- router->ClearBookmarkDragData();
- SendResponse(true);
- return true;
+ router->ClearBookmarkDragData();
+ SendResponse(true);
+ return true;
+ } else {
+ NOTREACHED();
+ return false;
+ }
}
diff --git a/chrome/browser/extensions/extension_dom_ui.cc b/chrome/browser/extensions/extension_dom_ui.cc
index 907e6c0..0a7e5d1 100644
--- a/chrome/browser/extensions/extension_dom_ui.cc
+++ b/chrome/browser/extensions/extension_dom_ui.cc
@@ -96,18 +96,12 @@ void ExtensionDOMUI::ProcessDOMUIMessage(const std::string& message,
has_callback);
}
-Browser* ExtensionDOMUI::GetBrowser(bool include_incognito) const {
+Browser* ExtensionDOMUI::GetBrowser() const {
Browser* browser = NULL;
TabContentsDelegate* tab_contents_delegate = tab_contents()->delegate();
- if (tab_contents_delegate) {
+ if (tab_contents_delegate)
browser = tab_contents_delegate->GetBrowser();
- if (browser && browser->profile()->IsOffTheRecord() && !include_incognito) {
- // Fall back to the toplevel regular browser if we don't want to include
- // incognito browsers.
- browser = BrowserList::GetLastActiveWithProfile(
- browser->profile()->GetOriginalProfile());
- }
- }
+
return browser;
}
@@ -115,20 +109,18 @@ Profile* ExtensionDOMUI::GetProfile() {
return DOMUI::GetProfile();
}
-gfx::NativeWindow ExtensionDOMUI::GetFrameNativeWindow() {
- gfx::NativeWindow native_window =
- ExtensionFunctionDispatcher::Delegate::GetFrameNativeWindow();
+gfx::NativeWindow ExtensionDOMUI::GetCustomFrameNativeWindow() {
+ if (GetBrowser())
+ return NULL;
- // If there was no window associated with the function dispatcher delegate,
+ // If there was no browser associated with the function dispatcher delegate,
// then this DOMUI may be hosted in an ExternalTabContainer, and a framing
// window will be accessible through the tab_contents.
- if (!native_window) {
- TabContentsDelegate* tab_contents_delegate = tab_contents()->delegate();
- if (tab_contents_delegate)
- native_window = tab_contents_delegate->GetFrameNativeWindow();
- }
-
- return native_window;
+ TabContentsDelegate* tab_contents_delegate = tab_contents()->delegate();
+ if (tab_contents_delegate)
+ return tab_contents_delegate->GetFrameNativeWindow();
+ else
+ return NULL;
}
gfx::NativeView ExtensionDOMUI::GetNativeViewOfHost() {
@@ -287,10 +279,6 @@ void ExtensionDOMUI::UnregisterChromeURLOverride(const std::string& page,
}
}
-RenderViewHost* ExtensionDOMUI::GetRenderViewHost() {
- return tab_contents() ? tab_contents()->render_view_host() : NULL;
-}
-
// static
void ExtensionDOMUI::UnregisterChromeURLOverrides(
Profile* profile, const Extension::URLOverrideMap& overrides) {
diff --git a/chrome/browser/extensions/extension_dom_ui.h b/chrome/browser/extensions/extension_dom_ui.h
index 54de39c..7892b89 100644
--- a/chrome/browser/extensions/extension_dom_ui.h
+++ b/chrome/browser/extensions/extension_dom_ui.h
@@ -41,13 +41,11 @@ class ExtensionDOMUI
bool has_callback);
// ExtensionFunctionDispatcher::Delegate
- virtual Browser* GetBrowser(bool include_incognito) const;
- virtual ExtensionDOMUI* GetExtensionDOMUI() { return this; }
- virtual gfx::NativeWindow GetFrameNativeWindow();
+ virtual Browser* GetBrowser() const;
+ virtual gfx::NativeView GetNativeViewOfHost();
+ virtual gfx::NativeWindow GetCustomFrameNativeWindow();
- virtual RenderViewHost* GetRenderViewHost();
virtual Profile* GetProfile();
- virtual gfx::NativeView GetNativeViewOfHost();
virtual ExtensionBookmarkManagerEventRouter*
extension_bookmark_manager_event_router() {
diff --git a/chrome/browser/extensions/extension_function.h b/chrome/browser/extensions/extension_function.h
index 75e2553a..8e1ab8f 100644
--- a/chrome/browser/extensions/extension_function.h
+++ b/chrome/browser/extensions/extension_function.h
@@ -97,8 +97,24 @@ class ExtensionFunction : public base::RefCounted<ExtensionFunction> {
return NULL;
}
- Browser* GetBrowser() {
- return dispatcher()->GetBrowser(include_incognito_);
+ // Gets the "current" browser, if any.
+ //
+ // Many extension APIs operate relative to the current browser, which is the
+ // browser the calling code is running inside of. For example, popups, tabs,
+ // and infobars all have a containing browser, but background pages and
+ // notification bubbles do not.
+ //
+ // If there is no containing window, the current browser defaults to the
+ // foremost one.
+ //
+ // Incognito browsers are not considered unless the calling extension has
+ // incognito access enabled.
+ //
+ // This method can return NULL if there is no matching browser, which can
+ // happen if only incognito windows are open, or early in startup or shutdown
+ // shutdown when there are no active windows.
+ Browser* GetCurrentBrowser() {
+ return dispatcher()->GetCurrentBrowser(include_incognito_);
}
// The peer to the dispatcher that will service this extension function call.
diff --git a/chrome/browser/extensions/extension_function_dispatcher.cc b/chrome/browser/extensions/extension_function_dispatcher.cc
index 546205c..f436d27 100644
--- a/chrome/browser/extensions/extension_function_dispatcher.cc
+++ b/chrome/browser/extensions/extension_function_dispatcher.cc
@@ -8,6 +8,7 @@
#include "base/singleton.h"
#include "base/values.h"
#include "chrome/browser/browser.h"
+#include "chrome/browser/browser_list.h"
#include "chrome/browser/browser_window.h"
#include "chrome/browser/extensions/execute_code_in_tab_function.h"
#include "chrome/browser/extensions/extension_accessibility_api.h"
@@ -240,20 +241,6 @@ ExtensionFunction* FactoryRegistry::NewFunction(const std::string& name) {
}; // namespace
-// ExtensionFunctionDispatcher::Delegate ---------------------------------------
-
-gfx::NativeWindow ExtensionFunctionDispatcher::Delegate::
- GetFrameNativeWindow() {
- Browser* browser = GetBrowser(true);
- // If a browser is bound to this dispatcher, then return the widget hosting
- // the window. Extensions hosted in ExternalTabContainer objects may not
- // have a running browser instance.
- if (browser)
- return browser->window()->GetNativeHandle();
-
- return NULL;
-}
-
// ExtensionFunctionDispatcher -------------------------------------------------
void ExtensionFunctionDispatcher::GetAllFunctionNames(
@@ -328,16 +315,42 @@ ExtensionFunctionDispatcher::~ExtensionFunctionDispatcher() {
Details<ExtensionFunctionDispatcher>(this));
}
-Browser* ExtensionFunctionDispatcher::GetBrowser(bool include_incognito) {
- return delegate_->GetBrowser(include_incognito);
-}
+Browser* ExtensionFunctionDispatcher::GetCurrentBrowser(
+ bool include_incognito) {
+ Browser* browser = delegate_->GetBrowser();
-ExtensionHost* ExtensionFunctionDispatcher::GetExtensionHost() {
- return delegate_->GetExtensionHost();
-}
+ // If the delegate has an associated browser and that browser is in the right
+ // incognito state, we can return it.
+ if (browser) {
+ if (include_incognito || !browser->profile()->IsOffTheRecord())
+ return browser;
+ }
-ExtensionDOMUI* ExtensionFunctionDispatcher::GetExtensionDOMUI() {
- return delegate_->GetExtensionDOMUI();
+ // Otherwise, try to default to a reasonable browser.
+ Profile* profile = render_view_host()->process()->profile();
+
+ // Make sure we don't return an incognito browser without proper access.
+ if (!include_incognito)
+ profile = profile->GetOriginalProfile();
+
+ browser = BrowserList::GetLastActiveWithProfile(profile);
+
+ // It's possible for a browser to exist, but to have never been active.
+ // This can happen if you launch the browser on a machine without an active
+ // desktop (a headless buildbot) or if you quickly give another app focus
+ // at launch time. This is easy to do with browser_tests.
+ if (!browser)
+ browser = BrowserList::FindBrowserWithProfile(profile);
+
+ // TODO(erikkay): can this still return NULL? Is Rafael's comment still
+ // valid here?
+ // NOTE(rafaelw): This can return NULL in some circumstances. In particular,
+ // a toolstrip or 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;
}
Extension* ExtensionFunctionDispatcher::GetExtension() {
@@ -398,7 +411,3 @@ void ExtensionFunctionDispatcher::HandleBadMessage(ExtensionFunction* api) {
Profile* ExtensionFunctionDispatcher::profile() {
return profile_;
}
-
-gfx::NativeWindow ExtensionFunctionDispatcher::GetFrameNativeWindow() {
- return delegate_ ? delegate_->GetFrameNativeWindow() : NULL;
-}
diff --git a/chrome/browser/extensions/extension_function_dispatcher.h b/chrome/browser/extensions/extension_function_dispatcher.h
index 6fe4ba0..18cce3b 100644
--- a/chrome/browser/extensions/extension_function_dispatcher.h
+++ b/chrome/browser/extensions/extension_function_dispatcher.h
@@ -33,17 +33,20 @@ class ExtensionFunctionDispatcher {
public:
class Delegate {
public:
- // Returns the browser that this delegate is associated with. If the browser
- // is incognito, but |include_incognito_windows| is false, we fall back to
- // the toplevel browser in the original profile.
- virtual Browser* GetBrowser(bool include_incognito_windows) const = 0;
+ // Returns the browser that this delegate is associated with, if any.
+ // Returns NULL otherwise.
+ virtual Browser* GetBrowser() const = 0;
- // Returns the gfx::NativeWindow that contains the view hosting the
- // environment in which the function dispatcher resides.
- virtual gfx::NativeWindow GetFrameNativeWindow();
+ // Returns the native view for this extension view, if any. This may be NULL
+ // if the view is not visible.
+ virtual gfx::NativeView GetNativeViewOfHost() = 0;
- virtual ExtensionHost* GetExtensionHost() { return NULL; }
- virtual ExtensionDOMUI* GetExtensionDOMUI() { return NULL; }
+ // Typically, the window is assumed to be the window associated with the
+ // result of GetBrowser(). Implementations may override this behavior with
+ // this method.
+ virtual gfx::NativeWindow GetCustomFrameNativeWindow() {
+ return NULL;
+ }
protected:
virtual ~Delegate() {}
@@ -82,6 +85,8 @@ class ExtensionFunctionDispatcher {
const GURL& url);
~ExtensionFunctionDispatcher();
+ Delegate* delegate() { return delegate_; }
+
// Handle a request to execute an extension function.
void HandleRequest(const std::string& name, const Value* args,
int request_id, bool has_callback);
@@ -89,25 +94,13 @@ class ExtensionFunctionDispatcher {
// Send a response to a function.
void SendResponse(ExtensionFunction* api, bool success);
- // Gets the browser extension functions should operate relative to. For
- // example, for positioning windows, or alert boxes, or creating tabs.
- // If |include_incognito| is false, and the appropriate browser is incognito,
- // we will fall back to a regular browser window or NULL if unavailable.
- Browser* GetBrowser(bool include_incognito);
-
- // Gets the ExtensionHost associated with this object. In the case of
- // tab hosted extension pages, this will return NULL.
- ExtensionHost* GetExtensionHost();
-
- // Gets the ExtensionDOMUI associated with this object. In the case of
- // non-tab-hosted extension pages, this will return NULL.
- ExtensionDOMUI* GetExtensionDOMUI();
-
- // Returns the gfx::NativeWindow that frames the view of the extension
- // containing the function dispatcher. This may return NULL. Refer to the
- // ExtensionFunctionDispatcher::Delegate::GetFrameNativeWindow()
- // implementation for an explanation.
- gfx::NativeWindow GetFrameNativeWindow();
+ // Returns the current browser. Callers should generally prefer
+ // ExtensionFunction::GetCurrentBrowser() over this method, as that one
+ // provides the correct value for |include_incognito|.
+ //
+ // See the comments for ExtensionFunction::GetCurrentBrowser() for more
+ // details.
+ Browser* GetCurrentBrowser(bool include_incognito);
// Gets the extension the function is being invoked by. This should not ever
// return NULL.
diff --git a/chrome/browser/extensions/extension_host.cc b/chrome/browser/extensions/extension_host.cc
index 350c370..a57780b 100644
--- a/chrome/browser/extensions/extension_host.cc
+++ b/chrome/browser/extensions/extension_host.cc
@@ -22,6 +22,7 @@
#include "chrome/browser/dom_ui/dom_ui_factory.h"
#include "chrome/browser/extensions/extension_message_service.h"
#include "chrome/browser/extensions/extension_tabs_module.h"
+#include "chrome/browser/extensions/extensions_service.h"
#include "chrome/browser/in_process_webkit/dom_storage_context.h"
#include "chrome/browser/in_process_webkit/webkit_context.h"
#include "chrome/browser/message_box_handler.h"
@@ -547,14 +548,18 @@ void ExtensionHost::ShowCreatedWindow(int route_id,
const gfx::Rect& initial_pos,
bool user_gesture) {
TabContents* contents = delegate_view_helper_.GetCreatedWindow(route_id);
- if (contents) {
- Browser* browser = GetBrowser();
- DCHECK(browser);
- if (!browser)
- return;
- browser->AddTabContents(contents, disposition, initial_pos,
- user_gesture);
- }
+ if (!contents)
+ return;
+
+ Browser* browser = extension_function_dispatcher_->GetCurrentBrowser(
+ profile_->GetExtensionsService()->IsIncognitoEnabled(extension_));
+ if (!browser)
+ return;
+
+ // TODO(aa): It seems like this means popup windows don't work via
+ // window.open() from ExtensionHost?
+ browser->AddTabContents(contents, disposition, initial_pos,
+ user_gesture);
}
void ExtensionHost::ShowCreatedWidget(int route_id,
@@ -648,40 +653,6 @@ void ExtensionHost::HandleMouseLeave() {
#endif
}
-Browser* ExtensionHost::GetBrowser(bool include_incognito) const {
- Browser* browser = NULL;
-
- if (view_.get())
- browser = view_->browser();
-
- if (!browser ||
- (browser->profile()->IsOffTheRecord() && !include_incognito)) {
- Profile* profile = render_view_host()->process()->profile();
- // Make sure we don't return an incognito browser without proper access.
- if (!include_incognito)
- profile = profile->GetOriginalProfile();
-
- browser = BrowserList::GetLastActiveWithProfile(profile);
-
- // It's possible for a browser to exist, but to have never been active.
- // This can happen if you launch the browser on a machine without an active
- // desktop (a headless buildbot) or if you quickly give another app focus
- // at launch time. This is easy to do with browser_tests.
- if (!browser)
- browser = BrowserList::FindBrowserWithProfile(profile);
- }
-
- // TODO(erikkay): can this still return NULL? Is Rafael's comment still
- // valid here?
- // NOTE(rafaelw): This can return NULL in some circumstances. In particular,
- // a toolstrip or 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;
-}
-
void ExtensionHost::SetRenderViewType(ViewType::Type type) {
DCHECK(type == ViewType::EXTENSION_MOLE ||
type == ViewType::EXTENSION_TOOLSTRIP ||
diff --git a/chrome/browser/extensions/extension_host.h b/chrome/browser/extensions/extension_host.h
index 509bc1f..3ff7d87 100644
--- a/chrome/browser/extensions/extension_host.h
+++ b/chrome/browser/extensions/extension_host.h
@@ -77,9 +77,6 @@ class ExtensionHost : public RenderViewHostDelegate,
bool document_element_available() const {
return document_element_available_;
}
- gfx::NativeView GetNativeViewOfHost() {
- return view() ? view()->native_view() : NULL;
- }
Profile* profile() const { return profile_; }
@@ -200,14 +197,12 @@ class ExtensionHost : public RenderViewHostDelegate,
void CreateRenderViewNow();
// ExtensionFunctionDispatcher::Delegate
- // If this ExtensionHost has a view, this returns the Browser that view is a
- // part of. If this is a global background page, we use the active Browser
- // instead.
- virtual Browser* GetBrowser(bool include_incognito) const;
- virtual ExtensionHost* GetExtensionHost() { return this; }
-
- virtual Browser* GetBrowser() const { return GetBrowser(true); }
- virtual RenderViewHost* GetRenderViewHost() { return render_view_host(); }
+ virtual Browser* GetBrowser() const {
+ return view() ? view()->browser() : NULL;
+ }
+ virtual gfx::NativeView GetNativeViewOfHost() {
+ return view() ? view()->native_view() : NULL;
+ }
// Handles keyboard events that were not handled by HandleKeyboardEvent().
// Platform specific implementation may override this method to handle the
diff --git a/chrome/browser/extensions/extension_infobar_module.cc b/chrome/browser/extensions/extension_infobar_module.cc
index fb5b2ed..01eec16 100644
--- a/chrome/browser/extensions/extension_infobar_module.cc
+++ b/chrome/browser/extensions/extension_infobar_module.cc
@@ -29,7 +29,7 @@ bool ShowInfoBarFunction::RunImpl() {
Extension* extension = dispatcher()->GetExtension();
GURL url = extension->GetResourceURL(extension->url(), html_path);
- Browser* browser = dispatcher()->GetBrowser(true);
+ Browser* browser = dispatcher()->GetCurrentBrowser(true);
if (!browser) {
error_ = keys::kNoCurrentWindowError;
return false;
diff --git a/chrome/browser/extensions/extension_popup_api.cc b/chrome/browser/extensions/extension_popup_api.cc
index c475751..521acce 100644
--- a/chrome/browser/extensions/extension_popup_api.cc
+++ b/chrome/browser/extensions/extension_popup_api.cc
@@ -10,6 +10,7 @@
#include "chrome/browser/extensions/extension_host.h"
#include "chrome/browser/extensions/extension_message_service.h"
#include "chrome/browser/browser.h"
+#include "chrome/browser/browser_window.h"
#include "chrome/browser/profile.h"
#include "chrome/browser/tab_contents/tab_contents.h"
#include "chrome/common/extensions/extension.h"
@@ -112,10 +113,8 @@ class ExtensionPopupHost : public ExtensionPopup::Observer,
if (router)
router->UnregisterRenderViewHost(popup_->host()->render_view_host());
- RenderViewHost* render_view_host =
- GetRenderViewHostFromDispatcher(dispatcher_);
- PopupEventRouter::OnPopupClosed(dispatcher_->profile(),
- render_view_host->routing_id());
+ PopupEventRouter::OnPopupClosed(
+ dispatcher_->profile(), dispatcher_->render_view_host()->routing_id());
dispatcher_ = NULL;
Release(); // Balanced in ctor.
}
@@ -126,9 +125,8 @@ class ExtensionPopupHost : public ExtensionPopup::Observer,
// If no view is to be focused, then Chrome was deactivated, so hide the
// popup.
if (focused_now) {
- gfx::NativeView host_view = dispatcher_->GetExtensionHost() ?
- dispatcher_->GetExtensionHost()->GetNativeViewOfHost() :
- dispatcher_->GetExtensionDOMUI()->GetNativeViewOfHost();
+ gfx::NativeView host_view =
+ dispatcher_->delegate()->GetNativeViewOfHost();
// If the widget hosting the popup contains the newly focused view, then
// don't dismiss the pop-up.
@@ -165,22 +163,13 @@ class ExtensionPopupHost : public ExtensionPopup::Observer,
if (!dispatcher)
return NULL;
- RenderViewHost* render_view_host =
- GetRenderViewHostFromDispatcher(dispatcher);
+ RenderViewHost* render_view_host = dispatcher->render_view_host();
RenderViewHostDelegate* delegate =
render_view_host ? render_view_host->delegate() : NULL;
return delegate ? delegate->GetAutomationResourceRoutingDelegate() : NULL;
}
- // Returns the RenderViewHost associated with |dispatcher|.
- static RenderViewHost* GetRenderViewHostFromDispatcher(
- ExtensionFunctionDispatcher* dispatcher) {
- return dispatcher->GetExtensionHost() ?
- dispatcher->GetExtensionHost()->render_view_host() :
- dispatcher->GetExtensionDOMUI()->GetRenderViewHost();
- }
-
// A pointer to the dispatcher that handled the request that opened this
// popup view.
ExtensionFunctionDispatcher* dispatcher_;
@@ -285,24 +274,38 @@ bool PopupShowFunction::RunImpl() {
#if defined(TOOLKIT_VIEWS)
gfx::Point origin(dom_left, dom_top);
- if (!ConvertHostPointToScreen(&origin)) {
+ if (!dispatcher()->render_view_host()->view()) {
error_ = kNotAnExtension;
return false;
}
+
+ gfx::Rect content_bounds =
+ dispatcher()->render_view_host()->view()->GetViewBounds();
+ origin.Offset(content_bounds.x(), content_bounds.y());
gfx::Rect rect(origin.x(), origin.y(), dom_width, dom_height);
// Pop-up from extension views (ExtensionShelf, etc.), and drop-down when
// in a TabContents view.
+ ViewType::Type view_type =
+ dispatcher()->render_view_host()->delegate()->GetRenderViewType();
BubbleBorder::ArrowLocation arrow_location =
- (NULL != dispatcher()->GetExtensionHost()) ? BubbleBorder::BOTTOM_LEFT :
- BubbleBorder::TOP_LEFT;
+ view_type == ViewType::TAB_CONTENTS ?
+ BubbleBorder::TOP_LEFT : BubbleBorder::BOTTOM_LEFT;
+
+ // Get the correct native window to pass to ExtensionPopup.
+ // ExtensionFunctionDispatcher::Delegate may provide a custom implementation
+ // of this.
+ gfx::NativeWindow window =
+ dispatcher()->delegate()->GetCustomFrameNativeWindow();
+ if (!window)
+ window = GetCurrentBrowser()->window()->GetNativeHandle();
// ExtensionPopupHost manages it's own lifetime.
ExtensionPopupHost* popup_host = new ExtensionPopupHost(dispatcher());
popup_ = ExtensionPopup::Show(url,
- GetBrowser(),
+ GetCurrentBrowser(),
dispatcher()->profile(),
- dispatcher()->GetFrameNativeWindow(),
+ window,
rect,
arrow_location,
give_focus,
@@ -318,41 +321,6 @@ bool PopupShowFunction::RunImpl() {
return true;
}
-bool PopupShowFunction::ConvertHostPointToScreen(gfx::Point* point) {
- DCHECK(point);
-
- // If the popup is being requested from an ExtensionHost, then compute
- // the sreen coordinates based on the views::View object of the ExtensionHost.
- if (dispatcher()->GetExtensionHost()) {
- // A dispatcher cannot have both an ExtensionHost, and an ExtensionDOMUI.
- DCHECK(!dispatcher()->GetExtensionDOMUI());
-
-#if defined(TOOLKIT_VIEWS)
- views::View* extension_view = dispatcher()->GetExtensionHost()->view();
- if (!extension_view)
- return false;
-
- views::View::ConvertPointToScreen(extension_view, point);
-#else
- // TODO(port)
- NOTIMPLEMENTED();
-#endif // defined(TOOLKIT_VIEWS)
- } else if (dispatcher()->GetExtensionDOMUI()) {
- // Otherwise, the popup is being requested from a TabContents, so determine
- // the screen-space position through the TabContentsView.
- ExtensionDOMUI* dom_ui = dispatcher()->GetExtensionDOMUI();
- TabContents* tab_contents = dom_ui->tab_contents();
- if (!tab_contents)
- return false;
-
- gfx::Rect content_bounds;
- tab_contents->GetContainerBounds(&content_bounds);
- point->Offset(content_bounds.x(), content_bounds.y());
- }
-
- return true;
-}
-
void PopupShowFunction::Observe(NotificationType type,
const NotificationSource& source,
const NotificationDetails& details) {
diff --git a/chrome/browser/extensions/extension_popup_api.h b/chrome/browser/extensions/extension_popup_api.h
index 9132de1..7550407 100644
--- a/chrome/browser/extensions/extension_popup_api.h
+++ b/chrome/browser/extensions/extension_popup_api.h
@@ -28,10 +28,6 @@ class PopupShowFunction : public AsyncExtensionFunction,
DECLARE_EXTENSION_FUNCTION_NAME("experimental.popup.show")
private:
- // Computes the screen-space position of the frame-relative point in the
- // extension view that is requesting to display a popup.
- bool ConvertHostPointToScreen(gfx::Point* point);
-
// NotificationObserver methods.
virtual void Observe(NotificationType type,
const NotificationSource& source,
diff --git a/chrome/browser/extensions/extension_tabs_module.cc b/chrome/browser/extensions/extension_tabs_module.cc
index 3d1ee4b..8afc4be 100644
--- a/chrome/browser/extensions/extension_tabs_module.cc
+++ b/chrome/browser/extensions/extension_tabs_module.cc
@@ -234,7 +234,7 @@ bool GetWindowFunction::RunImpl() {
}
bool GetCurrentWindowFunction::RunImpl() {
- Browser* browser = GetBrowser();
+ Browser* browser = GetCurrentBrowser();
if (!browser) {
error_ = keys::kNoCurrentWindowError;
return false;
@@ -312,10 +312,10 @@ bool CreateWindowFunction::RunImpl() {
// The call offsets the bounds by kWindowTilePixels (defined in WindowSizer to
// be 10)
//
- // NOTE(rafaelw): It's ok if dispatcher_->GetBrowser() returns NULL here.
+ // NOTE(rafaelw): It's ok if GetCurrentBrowser() returns NULL here.
// GetBrowserWindowBounds will default to saved "default" values for the app.
WindowSizer::GetBrowserWindowBounds(std::wstring(), empty_bounds,
- GetBrowser(), &bounds,
+ GetCurrentBrowser(), &bounds,
&maximized);
Profile* window_profile = profile();
@@ -468,7 +468,7 @@ bool GetSelectedTabFunction::RunImpl() {
browser = GetBrowserInProfileWithId(profile(), window_id,
include_incognito(), &error_);
} else {
- browser = GetBrowser();
+ browser = GetCurrentBrowser();
if (!browser)
error_ = keys::kNoCurrentWindowError;
}
@@ -495,7 +495,7 @@ bool GetAllTabsInWindowFunction::RunImpl() {
browser = GetBrowserInProfileWithId(profile(), window_id,
include_incognito(), &error_);
} else {
- browser = GetBrowser();
+ browser = GetCurrentBrowser();
if (!browser)
error_ = keys::kNoCurrentWindowError;
}
@@ -520,7 +520,7 @@ bool CreateTabFunction::RunImpl() {
browser = GetBrowserInProfileWithId(profile(), window_id,
include_incognito(), &error_);
} else {
- browser = GetBrowser();
+ browser = GetCurrentBrowser();
if (!browser)
error_ = keys::kNoCurrentWindowError;
}
@@ -792,7 +792,7 @@ bool CaptureVisibleTabFunction::RunImpl() {
browser = GetBrowserInProfileWithId(profile(), window_id,
include_incognito(), &error_);
} else {
- browser = GetBrowser();
+ browser = GetCurrentBrowser();
}
if (!browser) {
@@ -910,7 +910,7 @@ bool DetectTabLanguageFunction::RunImpl() {
if (!browser || !contents)
return false;
} else {
- browser = GetBrowser();
+ browser = GetCurrentBrowser();
if (!browser)
return false;
contents = browser->tabstrip_model()->GetSelectedTabContents();
diff --git a/chrome/browser/extensions/extension_toolstrip_api.cc b/chrome/browser/extensions/extension_toolstrip_api.cc
index 56ad0a2..a858150 100644
--- a/chrome/browser/extensions/extension_toolstrip_api.cc
+++ b/chrome/browser/extensions/extension_toolstrip_api.cc
@@ -12,6 +12,7 @@
#include "chrome/browser/extensions/extension_shelf_model.h"
#include "chrome/browser/extensions/extension_tabs_module_constants.h"
#include "chrome/browser/profile.h"
+#include "chrome/browser/renderer_host/render_view_host.h"
namespace extension_toolstrip_api_events {
const char kOnToolstripExpanded[] = "toolstrip.onExpanded.%d";
@@ -35,26 +36,36 @@ namespace keys = extension_tabs_module_constants;
namespace events = extension_toolstrip_api_events;
bool ToolstripFunction::RunImpl() {
- ExtensionHost* host = dispatcher()->GetExtensionHost();
- if (!host) {
+ ViewType::Type view_type =
+ dispatcher()->render_view_host()->delegate()->GetRenderViewType();
+ if (view_type != ViewType::EXTENSION_TOOLSTRIP &&
+ view_type != ViewType::EXTENSION_MOLE) {
error_ = kNotAToolstripError;
return false;
}
- Browser* browser = GetBrowser();
+
+ Browser* browser = GetCurrentBrowser();
if (!browser) {
error_ = kNotAToolstripError;
return false;
}
+
model_ = browser->extension_shelf_model();
if (!model_) {
error_ = kNotAToolstripError;
return false;
}
+
+ // Since this is an EXTENSION_TOOLSTRIP or EXTESION_MOLE view type, we know
+ // the delegate must be an ExtensionHost.
+ ExtensionHost* host =
+ static_cast<ExtensionHost*>(dispatcher()->delegate());
toolstrip_ = model_->ToolstripForHost(host);
if (toolstrip_ == model_->end()) {
error_ = kNotAToolstripError;
return false;
}
+
return true;
}
diff --git a/chrome/browser/extensions/extensions_ui.cc b/chrome/browser/extensions/extensions_ui.cc
index 1575577..9c2fc3b 100644
--- a/chrome/browser/extensions/extensions_ui.cc
+++ b/chrome/browser/extensions/extensions_ui.cc
@@ -806,10 +806,10 @@ std::vector<ExtensionPage> ExtensionsDOMHandler::GetActivePagesForExtension(
// because clicking the link would cause the popup to loose focus and
// close. Instead, we display text that tells the developer to
// right-click on popups to inspect them.
- if ((*iter)->GetExtensionHost() &&
- (ViewType::EXTENSION_POPUP ==
- (*iter)->GetExtensionHost()->extension_host_type()))
+ if (ViewType::EXTENSION_POPUP ==
+ (*iter)->render_view_host()->delegate()->GetRenderViewType()) {
continue;
+ }
result.push_back(ExtensionPage((*iter)->url(),
view->process()->id(),