diff options
author | cindylau@google.com <cindylau@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-11-22 17:39:45 +0000 |
---|---|---|
committer | cindylau@google.com <cindylau@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-11-22 17:39:45 +0000 |
commit | 0fbc0a5777c35175ff7307ca81fcb4b0add8809b (patch) | |
tree | b1f7ad98162e76a74df183ecfa970f7e4c36c7e0 | |
parent | 6d3e1344b8ba529e4f51cbeceb4ab2edd291d48e (diff) | |
download | chromium_src-0fbc0a5777c35175ff7307ca81fcb4b0add8809b.zip chromium_src-0fbc0a5777c35175ff7307ca81fcb4b0add8809b.tar.gz chromium_src-0fbc0a5777c35175ff7307ca81fcb4b0add8809b.tar.bz2 |
Add the associated tab contents to automation messages for extension API calls. This
will allow automation clients to know which tab generated each API call.
BUG=none
TEST=ui_tests.exe
Review URL: http://codereview.chromium.org/5222004
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@66963 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r-- | chrome/browser/automation/automation_extension_function.cc | 13 | ||||
-rw-r--r-- | chrome/browser/extensions/extension_uitest.cc | 13 |
2 files changed, 26 insertions, 0 deletions
diff --git a/chrome/browser/automation/automation_extension_function.cc b/chrome/browser/automation/automation_extension_function.cc index 2e72c6b..7f46e3e 100644 --- a/chrome/browser/automation/automation_extension_function.cc +++ b/chrome/browser/automation/automation_extension_function.cc @@ -11,6 +11,7 @@ #include "base/values.h" #include "chrome/browser/automation/extension_automation_constants.h" #include "chrome/browser/extensions/extension_function_dispatcher.h" +#include "chrome/browser/extensions/extension_tabs_module.h" #include "chrome/browser/renderer_host/render_view_host.h" #include "chrome/browser/renderer_host/render_view_host_delegate.h" #include "chrome/browser/tab_contents/tab_contents.h" @@ -51,6 +52,18 @@ bool AutomationExtensionFunction::RunImpl() { message_to_host.SetString(keys::kAutomationArgsKey, args_); message_to_host.SetInteger(keys::kAutomationRequestIdKey, request_id_); message_to_host.SetBoolean(keys::kAutomationHasCallbackKey, has_callback_); + // Send the API request's associated tab along to the automation client, so + // that it can determine the execution context of the API call. + TabContents* contents = NULL; + ExtensionFunctionDispatcher* function_dispatcher = dispatcher(); + if (function_dispatcher && function_dispatcher->delegate()) { + contents = function_dispatcher->delegate()->associated_tab_contents(); + } else { + NOTREACHED() << "Extension function dispatcher delegate not found."; + } + if (contents) + message_to_host.Set(keys::kAutomationTabJsonKey, + ExtensionTabUtil::CreateTabValue(contents)); std::string message; base::JSONWriter::Write(&message_to_host, false, &message); diff --git a/chrome/browser/extensions/extension_uitest.cc b/chrome/browser/extensions/extension_uitest.cc index 8688806..bc25d75 100644 --- a/chrome/browser/extensions/extension_uitest.cc +++ b/chrome/browser/extensions/extension_uitest.cc @@ -168,6 +168,14 @@ TEST_F(ExtensionTestSimpleApiCall, FLAKY_RunTest) { EXPECT_TRUE(message_dict->GetBoolean(keys::kAutomationHasCallbackKey, &has_callback)); EXPECT_FALSE(has_callback); + DictionaryValue* associated_tab = NULL; + EXPECT_TRUE(message_dict->GetDictionary(keys::kAutomationTabJsonKey, + &associated_tab)); + std::string associated_tab_url; + EXPECT_TRUE(associated_tab->GetString( + extension_tabs_module_constants::kUrlKey, &associated_tab_url)); + EXPECT_EQ("chrome-extension://pmgpglkggjdpkpghhdmbdhababjpcohk/test.html", + associated_tab_url); } // A test that loads a basic extension that makes an API call that does @@ -209,6 +217,11 @@ public: bool has_callback = false; EXPECT_TRUE(request_dict->GetBoolean(keys::kAutomationHasCallbackKey, &has_callback)); + // The API requests in this extension come from the background page, so + // the tab is not set. + DictionaryValue* associated_tab = NULL; + EXPECT_FALSE(request_dict->GetDictionary(keys::kAutomationTabJsonKey, + &associated_tab)); if (messages_received_ == 1) { EXPECT_EQ("tabs.getSelected", function_name); |