summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authornirnimesh@chromium.org <nirnimesh@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-08-22 05:50:05 +0000
committernirnimesh@chromium.org <nirnimesh@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-08-22 05:50:05 +0000
commit2d3806a4dec058f2193a8e42dc6b86e66860fc57 (patch)
tree142abd065fb91d4f7e7011f27b893171a6882500
parentd7abd05db588e8c35e4858e1fe74754b21986c86 (diff)
downloadchromium_src-2d3806a4dec058f2193a8e42dc6b86e66860fc57.zip
chromium_src-2d3806a4dec058f2193a8e42dc6b86e66860fc57.tar.gz
chromium_src-2d3806a4dec058f2193a8e42dc6b86e66860fc57.tar.bz2
Revert 97569 - Add the functionality to inject JavaScript into ExtensionHosts.
Reverting because it's causing wholesale failure in pyauto_functional_tests, chromedriver_tests and webdriver_tests across all platforms: See http://build.chromium.org/p/chromium.pyauto/builders/Linux%20%28deb%29/builds/18178/ BUG=chromium-os:17902 TEST= Review URL: http://codereview.chromium.org/7637020 TBR=frankf@chromium.org Review URL: http://codereview.chromium.org/7694024 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@97607 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--chrome/browser/automation/automation_provider.cc2
-rw-r--r--chrome/browser/automation/automation_provider_observers.cc28
-rw-r--r--chrome/browser/automation/automation_provider_observers.h3
-rw-r--r--chrome/browser/automation/testing_automation_provider.cc134
-rw-r--r--chrome/browser/automation/testing_automation_provider.h16
-rw-r--r--chrome/test/data/extensions/js_injection_background/bg.html5
-rw-r--r--chrome/test/data/extensions/js_injection_background/manifest.json10
-rw-r--r--chrome/test/functional/execute_javascript.py32
-rw-r--r--chrome/test/functional/memory.py2
-rw-r--r--chrome/test/pyautolib/pyauto.py47
10 files changed, 36 insertions, 243 deletions
diff --git a/chrome/browser/automation/automation_provider.cc b/chrome/browser/automation/automation_provider.cc
index 9d5d834..eeaf263 100644
--- a/chrome/browser/automation/automation_provider.cc
+++ b/chrome/browser/automation/automation_provider.cc
@@ -782,7 +782,6 @@ void AutomationProvider::InstallExtension(
// The observer will delete itself when done.
new ExtensionReadyNotificationObserver(
manager,
- service,
this,
AutomationMsg_InstallExtension::ID,
reply_message);
@@ -828,7 +827,6 @@ void AutomationProvider::EnableExtension(int extension_handle,
// The observer will delete itself when done.
new ExtensionReadyNotificationObserver(
manager,
- service,
this,
AutomationMsg_EnableExtension::ID,
reply_message);
diff --git a/chrome/browser/automation/automation_provider_observers.cc b/chrome/browser/automation/automation_provider_observers.cc
index 3048a68..3f2a306 100644
--- a/chrome/browser/automation/automation_provider_observers.cc
+++ b/chrome/browser/automation/automation_provider_observers.cc
@@ -28,7 +28,6 @@
#include "chrome/browser/extensions/crx_installer.h"
#include "chrome/browser/extensions/extension_host.h"
#include "chrome/browser/extensions/extension_process_manager.h"
-#include "chrome/browser/extensions/extension_service.h"
#include "chrome/browser/extensions/extension_tabs_module.h"
#include "chrome/browser/extensions/extension_updater.h"
#include "chrome/browser/history/history_types.h"
@@ -68,7 +67,6 @@
#include "content/browser/renderer_host/render_view_host.h"
#include "content/browser/tab_contents/navigation_controller.h"
#include "content/browser/tab_contents/tab_contents.h"
-#include "content/common/json_value_serializer.h"
#include "content/common/notification_service.h"
#include "googleurl/src/gurl.h"
#include "ui/gfx/codec/png_codec.h"
@@ -525,10 +523,9 @@ void ExtensionUninstallObserver::Observe(
}
ExtensionReadyNotificationObserver::ExtensionReadyNotificationObserver(
- ExtensionProcessManager* manager, ExtensionService* service,
- AutomationProvider* automation, int id, IPC::Message* reply_message)
+ ExtensionProcessManager* manager, AutomationProvider* automation, int id,
+ IPC::Message* reply_message)
: manager_(manager),
- service_(service),
automation_(automation->AsWeakPtr()),
id_(id),
reply_message_(reply_message),
@@ -565,12 +562,6 @@ void ExtensionReadyNotificationObserver::Observe(
extension_ = Details<const Extension>(details).ptr();
if (!DidExtensionHostsStopLoading(manager_))
return;
- // For some reason, the background ExtensionHost is not yet
- // created at this point so just checking whether all ExtensionHosts
- // are loaded is not sufficient. If background page is not ready,
- // we wait for NOTIFICATION_EXTENSION_HOST_DID_STOP_LOADING.
- if(!service_->IsBackgroundPageReady(extension_))
- return;
break;
case chrome::NOTIFICATION_EXTENSION_INSTALL_ERROR:
case chrome::NOTIFICATION_EXTENSION_UPDATE_DISABLED:
@@ -1149,20 +1140,7 @@ void DomOperationMessageSender::OnDomOperationCompleted(
if (automation_) {
if (use_json_interface_) {
DictionaryValue dict;
- // Wrap |json| in an array before deserializing because valid JSON has an
- // array or an object as the root.
- std::string new_json(json);
- new_json.insert(0, "[");
- new_json.append("]");
- JSONStringValueSerializer deserializer(new_json);
- Value* root = deserializer.Deserialize(NULL, NULL);
- DCHECK(root);
-
- Value* value = NULL;
- DCHECK(root->IsType(Value::TYPE_LIST));
- static_cast<ListValue*>(root)->Get(0, &value);
- DCHECK(value);
- dict.Set("result", value);
+ dict.SetString("result", json);
AutomationJSONReply(automation_, reply_message_.release())
.SendSuccess(&dict);
} else {
diff --git a/chrome/browser/automation/automation_provider_observers.h b/chrome/browser/automation/automation_provider_observers.h
index f7358d7..d6054b8 100644
--- a/chrome/browser/automation/automation_provider_observers.h
+++ b/chrome/browser/automation/automation_provider_observers.h
@@ -57,7 +57,6 @@ class BalloonCollection;
class Browser;
class Extension;
class ExtensionProcessManager;
-class ExtensionService;
class NavigationController;
class Profile;
class RenderViewHost;
@@ -314,7 +313,6 @@ class ExtensionUninstallObserver : public NotificationObserver {
class ExtensionReadyNotificationObserver : public NotificationObserver {
public:
ExtensionReadyNotificationObserver(ExtensionProcessManager* manager,
- ExtensionService* service,
AutomationProvider* automation,
int id,
IPC::Message* reply_message);
@@ -328,7 +326,6 @@ class ExtensionReadyNotificationObserver : public NotificationObserver {
private:
NotificationRegistrar registrar_;
ExtensionProcessManager* manager_;
- ExtensionService* service_;
base::WeakPtr<AutomationProvider> automation_;
int id_;
scoped_ptr<IPC::Message> reply_message_;
diff --git a/chrome/browser/automation/testing_automation_provider.cc b/chrome/browser/automation/testing_automation_provider.cc
index 233cc0e..48cc884 100644
--- a/chrome/browser/automation/testing_automation_provider.cc
+++ b/chrome/browser/automation/testing_automation_provider.cc
@@ -45,9 +45,7 @@
#include "chrome/browser/debugger/devtools_window.h"
#include "chrome/browser/download/download_prefs.h"
#include "chrome/browser/download/save_package_file_picker.h"
-#include "chrome/browser/extensions/extension_browser_event_router.h"
#include "chrome/browser/extensions/extension_host.h"
-#include "chrome/browser/extensions/extension_process_manager.h"
#include "chrome/browser/extensions/extension_service.h"
#include "chrome/browser/extensions/extension_updater.h"
#include "chrome/browser/history/top_sites.h"
@@ -106,7 +104,6 @@
#include "content/browser/tab_contents/interstitial_page.h"
#include "content/common/common_param_traits.h"
#include "content/common/notification_service.h"
-#include "content/common/view_types.h"
#include "net/base/cookie_store.h"
#include "third_party/WebKit/Source/WebKit/chromium/public/WebInputEvent.h"
#include "ui/base/events.h"
@@ -1294,30 +1291,6 @@ void TestingAutomationProvider::GetFullscreenBubbleVisibility(int handle,
}
}
-namespace {
-
-void ExecuteJavascriptInRenderViewFrame(
- const string16& frame_xpath,
- const string16& script,
- IPC::Message* reply_message,
- RenderViewHost* render_view_host) {
- // Set the routing id of this message with the controller.
- // This routing id needs to be remembered for the reverse
- // communication while sending back the response of
- // this javascript execution.
- std::string set_automation_id;
- base::SStringPrintf(&set_automation_id,
- "window.domAutomationController.setAutomationId(%d);",
- reply_message->routing_id());
-
- render_view_host->ExecuteJavascriptInWebFrame(
- frame_xpath, UTF8ToUTF16(set_automation_id));
- render_view_host->ExecuteJavascriptInWebFrame(
- frame_xpath, script);
-}
-
-} // namespace
-
void TestingAutomationProvider::ExecuteJavascript(
int handle,
const std::wstring& frame_xpath,
@@ -1330,10 +1303,20 @@ void TestingAutomationProvider::ExecuteJavascript(
return;
}
+ // Set the routing id of this message with the controller.
+ // This routing id needs to be remembered for the reverse
+ // communication while sending back the response of
+ // this javascript execution.
+ std::string set_automation_id;
+ base::SStringPrintf(&set_automation_id,
+ "window.domAutomationController.setAutomationId(%d);",
+ reply_message->routing_id());
+
new DomOperationMessageSender(this, reply_message, false);
- ExecuteJavascriptInRenderViewFrame(WideToUTF16Hack(frame_xpath),
- WideToUTF16Hack(script), reply_message,
- tab_contents->render_view_host());
+ tab_contents->render_view_host()->ExecuteJavascriptInWebFrame(
+ WideToUTF16Hack(frame_xpath), UTF8ToUTF16(set_automation_id));
+ tab_contents->render_view_host()->ExecuteJavascriptInWebFrame(
+ WideToUTF16Hack(frame_xpath), WideToUTF16Hack(script));
}
void TestingAutomationProvider::GetConstrainedWindowCount(int handle,
@@ -2181,8 +2164,6 @@ void TestingAutomationProvider::SendJSONRequest(int handle,
&TestingAutomationProvider::NavigateToURL;
handler_map["ExecuteJavascript"] =
&TestingAutomationProvider::ExecuteJavascriptJSON;
- handler_map["ExecuteJavascriptInRenderView"] =
- &TestingAutomationProvider::ExecuteJavascriptInRenderView;
handler_map["GoForward"] =
&TestingAutomationProvider::GoForward;
handler_map["GoBack"] =
@@ -2790,7 +2771,7 @@ void TestingAutomationProvider::GetBrowserInfo(
// Add all extension processes in a list of dictionaries, one dictionary
// item per extension process.
- ListValue* extension_views = new ListValue;
+ ListValue* extension_processes = new ListValue;
ProfileManager* profile_manager = g_browser_process->profile_manager();
std::vector<Profile*> profiles(profile_manager->GetLoadedProfiles());
for (size_t i = 0; i < profiles.size(); ++i) {
@@ -2806,43 +2787,13 @@ void TestingAutomationProvider::GetBrowserInfo(
continue;
DictionaryValue* item = new DictionaryValue;
item->SetString("name", ex_host->extension()->name());
- item->SetString("extension_id", ex_host->extension()->id());
item->SetInteger(
"pid",
base::GetProcId(ex_host->render_process_host()->GetHandle()));
- DictionaryValue* view = new DictionaryValue;
- view->SetInteger(
- "render_process_id",
- ex_host->render_process_host()->id());
- view->SetInteger(
- "render_view_id",
- ex_host->render_view_host()->routing_id());
- item->Set("view", view);
- std::string type;
- switch (ex_host->extension_host_type()) {
- case ViewType::EXTENSION_BACKGROUND_PAGE:
- type = "EXTENSION_BACKGROUND_PAGE";
- break;
- case ViewType::EXTENSION_POPUP:
- type = "EXTENSION_POPUP";
- break;
- case ViewType::EXTENSION_INFOBAR:
- type = "EXTENSION_INFOBAR";
- break;
- case ViewType::EXTENSION_DIALOG:
- type = "EXTENSION_DIALOG";
- break;
- default:
- type = "unknown";
- break;
- }
- item->SetString("view_type", type);
- item->SetString("url", ex_host->GetURL().spec());
- item->SetBoolean("loaded", ex_host->did_stop_loading());
- extension_views->Append(item);
+ extension_processes->Append(item);
}
}
- return_value->Set("extension_views", extension_views);
+ return_value->Set("extension_processes", extension_processes);
AutomationJSONReply(this, reply_message).SendSuccess(return_value.get());
}
@@ -5784,49 +5735,20 @@ void TestingAutomationProvider::ExecuteJavascriptJSON(
return;
}
- new DomOperationMessageSender(this, reply_message, true);
- ExecuteJavascriptInRenderViewFrame(frame_xpath, javascript, reply_message,
- tab_contents->render_view_host());
-}
-
-void TestingAutomationProvider::ExecuteJavascriptInRenderView(
- DictionaryValue* args,
- IPC::Message* reply_message) {
- string16 frame_xpath, javascript, extension_id, url_text;
- std::string error;
- int render_process_id, render_view_id;
- if (!args->GetString("frame_xpath", &frame_xpath)) {
- AutomationJSONReply(this, reply_message)
- .SendError("'frame_xpath' missing or invalid");
- return;
- }
- if (!args->GetString("javascript", &javascript)) {
- AutomationJSONReply(this, reply_message)
- .SendError("'javascript' missing or invalid");
- return;
- }
- if (!args->GetInteger("view.render_process_id", &render_process_id)) {
- AutomationJSONReply(this, reply_message)
- .SendError("'view.render_process_id' missing or invalid");
- return;
- }
- if (!args->GetInteger("view.render_view_id", &render_view_id)) {
- AutomationJSONReply(this, reply_message)
- .SendError("'view.render_view_id' missing or invalid");
- return;
- }
-
- RenderViewHost* rvh = RenderViewHost::FromID(render_process_id,
- render_view_id);
- if(!rvh) {
- AutomationJSONReply(this, reply_message).SendError(
- "A RenderViewHost object was not found with the given view ID.");
- return;
- }
+ // Set the routing id of this message with the controller.
+ // This routing id needs to be remembered for the reverse
+ // communication while sending back the response of
+ // this javascript execution.
+ std::string set_automation_id;
+ base::SStringPrintf(&set_automation_id,
+ "window.domAutomationController.setAutomationId(%d);",
+ reply_message->routing_id());
new DomOperationMessageSender(this, reply_message, true);
- ExecuteJavascriptInRenderViewFrame(frame_xpath, javascript, reply_message,
- rvh);
+ tab_contents->render_view_host()->ExecuteJavascriptInWebFrame(
+ frame_xpath, UTF8ToUTF16(set_automation_id));
+ tab_contents->render_view_host()->ExecuteJavascriptInWebFrame(
+ frame_xpath, javascript);
}
void TestingAutomationProvider::GoForward(
diff --git a/chrome/browser/automation/testing_automation_provider.h b/chrome/browser/automation/testing_automation_provider.h
index 653e1a4..fbd486c 100644
--- a/chrome/browser/automation/testing_automation_provider.h
+++ b/chrome/browser/automation/testing_automation_provider.h
@@ -884,22 +884,6 @@ class TestingAutomationProvider : public AutomationProvider,
void ExecuteJavascriptJSON(
base::DictionaryValue* args, IPC::Message* reply_message);
- // Executes javascript in the specified frame of a render view.
- // Uses the JSON interface. Waits for a result from the
- // |DOMAutomationController|. The javascript must send a string.
- // Example:
- // input: { "view": {
- // "render_process_id": 1,
- // "render_view_id": 2,
- // }
- // "frame_xpath": "//frames[1]",
- // "javascript":
- // "window.domAutomationController.send(window.name)",
- // }
- // output: { "result": "My Window Name" }
- void ExecuteJavascriptInRenderView(
- base::DictionaryValue* args, IPC::Message* reply_message);
-
// Goes forward in the specified tab. Uses the JSON interface.
// Example:
// input: { "windex": 1, "tab_index": 1 }
diff --git a/chrome/test/data/extensions/js_injection_background/bg.html b/chrome/test/data/extensions/js_injection_background/bg.html
deleted file mode 100644
index 3daf384..0000000
--- a/chrome/test/data/extensions/js_injection_background/bg.html
+++ /dev/null
@@ -1,5 +0,0 @@
-<html>
- <body>
- <input id="myinput"></input>
- </body>
-</html>
diff --git a/chrome/test/data/extensions/js_injection_background/manifest.json b/chrome/test/data/extensions/js_injection_background/manifest.json
deleted file mode 100644
index a6d3076..0000000
--- a/chrome/test/data/extensions/js_injection_background/manifest.json
+++ /dev/null
@@ -1,10 +0,0 @@
-{
- "name": "js_injection_background",
- "description": "Tests JS injection into an extension's background page.
- The name of a DOM node in the background page is returned and verified.",
- "version": "0.1",
- "background_page": "bg.html",
- "browser_action": {
- "default_title": "Browser Action"
- }
-}
diff --git a/chrome/test/functional/execute_javascript.py b/chrome/test/functional/execute_javascript.py
index f880868..1173d4a 100644
--- a/chrome/test/functional/execute_javascript.py
+++ b/chrome/test/functional/execute_javascript.py
@@ -12,11 +12,6 @@ from pyauto import PyUITest
class ExecuteJavascriptTest(PyUITest):
- def _GetExtensionInfoById(self, extensions, id):
- for x in extensions:
- if x['id'] == id:
- return x
- return None
def testExecuteJavascript(self):
self.NavigateToURL(self.GetFileURLForDataPath(
@@ -33,33 +28,6 @@ class ExecuteJavascriptTest(PyUITest):
v = self.GetDOMValue('document.getElementById("myinput").nodeName')
self.assertEqual(v, 'INPUT')
- def testExecuteJavascriptInExtension(self):
- """Test we can inject JavaScript into an extension."""
- dir_path = os.path.abspath(
- os.path.join(self.DataDir(), 'extensions', 'js_injection_background'))
- ext_id = self.InstallExtension(dir_path, False);
- self.assertTrue(ext_id, msg='Failed to install extension: %s.' % dir_path)
-
- # Verify extension is enabled.
- extension = self._GetExtensionInfoById(self.GetExtensionsInfo(), ext_id)
- self.assertTrue(extension['is_enabled'],
- msg='Extension was disabled by default')
-
- # Get the background page's view.
- info = self.GetBrowserInfo()['extension_views']
- view = [x for x in info if
- x['extension_id'] == ext_id and
- x['view_type'] == 'EXTENSION_BACKGROUND_PAGE']
- self.assertEqual(1, len(view),
- msg='problematic background view: view = %s.' % view)
- background_view = view[0]
-
- # Get a value from background page's DOM
- v = self.ExecuteJavascriptInRenderView(
- 'window.domAutomationController.send('
- 'document.getElementById("myinput").nodeName)', background_view['view'])
- self.assertEqual(v, 'INPUT', msg='Incorrect value returned.')
-
if __name__ == '__main__':
pyauto_functional.Main()
diff --git a/chrome/test/functional/memory.py b/chrome/test/functional/memory.py
index bf7e044..a06eb23 100644
--- a/chrome/test/functional/memory.py
+++ b/chrome/test/functional/memory.py
@@ -56,7 +56,7 @@ class MemoryTest(pyauto.PyUITest):
The integer process identifier (PID) for the specified process, or
None if the PID cannot be identified.
"""
- info = self.GetBrowserInfo()['extension_views']
+ info = self.GetBrowserInfo()['extension_processes']
pid = [x['pid'] for x in info if x['name'] == '%s' % name]
if pid:
return pid[0]
diff --git a/chrome/test/pyautolib/pyauto.py b/chrome/test/pyautolib/pyauto.py
index ba69f9e..89ef512 100644
--- a/chrome/test/pyautolib/pyauto.py
+++ b/chrome/test/pyautolib/pyauto.py
@@ -1223,16 +1223,10 @@ class PyUITest(pyautolib.PyUITestBase, unittest.TestCase):
u'child_processes': [ { u'name': u'Shockwave Flash',
u'pid': 93766,
u'type': u'Plug-in'}],
- u'extension_views': [ {
- u'name': u'Webpage Screenshot',
- u'pid': 93938,
- u'extension_id': u'dgcoklnmbeljaehamekjpeidmbicddfj',
- u'url': u'chrome-extension://dgcoklnmbeljaehamekjpeidmbicddfj/'
- 'bg.html',
- u'view': {
- u'render_process_id': 2,
- u'render_view_id': 1},
- u'view_type': u'EXTENSION_BACKGROUND_PAGE'}]
+ # There's one extension process per extension.
+ u'extension_processes': [
+ { u'name': u'Webpage Screenshot', u'pid': 93938},
+ { u'name': u'Google Voice (by Google)', u'pid': 93852}],
u'properties': {
u'BrowserProcessExecutableName': u'Chromium',
u'BrowserProcessExecutablePath': u'Chromium.app/Contents/MacOS/'
@@ -2210,39 +2204,6 @@ class PyUITest(pyautolib.PyUITestBase, unittest.TestCase):
}
return self._GetResultFromJSONRequest(cmd_dict, windex=windex)
- def ExecuteJavascriptInRenderView(self, js, view, frame_xpath=''):
- """Executes a script in the specified frame of an render view.
-
- The invoked javascript function must send a result back via the
- domAutomationController.send function, or this function will never return.
-
- Args:
- js: script to be executed
- view: A dictionary representing a unique id for the render view as
- returned for example by
- self.GetBrowserInfo()['extension_views'][]['view'].
- Example:
- { 'render_process_id': 1,
- 'render_view_id' : 2}
-
- frame_xpath: XPath of the frame to execute the script. Default is no
- frame. Example:
- '//frames[1]'
-
- Returns:
- a string that was sent back via the domAutomationController.send method
-
- Raises:
- pyauto_errors.JSONInterfaceError if the automation call returns an error.
- """
- cmd_dict = {
- 'command': 'ExecuteJavascriptInRenderView',
- 'javascript' : js,
- 'view' : view,
- 'frame_xpath' : frame_xpath,
- }
- return self._GetResultFromJSONRequest(cmd_dict)['result']
-
def CallJavascriptFunc(self, function, args=[], tab_index=0, windex=0):
"""Executes a script which calls a given javascript function.