diff --git a/chrome_frame/chrome_frame_npapi.cc b/chrome_frame/chrome_frame_npapi.cc index f3144b1bfd9671..c645ee8187725e 100644 --- a/chrome_frame/chrome_frame_npapi.cc +++ b/chrome_frame/chrome_frame_npapi.cc @@ -55,6 +55,7 @@ const NPUTF8* ChromeFrameNPAPI::plugin_property_identifier_names_[] = { "onprivatemessage", "usechromenetwork", "onclose", + "sessionid", }; const NPUTF8* ChromeFrameNPAPI::plugin_method_identifier_names_[] = { @@ -667,6 +668,14 @@ bool ChromeFrameNPAPI::GetProperty(NPIdentifier name, plugin_property_identifiers_[PLUGIN_PROPERTY_USECHROMENETWORK]) { BOOLEAN_TO_NPVARIANT(automation_client_->use_chrome_network(), *variant); return true; + } else if (name == plugin_property_identifiers_[PLUGIN_PROPERTY_SESSIONID]) { + if (!is_privileged_) { + DLOG(WARNING) << "Attempt to read sessionid property while not " + "privileged"; + } else { + INT32_TO_NPVARIANT(automation_client_->GetSessionId(), *variant); + return true; + } } return false; diff --git a/chrome_frame/chrome_frame_npapi.h b/chrome_frame/chrome_frame_npapi.h index d60609076ab31a..f05185cb0d24a6 100644 --- a/chrome_frame/chrome_frame_npapi.h +++ b/chrome_frame/chrome_frame_npapi.h @@ -47,6 +47,7 @@ class ChromeFrameNPAPI PLUGIN_PROPERTY_ONPRIVATEMESSAGE, PLUGIN_PROPERTY_USECHROMENETWORK, PLUGIN_PROPERTY_ONCLOSE, + PLUGIN_PROPERTY_SESSIONID, PLUGIN_PROPERTY_COUNT // must be last } PluginPropertyId; diff --git a/chrome_frame/ff_30_privilege_check.cc b/chrome_frame/ff_30_privilege_check.cc index cecd4a0040c114..7031bd5d1b9aea 100644 --- a/chrome_frame/ff_30_privilege_check.cc +++ b/chrome_frame/ff_30_privilege_check.cc @@ -22,6 +22,7 @@ #include "chrome_frame/scoped_ns_ptr_win.h" #include "chrome_frame/ns_associate_iid_win.h" #include "chrome_frame/np_utils.h" +#include "chrome_frame/utils.h" #include "googleurl/src/gurl.h" ASSOCIATE_IID(NS_ISERVICEMANAGER_IID_STR, nsIServiceManager); @@ -29,6 +30,21 @@ ASSOCIATE_IID(NS_ISERVICEMANAGER_IID_STR, nsIServiceManager); // Returns true iff we're being instantiated into a document // that has the system principal's privileges bool IsFireFoxPrivilegedInvocation(NPP instance) { + // For testing purposes, check the registry to see if the privilege mode + // is being forced to a certain value. If this property does not exist, the + // mode should be verified normally. If this property does exist, its value + // is interpreted as follows: + // + // 0: force privilege mode off + // 1: force privilege mode on + // any other value: do normal verification + int privilege_mode = GetConfigInt(2, kEnableFirefoxPrivilegeMode); + if (privilege_mode == 0) { + return false; + } else if (privilege_mode == 1) { + return true; + } + // Make sure that we are running in Firefox before checking for privilege. const char* user_agent = npapi::UserAgent(instance); if (strstr(user_agent, "Firefox") == NULL) diff --git a/chrome_frame/test/data/sessionid.html b/chrome_frame/test/data/sessionid.html new file mode 100644 index 00000000000000..14e84bc995fe29 --- /dev/null +++ b/chrome_frame/test/data/sessionid.html @@ -0,0 +1,39 @@ + + + + + + + + + + + +
+
+

Test for Chrome frame sessionid

+
+ Test running.... +
+ + diff --git a/chrome_frame/test/test_with_web_server.cc b/chrome_frame/test/test_with_web_server.cc index 03dff3fa4abdd3..a030a769500164 100644 --- a/chrome_frame/test/test_with_web_server.cc +++ b/chrome_frame/test/test_with_web_server.cc @@ -127,6 +127,10 @@ void ChromeFrameTestWithWebServer::SetUp() { } void ChromeFrameTestWithWebServer::TearDown() { + // Make sure that the Firefox privilege mode is never forced either on or off + // after the test completes. + DeleteConfigValue(kEnableFirefoxPrivilegeMode); + CloseBrowser(); CloseAllBrowsers(); file_util::Delete(CFInstall_path_, false); @@ -281,6 +285,19 @@ void ChromeFrameTestWithWebServer::VersionTest(BrowserKind browser, ASSERT_EQ(version, UTF8ToWide(server_mock_.posted_result())); } +void ChromeFrameTestWithWebServer::SessionIdTest(BrowserKind browser, + const wchar_t* page, + int privilege_mode, + const char* expected_result) { + SetConfigInt(kEnableFirefoxPrivilegeMode, privilege_mode); + EXPECT_TRUE(LaunchBrowser(browser, page)); + server_mock_.set_expected_result(expected_result); + server_mock_.ExpectAndHandlePostedResult(CFInvocation(CFInvocation::NONE), + kPostedResultSubstring); + WaitForTestToComplete(kLongWaitTimeout); + ASSERT_EQ(expected_result, server_mock_.posted_result()); +} + // MockWebServer methods void MockWebServer::ExpectAndServeRequest(CFInvocation invocation, const std::wstring& url) { @@ -804,6 +821,16 @@ TEST_F(ChromeFrameTestWithWebServer, WidgetModeFF_Version) { VersionTest(FIREFOX, kVersionPage); } +const wchar_t kSessionIdPage[] = L"sessionid.html"; + +TEST_F(ChromeFrameTestWithWebServer, WidgetModeFF_SessionIdPrivilege) { + SessionIdTest(FIREFOX, kSessionIdPage, 1, "OK"); +} + +TEST_F(ChromeFrameTestWithWebServer, WidgetModeFF_SessionIdNoPrivilege) { + SessionIdTest(FIREFOX, kSessionIdPage, 0, "no sessionId"); +} + const wchar_t kEventListenerPage[] = L"event_listener.html"; TEST_F(ChromeFrameTestWithWebServer, WidgetModeIE_EventListener) { @@ -1260,4 +1287,3 @@ TEST_F(ChromeFrameTestWithWebServer, FullTabModeIE_TestDownloadFromForm) { EXPECT_EQ(1, response->get_request_count()); EXPECT_EQ(1, response->post_request_count()); } - diff --git a/chrome_frame/test/test_with_web_server.h b/chrome_frame/test/test_with_web_server.h index fd65615936c109..3b424f37225217 100644 --- a/chrome_frame/test/test_with_web_server.h +++ b/chrome_frame/test/test_with_web_server.h @@ -175,6 +175,10 @@ class ChromeFrameTestWithWebServer: public testing::Test { // Test if chrome frame correctly reports its version. void VersionTest(BrowserKind browser, const wchar_t* page); + // Test if chrome frame correctly reports its session Id. + void SessionIdTest(BrowserKind browser, const wchar_t* page, + int privilege_mode, const char* expected_result); + // Closes all browsers in preparation for a test and during cleanup. void CloseAllBrowsers(); diff --git a/chrome_frame/utils.cc b/chrome_frame/utils.cc index 294f0449d08ed3..8fd90fc4a48fcd 100644 --- a/chrome_frame/utils.cc +++ b/chrome_frame/utils.cc @@ -62,8 +62,9 @@ const wchar_t kEnableGCFRendererByDefault[] = L"IsDefaultRenderer"; const wchar_t kIexploreProfileName[] = L"iexplore"; const wchar_t kRundllProfileName[] = L"rundll32"; -static const wchar_t kAllowUnsafeURLs[] = L"AllowUnsafeURLs"; -static const wchar_t kEnableBuggyBhoIntercept[] = L"EnableBuggyBhoIntercept"; +const wchar_t kAllowUnsafeURLs[] = L"AllowUnsafeURLs"; +const wchar_t kEnableBuggyBhoIntercept[] = L"EnableBuggyBhoIntercept"; +const wchar_t kEnableFirefoxPrivilegeMode[] = L"EnableFirefoxPrivilegeMode"; static const wchar_t kChromeFrameNPAPIKey[] = L"Software\\MozillaPlugins\\@google.com/ChromeFrame,version=1.0"; diff --git a/chrome_frame/utils.h b/chrome_frame/utils.h index 11b749b593567e..44920787a4c248 100644 --- a/chrome_frame/utils.h +++ b/chrome_frame/utils.h @@ -33,6 +33,7 @@ extern const wchar_t kChromeFrameAccessibleMode[]; extern const wchar_t kChromeFrameUnpinnedMode[]; extern const wchar_t kAllowUnsafeURLs[]; extern const wchar_t kEnableBuggyBhoIntercept[]; +extern const wchar_t kEnableFirefoxPrivilegeMode[]; extern const wchar_t kChromeMimeType[]; extern const wchar_t kChromeFrameAttachTabPattern[]; extern const wchar_t kChromeFrameConfigKey[];