diff options
author | ericdingle@chromium.org <ericdingle@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-11-15 19:16:18 +0000 |
---|---|---|
committer | ericdingle@chromium.org <ericdingle@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-11-15 19:16:18 +0000 |
commit | 68af726f3785f91ed9bbe1190228de987b7002df (patch) | |
tree | 46b5e48c78619dff871348dd8894b446e53799ce /ceee | |
parent | 31da931306f3b66e28deff15957a9c5af49ab701 (diff) | |
download | chromium_src-68af726f3785f91ed9bbe1190228de987b7002df.zip chromium_src-68af726f3785f91ed9bbe1190228de987b7002df.tar.gz chromium_src-68af726f3785f91ed9bbe1190228de987b7002df.tar.bz2 |
IE CEEE: Explicitly assign window properties/methods into the script host global namespace instead of automatically.
BUG=none
TEST=none
Review URL: http://codereview.chromium.org/4997002
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@66144 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'ceee')
-rw-r--r-- | ceee/ie/plugin/scripting/ceee_bootstrap.js | 55 | ||||
-rw-r--r-- | ceee/ie/plugin/scripting/content_script_manager.cc | 12 | ||||
-rw-r--r-- | ceee/ie/plugin/scripting/content_script_manager_unittest.cc | 39 |
3 files changed, 83 insertions, 23 deletions
diff --git a/ceee/ie/plugin/scripting/ceee_bootstrap.js b/ceee/ie/plugin/scripting/ceee_bootstrap.js index 28a0a7d..c5d8c85 100644 --- a/ceee/ie/plugin/scripting/ceee_bootstrap.js +++ b/ceee/ie/plugin/scripting/ceee_bootstrap.js @@ -111,7 +111,60 @@ ceee.endInit_ = function (nativenativeContentScriptApi, extensionId) { // Delete the ceee namespace from globals. delete ceee; -} +}; + +ceee.initGlobals_ = function() { + // We expose a subset of the Window interface defined at + // http://www.w3.org/TR/html5/browsers.html#the-window-object + // to the global namespace. We purposely skip all event handler + // attributes (e.g. onclick). + + // Browsing context. + self = window.self; + document = window.document; + name = window.name; + location = window.location; + history = window.history; + undoManager = window.undoManager; + locationbar = window.locationbar; + menubar = window.menubar; + scrollbars = window.scrollbars; + statusbar = window.statusbar; + toolbar = window.toolbar; + close = window.close; + stop = window.stop; + focus = window.focus; + blur = window.blur; + + // Other browsing contexts. + frames = window.frames; + length = window.length; + top = window.top; + opener = window.opener; + parent = window.parent; + frameElement = window.frameElement; + open = window.open; + + // User agent. + navigator = window.navigator; + applicationCache = window.applicationCache; + + // User prompts. + alert = window.alert; + confirm = window.confirm; + prompt = window.prompt; + print = window.print; + showModalDialog = window.showModalDialog; + + // EventTarget interface. + addEventListener = window.addEventListener; + removeEventListener = window.removeEventListener; + dispatchEvent = window.dispatchEvent; + + // Old IE event model. + attachEvent = window.attachEvent; + detachEvent = window.detachEvent; +}; console.log = console.log || function (msg) { if (nativeContentScriptApi) diff --git a/ceee/ie/plugin/scripting/content_script_manager.cc b/ceee/ie/plugin/scripting/content_script_manager.cc index 38566e0..1fe5be9 100644 --- a/ceee/ie/plugin/scripting/content_script_manager.cc +++ b/ceee/ie/plugin/scripting/content_script_manager.cc @@ -157,6 +157,8 @@ HRESULT ContentScriptManager::InitializeScriptHost( CComPtr<IExtensionPortMessagingProvider> messaging_provider; HRESULT hr = host_->GetExtensionPortMessagingProvider(&messaging_provider); + if (FAILED(hr)) + return hr; hr = ContentScriptNativeApi::CreateInitialized(messaging_provider, &native_api_); if (FAILED(hr)) @@ -169,14 +171,18 @@ HRESULT ContentScriptManager::InitializeScriptHost( // Execute the bootstrap scripts. hr = BootstrapScriptHost(script_host, native_api_, extension_id.c_str()); + if (FAILED(hr)) + return hr; + // Register the window object and manually make its members global. CComPtr<IHTMLWindow2> window; hr = document->get_parentWindow(&window); if (FAILED(hr)) return hr; - - // Register the window object and make its members global. - hr = script_host->RegisterScriptObject(L"window", window, true); + hr = script_host->RegisterScriptObject(L"window", window, false); + if (FAILED(hr)) + return hr; + hr = InvokeNamedFunction(script_host, L"ceee.initGlobals_", NULL, 0); return hr; } diff --git a/ceee/ie/plugin/scripting/content_script_manager_unittest.cc b/ceee/ie/plugin/scripting/content_script_manager_unittest.cc index 0384875..113fbd4 100644 --- a/ceee/ie/plugin/scripting/content_script_manager_unittest.cc +++ b/ceee/ie/plugin/scripting/content_script_manager_unittest.cc @@ -223,36 +223,37 @@ class ContentScriptManagerTest: public testing::Test { // Set up to expect scripting initialization. void ExpectScriptInitialization() { - EXPECT_CALL(*script_host_, - RegisterScriptObject(StrEq(L"window"), _, true)) - .WillOnce(Return(S_OK)); + EXPECT_CALL(*frame_host_, GetExtensionId(_)).WillOnce(DoAll( + SetArgumentPointee<0>(std::wstring(kExtensionId)), + Return(S_OK))); EXPECT_CALL(*script_host_, RunScript(testing::StartsWith(L"ceee-content://"), _)) - .Times(5) - .WillRepeatedly(Return(S_OK)); + .Times(5).WillRepeatedly(Return(S_OK)); // Return the mock function for start/end init. EXPECT_CALL(*script_host_, RunExpression(StrEq(L"ceee.startInit_"), _)) - .WillOnce( - DoAll( - CopyVariantToArgument<1>(CComVariant(function_keeper_)), - Return(S_OK))); + .WillOnce(DoAll( + CopyVariantToArgument<1>(CComVariant(function_keeper_)), + Return(S_OK))); EXPECT_CALL(*script_host_, RunExpression(StrEq(L"ceee.endInit_"), _)) - .WillOnce( - DoAll( - CopyVariantToArgument<1>(CComVariant(function_keeper_)), - Return(S_OK))); + .WillOnce(DoAll( + CopyVariantToArgument<1>(CComVariant(function_keeper_)), + Return(S_OK))); - EXPECT_CALL(*frame_host_, GetExtensionId(_)).WillOnce(DoAll( - SetArgumentPointee<0>(std::wstring(kExtensionId)), - Return(S_OK))); + // Register the window object and initialize its globals. + EXPECT_CALL(*script_host_, + RegisterScriptObject(StrEq(L"window"), _, false)) + .WillOnce(Return(S_OK)); + EXPECT_CALL(*script_host_, RunExpression(StrEq(L"ceee.initGlobals_"), _)) + .WillOnce(DoAll( + CopyVariantToArgument<1>(CComVariant(function_keeper_)), + Return(S_OK))); - // And expect two invocations. + // And expect three invocations. // TODO(siggi@chromium.org): be more specific? EXPECT_CALL(*function_, Invoke(_, _, _, _, _, _, _, _)) - .Times(2) - .WillRepeatedly(Return(S_OK)); + .Times(3).WillRepeatedly(Return(S_OK)); } void ExpectCreateScriptHost(TestingContentScriptManager* manager) { |