| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "chrome/renderer/extensions/extension_process_bindings.h" | 5 #include "chrome/renderer/extensions/extension_process_bindings.h" |
| 6 | 6 |
| 7 #include <map> | 7 #include <map> |
| 8 #include <set> | 8 #include <set> |
| 9 #include <string> | 9 #include <string> |
| 10 #include <vector> | 10 #include <vector> |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 55 | 55 |
| 56 // A map of extension ID to vector of page action ids. | 56 // A map of extension ID to vector of page action ids. |
| 57 typedef std::map< std::string, std::vector<std::string> > PageActionIdMap; | 57 typedef std::map< std::string, std::vector<std::string> > PageActionIdMap; |
| 58 | 58 |
| 59 // A map of permission name to whether its enabled for this extension. | 59 // A map of permission name to whether its enabled for this extension. |
| 60 typedef std::map<std::string, bool> PermissionsMap; | 60 typedef std::map<std::string, bool> PermissionsMap; |
| 61 | 61 |
| 62 // A map of extension ID to permissions map. | 62 // A map of extension ID to permissions map. |
| 63 typedef std::map<std::string, PermissionsMap> ExtensionPermissionsMap; | 63 typedef std::map<std::string, PermissionsMap> ExtensionPermissionsMap; |
| 64 | 64 |
| 65 // A map of extension ID to whether this extension was enabled in incognito. | 65 // A map of extension ID to whether this extension can access data from other |
| 66 typedef std::map<std::string, bool> IncognitoEnabledMap; | 66 // profiles. |
| 67 typedef std::map<std::string, bool> CrossProfileAccessMap; |
| 67 | 68 |
| 68 const char kExtensionName[] = "chrome/ExtensionProcessBindings"; | 69 const char kExtensionName[] = "chrome/ExtensionProcessBindings"; |
| 69 const char* kExtensionDeps[] = { | 70 const char* kExtensionDeps[] = { |
| 70 BaseJsV8Extension::kName, | 71 BaseJsV8Extension::kName, |
| 71 EventBindings::kName, | 72 EventBindings::kName, |
| 72 JsonSchemaJsV8Extension::kName, | 73 JsonSchemaJsV8Extension::kName, |
| 73 RendererExtensionBindings::kName, | 74 RendererExtensionBindings::kName, |
| 74 ExtensionApiTestV8Extension::kName, | 75 ExtensionApiTestV8Extension::kName, |
| 75 }; | 76 }; |
| 76 | 77 |
| (...skipping 10 matching lines...) Expand all Loading... |
| 87 "browserActions", | 88 "browserActions", |
| 88 "i18n", | 89 "i18n", |
| 89 "devtools", | 90 "devtools", |
| 90 "test" | 91 "test" |
| 91 }; | 92 }; |
| 92 | 93 |
| 93 struct SingletonData { | 94 struct SingletonData { |
| 94 std::set<std::string> function_names_; | 95 std::set<std::string> function_names_; |
| 95 PageActionIdMap page_action_ids_; | 96 PageActionIdMap page_action_ids_; |
| 96 ExtensionPermissionsMap permissions_; | 97 ExtensionPermissionsMap permissions_; |
| 97 IncognitoEnabledMap incognito_enabled_map_; | 98 CrossProfileAccessMap cross_profile_access_map_; |
| 98 }; | 99 }; |
| 99 | 100 |
| 100 static std::set<std::string>* GetFunctionNameSet() { | 101 static std::set<std::string>* GetFunctionNameSet() { |
| 101 return &Singleton<SingletonData>()->function_names_; | 102 return &Singleton<SingletonData>()->function_names_; |
| 102 } | 103 } |
| 103 | 104 |
| 104 static PageActionIdMap* GetPageActionMap() { | 105 static PageActionIdMap* GetPageActionMap() { |
| 105 return &Singleton<SingletonData>()->page_action_ids_; | 106 return &Singleton<SingletonData>()->page_action_ids_; |
| 106 } | 107 } |
| 107 | 108 |
| 108 static PermissionsMap* GetPermissionsMap(const std::string& extension_id) { | 109 static PermissionsMap* GetPermissionsMap(const std::string& extension_id) { |
| 109 return &Singleton<SingletonData>()->permissions_[extension_id]; | 110 return &Singleton<SingletonData>()->permissions_[extension_id]; |
| 110 } | 111 } |
| 111 | 112 |
| 112 static IncognitoEnabledMap* GetIncognitoEnabledMap() { | 113 static CrossProfileAccessMap* GetCrossProfileAccessMap() { |
| 113 return &Singleton<SingletonData>()->incognito_enabled_map_; | 114 return &Singleton<SingletonData>()->cross_profile_access_map_; |
| 114 } | 115 } |
| 115 | 116 |
| 116 static void GetActiveExtensionIDs(std::set<std::string>* extension_ids) { | 117 static void GetActiveExtensionIDs(std::set<std::string>* extension_ids) { |
| 117 ExtensionPermissionsMap& permissions = | 118 ExtensionPermissionsMap& permissions = |
| 118 Singleton<SingletonData>()->permissions_; | 119 Singleton<SingletonData>()->permissions_; |
| 119 | 120 |
| 120 for (ExtensionPermissionsMap::iterator iter = permissions.begin(); | 121 for (ExtensionPermissionsMap::iterator iter = permissions.begin(); |
| 121 iter != permissions.end(); ++iter) { | 122 iter != permissions.end(); ++iter) { |
| 122 extension_ids->insert(iter->first); | 123 extension_ids->insert(iter->first); |
| 123 } | 124 } |
| (...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 257 } else if (name->Equals(v8::String::New("GetRenderViewId"))) { | 258 } else if (name->Equals(v8::String::New("GetRenderViewId"))) { |
| 258 return v8::FunctionTemplate::New(GetRenderViewId); | 259 return v8::FunctionTemplate::New(GetRenderViewId); |
| 259 } else if (name->Equals(v8::String::New("GetPopupView"))) { | 260 } else if (name->Equals(v8::String::New("GetPopupView"))) { |
| 260 return v8::FunctionTemplate::New(GetPopupView); | 261 return v8::FunctionTemplate::New(GetPopupView); |
| 261 } else if (name->Equals(v8::String::New("GetPopupParentWindow"))) { | 262 } else if (name->Equals(v8::String::New("GetPopupParentWindow"))) { |
| 262 return v8::FunctionTemplate::New(GetPopupParentWindow); | 263 return v8::FunctionTemplate::New(GetPopupParentWindow); |
| 263 } else if (name->Equals(v8::String::New("SetIconCommon"))) { | 264 } else if (name->Equals(v8::String::New("SetIconCommon"))) { |
| 264 return v8::FunctionTemplate::New(SetIconCommon); | 265 return v8::FunctionTemplate::New(SetIconCommon); |
| 265 } else if (name->Equals(v8::String::New("IsExtensionProcess"))) { | 266 } else if (name->Equals(v8::String::New("IsExtensionProcess"))) { |
| 266 return v8::FunctionTemplate::New(IsExtensionProcess); | 267 return v8::FunctionTemplate::New(IsExtensionProcess); |
| 268 } else if (name->Equals(v8::String::New("IsIncognitoProcess"))) { |
| 269 return v8::FunctionTemplate::New(IsIncognitoProcess); |
| 267 } | 270 } |
| 268 | 271 |
| 269 return ExtensionBase::GetNativeFunction(name); | 272 return ExtensionBase::GetNativeFunction(name); |
| 270 } | 273 } |
| 271 | 274 |
| 272 private: | 275 private: |
| 273 static v8::Handle<v8::Value> GetExtensionAPIDefinition( | 276 static v8::Handle<v8::Value> GetExtensionAPIDefinition( |
| 274 const v8::Arguments& args) { | 277 const v8::Arguments& args) { |
| 275 return v8::String::New(GetStringResource<IDR_EXTENSION_API_JSON>()); | 278 return v8::String::New(GetStringResource<IDR_EXTENSION_API_JSON>()); |
| 276 } | 279 } |
| (...skipping 278 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 555 return v8::Undefined(); | 558 return v8::Undefined(); |
| 556 return v8::Integer::New(renderview->routing_id()); | 559 return v8::Integer::New(renderview->routing_id()); |
| 557 } | 560 } |
| 558 | 561 |
| 559 static v8::Handle<v8::Value> IsExtensionProcess(const v8::Arguments& args) { | 562 static v8::Handle<v8::Value> IsExtensionProcess(const v8::Arguments& args) { |
| 560 bool retval = false; | 563 bool retval = false; |
| 561 if (EventBindings::GetRenderThread()) | 564 if (EventBindings::GetRenderThread()) |
| 562 retval = EventBindings::GetRenderThread()->IsExtensionProcess(); | 565 retval = EventBindings::GetRenderThread()->IsExtensionProcess(); |
| 563 return v8::Boolean::New(retval); | 566 return v8::Boolean::New(retval); |
| 564 } | 567 } |
| 568 |
| 569 static v8::Handle<v8::Value> IsIncognitoProcess(const v8::Arguments& args) { |
| 570 bool retval = false; |
| 571 if (EventBindings::GetRenderThread()) |
| 572 retval = EventBindings::GetRenderThread()->IsIncognitoProcess(); |
| 573 return v8::Boolean::New(retval); |
| 574 } |
| 565 }; | 575 }; |
| 566 | 576 |
| 567 } // namespace | 577 } // namespace |
| 568 | 578 |
| 569 v8::Extension* ExtensionProcessBindings::Get() { | 579 v8::Extension* ExtensionProcessBindings::Get() { |
| 570 static v8::Extension* extension = new ExtensionImpl(); | 580 static v8::Extension* extension = new ExtensionImpl(); |
| 571 return extension; | 581 return extension; |
| 572 } | 582 } |
| 573 | 583 |
| 574 void ExtensionProcessBindings::GetActiveExtensions( | 584 void ExtensionProcessBindings::GetActiveExtensions( |
| 575 std::set<std::string>* extension_ids) { | 585 std::set<std::string>* extension_ids) { |
| 576 GetActiveExtensionIDs(extension_ids); | 586 GetActiveExtensionIDs(extension_ids); |
| 577 } | 587 } |
| 578 | 588 |
| 579 void ExtensionProcessBindings::SetFunctionNames( | 589 void ExtensionProcessBindings::SetFunctionNames( |
| 580 const std::vector<std::string>& names) { | 590 const std::vector<std::string>& names) { |
| 581 ExtensionImpl::SetFunctionNames(names); | 591 ExtensionImpl::SetFunctionNames(names); |
| 582 } | 592 } |
| 583 | 593 |
| 584 void ExtensionProcessBindings::SetIncognitoEnabled( | 594 void ExtensionProcessBindings::SetIncognitoEnabled( |
| 585 const std::string& extension_id, bool enabled) { | 595 const std::string& extension_id, bool enabled, bool incognito_split_mode) { |
| 586 (*GetIncognitoEnabledMap())[extension_id] = enabled; | 596 // We allow the extension to see events and data from another profile iff it |
| 597 // uses "spanning" behavior and it has incognito access. "split" mode |
| 598 // extensions only see events for a matching profile. |
| 599 (*GetCrossProfileAccessMap())[extension_id] = |
| 600 enabled && !incognito_split_mode; |
| 587 } | 601 } |
| 588 | 602 |
| 589 // static | 603 // static |
| 590 bool ExtensionProcessBindings::HasIncognitoEnabled( | 604 bool ExtensionProcessBindings::AllowCrossProfile( |
| 591 const std::string& extension_id) { | 605 const std::string& extension_id) { |
| 592 return (!extension_id.empty() && (*GetIncognitoEnabledMap())[extension_id]); | 606 return (!extension_id.empty() && (*GetCrossProfileAccessMap())[extension_id]); |
| 593 } | 607 } |
| 594 | 608 |
| 595 // static | 609 // static |
| 596 void ExtensionProcessBindings::HandleResponse(int request_id, bool success, | 610 void ExtensionProcessBindings::HandleResponse(int request_id, bool success, |
| 597 const std::string& response, | 611 const std::string& response, |
| 598 const std::string& error) { | 612 const std::string& error) { |
| 599 PendingRequestMap& pending_requests = GetPendingRequestMap(); | 613 PendingRequestMap& pending_requests = GetPendingRequestMap(); |
| 600 PendingRequestMap::iterator request = pending_requests.find(request_id); | 614 PendingRequestMap::iterator request = pending_requests.find(request_id); |
| 601 if (request == pending_requests.end()) | 615 if (request == pending_requests.end()) |
| 602 return; // The frame went away. | 616 return; // The frame went away. |
| (...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 711 const std::string& function_name) { | 725 const std::string& function_name) { |
| 712 static const char kMessage[] = | 726 static const char kMessage[] = |
| 713 "You do not have permission to use '%s'. Be sure to declare" | 727 "You do not have permission to use '%s'. Be sure to declare" |
| 714 " in your manifest what permissions you need."; | 728 " in your manifest what permissions you need."; |
| 715 std::string error_msg = StringPrintf(kMessage, function_name.c_str()); | 729 std::string error_msg = StringPrintf(kMessage, function_name.c_str()); |
| 716 | 730 |
| 717 return v8::ThrowException(v8::Exception::Error( | 731 return v8::ThrowException(v8::Exception::Error( |
| 718 v8::String::New(error_msg.c_str()))); | 732 v8::String::New(error_msg.c_str()))); |
| 719 } | 733 } |
| 720 | 734 |
| OLD | NEW |