OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 // This file relies on the 1.9 version of the unfrozen interfaces |
| 6 // "nsIScriptSecurityManager" and "nsIScriptObjectPrincipal" |
| 7 // from gecko 1.9, which means that this implementation is specific to |
| 8 // FireFox 3.0 and any other browsers built from the same gecko version. |
| 9 // See [http://en.wikipedia.org/wiki/Gecko_(layout_engine] |
| 10 // It's a good bet that nsIScriptSecurityManager will change for gecko |
| 11 // 1.9.1 and FireFox 3.5, in which case we'll need another instance of this |
| 12 // code for the 3.5 version of FireFox. |
| 13 |
| 14 // Gecko headers need this on Windows. |
| 15 #define XP_WIN |
| 16 #include "chrome_frame/script_security_manager.h" |
| 17 #include "third_party/xulrunner-sdk/win/include/dom/nsIScriptObjectPrincipal.h" |
| 18 #include "third_party/xulrunner-sdk/win/include/xpcom/nsIServiceManager.h" |
| 19 |
| 20 // These are needed to work around typedef conflicts in chrome headers. |
| 21 #define _UINT32 |
| 22 #define _INT32 |
| 23 |
| 24 #include "chrome_frame/np_browser_functions.h" |
| 25 #include "chrome_frame/scoped_ns_ptr_win.h" |
| 26 #include "chrome_frame/ns_associate_iid_win.h" |
| 27 #include "base/logging.h" |
| 28 |
| 29 ASSOCIATE_IID(NS_ISERVICEMANAGER_IID_STR, nsIServiceManager); |
| 30 |
| 31 namespace { |
| 32 // Unfortunately no NS_ISCRIPTOBJECTPRINCIPAL_IID_STR |
| 33 // defined for this interface |
| 34 nsIID IID_nsIScriptObjectPrincipal = NS_ISCRIPTOBJECTPRINCIPAL_IID; |
| 35 } // namespace |
| 36 |
| 37 // Returns true iff we're being instantiated into a document |
| 38 // that has the system principal's privileges |
| 39 bool IsFireFoxPrivilegedInvocation(NPP instance) { |
| 40 ScopedNsPtr<nsIServiceManager> service_manager; |
| 41 NPError nperr = npapi::GetValue(instance, NPNVserviceManager, |
| 42 service_manager.Receive()); |
| 43 if (nperr != NPERR_NO_ERROR || !service_manager.get()) |
| 44 return false; |
| 45 DCHECK(service_manager); |
| 46 |
| 47 // Get the document. |
| 48 ScopedNsPtr<nsISupports> window; |
| 49 nperr = npapi::GetValue(instance, NPNVDOMWindow, window.Receive()); |
| 50 if (nperr != NPERR_NO_ERROR || !window.get()) |
| 51 return false; |
| 52 DCHECK(window); |
| 53 |
| 54 // This interface allows us access to the window's principal. |
| 55 ScopedNsPtr<nsIScriptObjectPrincipal, &IID_nsIScriptObjectPrincipal> |
| 56 script_object_principal; |
| 57 nsresult err = script_object_principal.QueryFrom(window); |
| 58 if (NS_FAILED(err) || !script_object_principal.get()) |
| 59 return false; |
| 60 DCHECK(script_object_principal); |
| 61 |
| 62 // For regular HTML windows, this will be a principal encoding the |
| 63 // document's origin. For browser XUL, this will be the all-powerful |
| 64 // system principal. |
| 65 nsIPrincipal* window_principal = script_object_principal->GetPrincipal(); |
| 66 DCHECK(window_principal); |
| 67 if (!window_principal) |
| 68 return false; |
| 69 |
| 70 // Get the script security manager. |
| 71 ScopedNsPtr<nsIScriptSecurityManager_FF35> security_manager_ff35; |
| 72 PRBool is_system = PR_FALSE; |
| 73 |
| 74 err = service_manager->GetServiceByContractID( |
| 75 NS_SCRIPTSECURITYMANAGER_CONTRACTID, |
| 76 nsIScriptSecurityManager_FF35::GetIID(), |
| 77 reinterpret_cast<void**>(security_manager_ff35.Receive())); |
| 78 if (NS_SUCCEEDED(err) && security_manager_ff35.get()) { |
| 79 err = security_manager_ff35->IsSystemPrincipal(window_principal, |
| 80 &is_system); |
| 81 if (NS_FAILED(err)) |
| 82 is_system = PR_FALSE; |
| 83 } else { |
| 84 ScopedNsPtr<nsIScriptSecurityManager_FF30> security_manager_ff30; |
| 85 err = service_manager->GetServiceByContractID( |
| 86 NS_SCRIPTSECURITYMANAGER_CONTRACTID, |
| 87 nsIScriptSecurityManager_FF30::GetIID(), |
| 88 reinterpret_cast<void**>(security_manager_ff30.Receive())); |
| 89 if (NS_SUCCEEDED(err) && security_manager_ff30.get()) { |
| 90 err = security_manager_ff30->IsSystemPrincipal(window_principal, |
| 91 &is_system); |
| 92 } |
| 93 |
| 94 if (NS_FAILED(err)) |
| 95 is_system = PR_FALSE; |
| 96 } |
| 97 |
| 98 return is_system == PR_TRUE; |
| 99 } |
OLD | NEW |