summaryrefslogtreecommitdiffstats
path: root/chrome_frame/ff_30_privilege_check.cc
diff options
context:
space:
mode:
authorslightlyoff@chromium.org <slightlyoff@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-09-24 05:11:58 +0000
committerslightlyoff@chromium.org <slightlyoff@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-09-24 05:11:58 +0000
commitf781782dd67077478e117c61dca4ea5eefce3544 (patch)
tree4801f724123cfdcbb69c4e7fe40a565b331723ae /chrome_frame/ff_30_privilege_check.cc
parent63cf4759efa2373e33436fb5df6849f930081226 (diff)
downloadchromium_src-f781782dd67077478e117c61dca4ea5eefce3544.zip
chromium_src-f781782dd67077478e117c61dca4ea5eefce3544.tar.gz
chromium_src-f781782dd67077478e117c61dca4ea5eefce3544.tar.bz2
Initial import of the Chrome Frame codebase. Integration in chrome.gyp coming in a separate CL.
BUG=None TEST=None Review URL: http://codereview.chromium.org/218019 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@27042 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome_frame/ff_30_privilege_check.cc')
-rw-r--r--chrome_frame/ff_30_privilege_check.cc99
1 files changed, 99 insertions, 0 deletions
diff --git a/chrome_frame/ff_30_privilege_check.cc b/chrome_frame/ff_30_privilege_check.cc
new file mode 100644
index 0000000..e2b6369
--- /dev/null
+++ b/chrome_frame/ff_30_privilege_check.cc
@@ -0,0 +1,99 @@
+// Copyright (c) 2009 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+// This file relies on the 1.9 version of the unfrozen interfaces
+// "nsIScriptSecurityManager" and "nsIScriptObjectPrincipal"
+// from gecko 1.9, which means that this implementation is specific to
+// FireFox 3.0 and any other browsers built from the same gecko version.
+// See [http://en.wikipedia.org/wiki/Gecko_(layout_engine]
+// It's a good bet that nsIScriptSecurityManager will change for gecko
+// 1.9.1 and FireFox 3.5, in which case we'll need another instance of this
+// code for the 3.5 version of FireFox.
+
+// Gecko headers need this on Windows.
+#define XP_WIN
+#include "chrome_frame/script_security_manager.h"
+#include "third_party/xulrunner-sdk/win/include/dom/nsIScriptObjectPrincipal.h"
+#include "third_party/xulrunner-sdk/win/include/xpcom/nsIServiceManager.h"
+
+// These are needed to work around typedef conflicts in chrome headers.
+#define _UINT32
+#define _INT32
+
+#include "chrome_frame/np_browser_functions.h"
+#include "chrome_frame/scoped_ns_ptr_win.h"
+#include "chrome_frame/ns_associate_iid_win.h"
+#include "base/logging.h"
+
+ASSOCIATE_IID(NS_ISERVICEMANAGER_IID_STR, nsIServiceManager);
+
+namespace {
+// Unfortunately no NS_ISCRIPTOBJECTPRINCIPAL_IID_STR
+// defined for this interface
+nsIID IID_nsIScriptObjectPrincipal = NS_ISCRIPTOBJECTPRINCIPAL_IID;
+} // namespace
+
+// Returns true iff we're being instantiated into a document
+// that has the system principal's privileges
+bool IsFireFoxPrivilegedInvocation(NPP instance) {
+ ScopedNsPtr<nsIServiceManager> service_manager;
+ NPError nperr = npapi::GetValue(instance, NPNVserviceManager,
+ service_manager.Receive());
+ if (nperr != NPERR_NO_ERROR || !service_manager.get())
+ return false;
+ DCHECK(service_manager);
+
+ // Get the document.
+ ScopedNsPtr<nsISupports> window;
+ nperr = npapi::GetValue(instance, NPNVDOMWindow, window.Receive());
+ if (nperr != NPERR_NO_ERROR || !window.get())
+ return false;
+ DCHECK(window);
+
+ // This interface allows us access to the window's principal.
+ ScopedNsPtr<nsIScriptObjectPrincipal, &IID_nsIScriptObjectPrincipal>
+ script_object_principal;
+ nsresult err = script_object_principal.QueryFrom(window);
+ if (NS_FAILED(err) || !script_object_principal.get())
+ return false;
+ DCHECK(script_object_principal);
+
+ // For regular HTML windows, this will be a principal encoding the
+ // document's origin. For browser XUL, this will be the all-powerful
+ // system principal.
+ nsIPrincipal* window_principal = script_object_principal->GetPrincipal();
+ DCHECK(window_principal);
+ if (!window_principal)
+ return false;
+
+ // Get the script security manager.
+ ScopedNsPtr<nsIScriptSecurityManager_FF35> security_manager_ff35;
+ PRBool is_system = PR_FALSE;
+
+ err = service_manager->GetServiceByContractID(
+ NS_SCRIPTSECURITYMANAGER_CONTRACTID,
+ nsIScriptSecurityManager_FF35::GetIID(),
+ reinterpret_cast<void**>(security_manager_ff35.Receive()));
+ if (NS_SUCCEEDED(err) && security_manager_ff35.get()) {
+ err = security_manager_ff35->IsSystemPrincipal(window_principal,
+ &is_system);
+ if (NS_FAILED(err))
+ is_system = PR_FALSE;
+ } else {
+ ScopedNsPtr<nsIScriptSecurityManager_FF30> security_manager_ff30;
+ err = service_manager->GetServiceByContractID(
+ NS_SCRIPTSECURITYMANAGER_CONTRACTID,
+ nsIScriptSecurityManager_FF30::GetIID(),
+ reinterpret_cast<void**>(security_manager_ff30.Receive()));
+ if (NS_SUCCEEDED(err) && security_manager_ff30.get()) {
+ err = security_manager_ff30->IsSystemPrincipal(window_principal,
+ &is_system);
+ }
+
+ if (NS_FAILED(err))
+ is_system = PR_FALSE;
+ }
+
+ return is_system == PR_TRUE;
+}