diff options
Diffstat (limited to 'chrome/renderer/extensions')
-rw-r--r-- | chrome/renderer/extensions/event_bindings.cc | 6 | ||||
-rw-r--r-- | chrome/renderer/extensions/extension_process_bindings.cc | 32 | ||||
-rw-r--r-- | chrome/renderer/extensions/extension_process_bindings.h | 8 |
3 files changed, 31 insertions, 15 deletions
diff --git a/chrome/renderer/extensions/event_bindings.cc b/chrome/renderer/extensions/event_bindings.cc index 1de179e..54edbb4 100644 --- a/chrome/renderer/extensions/event_bindings.cc +++ b/chrome/renderer/extensions/event_bindings.cc @@ -144,9 +144,9 @@ static bool HasSufficientPermissions(ContextInfo* context, const GURL& event_url) { v8::Context::Scope context_scope(context->context); - bool incognito_permissions_ok = (!requires_incognito_access || - ExtensionProcessBindings::HasIncognitoEnabled(context->extension_id)); - if (!incognito_permissions_ok) + bool cross_profile_ok = (!requires_incognito_access || + ExtensionProcessBindings::AllowCrossProfile(context->extension_id)); + if (!cross_profile_ok) return false; // During unit tests, we might be invoked without a v8 context. In these diff --git a/chrome/renderer/extensions/extension_process_bindings.cc b/chrome/renderer/extensions/extension_process_bindings.cc index 38d2919..340502f 100644 --- a/chrome/renderer/extensions/extension_process_bindings.cc +++ b/chrome/renderer/extensions/extension_process_bindings.cc @@ -63,8 +63,9 @@ typedef std::vector<std::string> PermissionsList; // A map of extension ID to permissions map. typedef std::map<std::string, PermissionsList> ExtensionPermissionsList; -// A map of extension ID to whether this extension was enabled in incognito. -typedef std::map<std::string, bool> IncognitoEnabledMap; +// A map of extension ID to whether this extension can access data from other +// profiles. +typedef std::map<std::string, bool> CrossProfileAccessMap; const char kExtensionName[] = "chrome/ExtensionProcessBindings"; const char* kExtensionDeps[] = { @@ -79,7 +80,7 @@ struct SingletonData { std::set<std::string> function_names_; PageActionIdMap page_action_ids_; ExtensionPermissionsList permissions_; - IncognitoEnabledMap incognito_enabled_map_; + CrossProfileAccessMap cross_profile_access_map_; }; static std::set<std::string>* GetFunctionNameSet() { @@ -94,8 +95,8 @@ static PermissionsList* GetPermissionsList(const std::string& extension_id) { return &Singleton<SingletonData>()->permissions_[extension_id]; } -static IncognitoEnabledMap* GetIncognitoEnabledMap() { - return &Singleton<SingletonData>()->incognito_enabled_map_; +static CrossProfileAccessMap* GetCrossProfileAccessMap() { + return &Singleton<SingletonData>()->cross_profile_access_map_; } static void GetActiveExtensionIDs(std::set<std::string>* extension_ids) { @@ -249,6 +250,8 @@ class ExtensionImpl : public ExtensionBase { return v8::FunctionTemplate::New(SetIconCommon); } else if (name->Equals(v8::String::New("IsExtensionProcess"))) { return v8::FunctionTemplate::New(IsExtensionProcess); + } else if (name->Equals(v8::String::New("IsIncognitoProcess"))) { + return v8::FunctionTemplate::New(IsIncognitoProcess); } return ExtensionBase::GetNativeFunction(name); @@ -547,6 +550,13 @@ class ExtensionImpl : public ExtensionBase { retval = EventBindings::GetRenderThread()->IsExtensionProcess(); return v8::Boolean::New(retval); } + + static v8::Handle<v8::Value> IsIncognitoProcess(const v8::Arguments& args) { + bool retval = false; + if (EventBindings::GetRenderThread()) + retval = EventBindings::GetRenderThread()->IsIncognitoProcess(); + return v8::Boolean::New(retval); + } }; } // namespace @@ -567,14 +577,18 @@ void ExtensionProcessBindings::SetFunctionNames( } void ExtensionProcessBindings::SetIncognitoEnabled( - const std::string& extension_id, bool enabled) { - (*GetIncognitoEnabledMap())[extension_id] = enabled; + const std::string& extension_id, bool enabled, bool incognito_split_mode) { + // We allow the extension to see events and data from another profile iff it + // uses "spanning" behavior and it has incognito access. "split" mode + // extensions only see events for a matching profile. + (*GetCrossProfileAccessMap())[extension_id] = + enabled && !incognito_split_mode; } // static -bool ExtensionProcessBindings::HasIncognitoEnabled( +bool ExtensionProcessBindings::AllowCrossProfile( const std::string& extension_id) { - return (!extension_id.empty() && (*GetIncognitoEnabledMap())[extension_id]); + return (!extension_id.empty() && (*GetCrossProfileAccessMap())[extension_id]); } // static diff --git a/chrome/renderer/extensions/extension_process_bindings.h b/chrome/renderer/extensions/extension_process_bindings.h index d64b4255..8202c46 100644 --- a/chrome/renderer/extensions/extension_process_bindings.h +++ b/chrome/renderer/extensions/extension_process_bindings.h @@ -49,10 +49,12 @@ class ExtensionProcessBindings { // Sets whether incognito is enabled for a particular extension. static void SetIncognitoEnabled(const std::string& extension_id, - bool enabled); + bool enabled, + bool incognito_split_mode); - // Checks whether incognito is enabled for a particular extension. - static bool HasIncognitoEnabled(const std::string& extension_id); + // Checks whether the given extension can see events/data from another + // profile (normal to incognito or vice versa). + static bool AllowCrossProfile(const std::string& extension_id); // Check if the extension in the currently running context has permission to // access the given extension function. Must be called with a valid V8 |