summaryrefslogtreecommitdiffstats
path: root/chrome/browser/extensions/extension_popup_api.cc
diff options
context:
space:
mode:
authortwiz@google.com <twiz@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2009-12-08 04:28:58 +0000
committertwiz@google.com <twiz@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2009-12-08 04:28:58 +0000
commitbf7e9637d7935075e56bd3d15df864f78312df53 (patch)
tree30ee46ce46c99585a43f9dc06788e69772f18bd1 /chrome/browser/extensions/extension_popup_api.cc
parente36ddc88da9374cfa6853101b2b81eb20a081026 (diff)
downloadchromium_src-bf7e9637d7935075e56bd3d15df864f78312df53.zip
chromium_src-bf7e9637d7935075e56bd3d15df864f78312df53.tar.gz
chromium_src-bf7e9637d7935075e56bd3d15df864f78312df53.tar.bz2
Addition of a new parameter to the popup.show(...) Chrome extension API that allows the caller to specify the behaviour of the window focus when the pop-up is displayed.
I added a test for the new parameter in the ExtensionApiTest.FLAKY_Popup test. I also corrected a truncated string in the unit-test. Because the pop-up actually uses two windows, I had to change the WidgetWin::Show() routine to also reposition the window at the top. If a window is shown and activated, it is automatically brought to the front. Because we don't activate the pop-up when we want to keep the focus in the current extension view, I had to bring it to the front so that it wouldn't be hidden behind the 'chrome-bubble' window. BUG=none TEST=ExtensionApiTest.FLAKY_Popup Review URL: http://codereview.chromium.org/454019 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@34037 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/extensions/extension_popup_api.cc')
-rw-r--r--chrome/browser/extensions/extension_popup_api.cc17
1 files changed, 15 insertions, 2 deletions
diff --git a/chrome/browser/extensions/extension_popup_api.cc b/chrome/browser/extensions/extension_popup_api.cc
index f778e0e..091fa71 100644
--- a/chrome/browser/extensions/extension_popup_api.cc
+++ b/chrome/browser/extensions/extension_popup_api.cc
@@ -42,6 +42,8 @@ const wchar_t kWidthKey[] = L"width";
const wchar_t kHeightKey[] = L"height";
const wchar_t kTopKey[] = L"top";
const wchar_t kLeftKey[] = L"left";
+const wchar_t kGiveFocusKey[] = L"giveFocus";
+const wchar_t kDomAnchorKey[] = L"domAnchor";
}; // namespace
@@ -81,8 +83,12 @@ bool PopupShowFunction::RunImpl() {
std::string url_string;
EXTENSION_FUNCTION_VALIDATE(args->GetString(0, &url_string));
+ DictionaryValue* show_details = NULL;
+ EXTENSION_FUNCTION_VALIDATE(args->GetDictionary(1, &show_details));
+
DictionaryValue* dom_anchor = NULL;
- EXTENSION_FUNCTION_VALIDATE(args->GetDictionary(1, &dom_anchor));
+ EXTENSION_FUNCTION_VALIDATE(show_details->GetDictionary(kDomAnchorKey,
+ &dom_anchor));
int dom_top, dom_left;
EXTENSION_FUNCTION_VALIDATE(dom_anchor->GetInteger(kTopKey,
@@ -98,6 +104,13 @@ bool PopupShowFunction::RunImpl() {
EXTENSION_FUNCTION_VALIDATE(dom_top >= 0 && dom_left >= 0 &&
dom_width >= 0 && dom_height >= 0);
+ // The default behaviour is to give the focus to the pop-up window.
+ bool give_focus = true;
+ if (show_details->HasKey(kGiveFocusKey)) {
+ EXTENSION_FUNCTION_VALIDATE(show_details->GetBoolean(kGiveFocusKey,
+ &give_focus));
+ }
+
GURL url = dispatcher()->url().Resolve(url_string);
if (!url.is_valid()) {
error_ = kInvalidURLError;
@@ -127,7 +140,7 @@ bool PopupShowFunction::RunImpl() {
(NULL != dispatcher()->GetExtensionHost()) ? BubbleBorder::BOTTOM_LEFT :
BubbleBorder::TOP_LEFT;
popup_ = ExtensionPopup::Show(url, dispatcher()->GetBrowser(), rect,
- arrow_location);
+ arrow_location, give_focus);
ExtensionPopupHost* popup_host = dispatcher()->GetPopupHost();
DCHECK(popup_host);