Skip to content

Commit

Permalink
Export the new sessionid property of Chrome Frame form the NPAPI inte…
Browse files Browse the repository at this point in the history
…rface.

BUG=0
TEST=see included unit test

Review URL: http://codereview.chromium.org/5331003

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@67311 0039d316-1c4b-4281-b951-d872f2087c98
  • Loading branch information
rogerta@chromium.org committed Nov 24, 2010
1 parent f57075e commit 69e4b61
Show file tree
Hide file tree
Showing 8 changed files with 100 additions and 3 deletions.
9 changes: 9 additions & 0 deletions chrome_frame/chrome_frame_npapi.cc
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ const NPUTF8* ChromeFrameNPAPI::plugin_property_identifier_names_[] = {
"onprivatemessage",
"usechromenetwork",
"onclose",
"sessionid",
};

const NPUTF8* ChromeFrameNPAPI::plugin_method_identifier_names_[] = {
Expand Down Expand Up @@ -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;
Expand Down
1 change: 1 addition & 0 deletions chrome_frame/chrome_frame_npapi.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
16 changes: 16 additions & 0 deletions chrome_frame/ff_30_privilege_check.cc
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,29 @@
#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);

// 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)
Expand Down
39 changes: 39 additions & 0 deletions chrome_frame/test/data/sessionid.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<html>
<!-- This page is meant to load inside the host browser like IE/FF -->
<head>
<script type="text/javascript" src="chrome_frame_tester_helpers.js">
</script>
<script type="text/javascript">
function onLoad() {
document.ChromeFrame.addEventListener('readystatechanged',
function() {
if (document.ChromeFrame.readystate == 4) { // READY_STATE_COMPLETED
var sessionId = document.ChromeFrame.sessionid;
appendStatus('Chrome frame sessionId: ' + sessionId);
if (sessionId == 1) {
onSuccess('sessionid', 1);
} else {
onFailure('sessionid', 1, 'no sessionId');
}
}
}, false);
}
</script>
</head>

<body onload="onLoad();">
<object id="ChromeFrame"
codebase="http://www.google.com"
classid="CLSID:E0A900DF-9611-4446-86BD-4B1D47E7DB2A">
<embed id="ChromeFramePlugin" name="ChromeFrame"
type="application/chromeframe" privileged_mode="1"
</embed>
</object>
<br>
<br>
<p>Test for Chrome frame sessionid</p>
<div id="statusPanel" style="border: 1px solid red; width: 100%">
Test running....
</div>
</body>
</html>
28 changes: 27 additions & 1 deletion chrome_frame/test/test_with_web_server.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -1260,4 +1287,3 @@ TEST_F(ChromeFrameTestWithWebServer, FullTabModeIE_TestDownloadFromForm) {
EXPECT_EQ(1, response->get_request_count());
EXPECT_EQ(1, response->post_request_count());
}

4 changes: 4 additions & 0 deletions chrome_frame/test/test_with_web_server.h
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down
5 changes: 3 additions & 2 deletions chrome_frame/utils.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down
1 change: 1 addition & 0 deletions chrome_frame/utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -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[];
Expand Down

0 comments on commit 69e4b61

Please sign in to comment.