| Index: chrome/renderer/extensions/extension_process_bindings.cc
|
| diff --git a/chrome/renderer/extensions/extension_process_bindings.cc b/chrome/renderer/extensions/extension_process_bindings.cc
|
| index 57d6fec02267f56228e4f848f52821be022b68fe..a8ed2696988be16453ef26e66e6321f1bbdacf9c 100644
|
| --- a/chrome/renderer/extensions/extension_process_bindings.cc
|
| +++ b/chrome/renderer/extensions/extension_process_bindings.cc
|
| @@ -4,14 +4,12 @@
|
|
|
| #include "chrome/renderer/extensions/extension_process_bindings.h"
|
|
|
| -#include <map>
|
| #include <set>
|
| #include <string>
|
| #include <vector>
|
|
|
| #include "base/command_line.h"
|
| #include "base/json/json_reader.h"
|
| -#include "base/lazy_instance.h"
|
| #include "base/memory/scoped_ptr.h"
|
| #include "base/string_number_conversions.h"
|
| #include "base/string_util.h"
|
| @@ -37,34 +35,18 @@
|
| #include "third_party/skia/include/core/SkBitmap.h"
|
| #include "third_party/skia/include/core/SkColor.h"
|
| #include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h"
|
| -#include "third_party/WebKit/Source/WebKit/chromium/public/WebURL.h"
|
| -#include "third_party/WebKit/Source/WebKit/chromium/public/WebKit.h"
|
| -#include "third_party/WebKit/Source/WebKit/chromium/public/WebSecurityPolicy.h"
|
| #include "third_party/WebKit/Source/WebKit/chromium/public/WebView.h"
|
|
|
| using bindings_utils::GetStringResource;
|
| -using bindings_utils::ContextInfo;
|
| -using bindings_utils::ContextList;
|
| -using bindings_utils::GetContexts;
|
| using bindings_utils::GetPendingRequestMap;
|
| using bindings_utils::PendingRequest;
|
| using bindings_utils::PendingRequestMap;
|
| using bindings_utils::ExtensionBase;
|
| using WebKit::WebFrame;
|
| -using WebKit::WebSecurityPolicy;
|
| using WebKit::WebView;
|
|
|
| namespace {
|
|
|
| -// A map of extension ID to vector of page action ids.
|
| -typedef std::map< std::string, std::vector<std::string> > PageActionIdMap;
|
| -
|
| -// A list of permissions that are enabled for this extension.
|
| -typedef std::set<std::string> PermissionsList;
|
| -
|
| -// A map of extension ID to permissions map.
|
| -typedef std::map<std::string, PermissionsList> ExtensionPermissionsList;
|
| -
|
| const char kExtensionName[] = "chrome/ExtensionProcessBindings";
|
| const char* kExtensionDeps[] = {
|
| BaseJsV8Extension::kName,
|
| @@ -74,36 +56,6 @@ const char* kExtensionDeps[] = {
|
| ExtensionApiTestV8Extension::kName,
|
| };
|
|
|
| -struct SingletonData {
|
| - std::set<std::string> function_names_;
|
| - PageActionIdMap page_action_ids_;
|
| - ExtensionPermissionsList permissions_;
|
| -};
|
| -
|
| -static base::LazyInstance<SingletonData> g_singleton_data(
|
| - base::LINKER_INITIALIZED);
|
| -
|
| -static std::set<std::string>* GetFunctionNameSet() {
|
| - return &g_singleton_data.Get().function_names_;
|
| -}
|
| -
|
| -static PageActionIdMap* GetPageActionMap() {
|
| - return &g_singleton_data.Get().page_action_ids_;
|
| -}
|
| -
|
| -static PermissionsList* GetPermissionsList(const std::string& extension_id) {
|
| - return &g_singleton_data.Get().permissions_[extension_id];
|
| -}
|
| -
|
| -static void GetActiveExtensionIDs(std::set<std::string>* extension_ids) {
|
| - ExtensionPermissionsList& permissions = g_singleton_data.Get().permissions_;
|
| -
|
| - for (ExtensionPermissionsList::iterator iter = permissions.begin();
|
| - iter != permissions.end(); ++iter) {
|
| - extension_ids->insert(iter->first);
|
| - }
|
| -}
|
| -
|
| // A RenderViewVisitor class that iterates through the set of available
|
| // views, looking for a view of the given type, in the given browser window
|
| // and within the given extension.
|
| @@ -189,36 +141,10 @@ class ExtensionImpl : public ExtensionBase {
|
| : ExtensionBase(kExtensionName,
|
| GetStringResource(IDR_EXTENSION_PROCESS_BINDINGS_JS),
|
| arraysize(kExtensionDeps),
|
| - kExtensionDeps) {
|
| - extension_dispatcher_ = extension_dispatcher;
|
| - }
|
| -
|
| - ~ExtensionImpl() {
|
| - extension_dispatcher_ = NULL;
|
| - }
|
| -
|
| - static void SetFunctionNames(const std::vector<std::string>& names) {
|
| - std::set<std::string>* name_set = GetFunctionNameSet();
|
| - for (size_t i = 0; i < names.size(); ++i) {
|
| - name_set->insert(names[i]);
|
| - }
|
| - }
|
| -
|
| - // Note: do not call this function before or during the chromeHidden.onLoad
|
| - // event dispatch. The URL might not have been committed yet and might not
|
| - // be an extension URL.
|
| - static std::string ExtensionIdForCurrentContext() {
|
| - RenderView* renderview = bindings_utils::GetRenderViewForCurrentContext();
|
| - if (!renderview)
|
| - return std::string(); // this can happen as a tab is closing.
|
| -
|
| - GURL url = renderview->webview()->mainFrame()->url();
|
| - const ExtensionSet* extensions = extension_dispatcher_->extensions();
|
| - if (!extensions->ExtensionBindingsAllowed(url))
|
| - return std::string();
|
| -
|
| - return extensions->GetIdByURL(url);
|
| + kExtensionDeps,
|
| + extension_dispatcher) {
|
| }
|
| + ~ExtensionImpl() {}
|
|
|
| virtual v8::Handle<v8::FunctionTemplate> GetNativeFunction(
|
| v8::Handle<v8::String> name) {
|
| @@ -288,11 +214,11 @@ class ExtensionImpl : public ExtensionBase {
|
| return v8::Undefined();
|
| }
|
|
|
| - std::string extension_id = ExtensionIdForCurrentContext();
|
| - if (extension_id.empty())
|
| + const Extension* extension = GetExtensionForCurrentContext();
|
| + if (!extension)
|
| return v8::Undefined();
|
|
|
| - ExtensionViewAccumulator accumulator(extension_id, browser_window_id,
|
| + ExtensionViewAccumulator accumulator(extension->id(), browser_window_id,
|
| view_type);
|
| RenderView::ForEach(&accumulator);
|
| return accumulator.views();
|
| @@ -369,8 +295,10 @@ class ExtensionImpl : public ExtensionBase {
|
| static v8::Handle<v8::Value> GetCurrentPageActions(
|
| const v8::Arguments& args) {
|
| std::string extension_id = *v8::String::Utf8Value(args[0]->ToString());
|
| - PageActionIdMap* page_action_map = GetPageActionMap();
|
| - PageActionIdMap::const_iterator it = page_action_map->find(extension_id);
|
| + ExtensionDispatcher::PageActionIdMap& page_action_map =
|
| + extension_dispatcher_->page_action_map();
|
| + ExtensionDispatcher::PageActionIdMap::const_iterator it =
|
| + page_action_map->find(extension_id);
|
|
|
| std::vector<std::string> page_actions;
|
| size_t size = 0;
|
| @@ -401,14 +329,15 @@ class ExtensionImpl : public ExtensionBase {
|
| return v8::Undefined();
|
|
|
| std::string name = *v8::String::AsciiValue(args[0]);
|
| - if (GetFunctionNameSet()->find(name) == GetFunctionNameSet()->end()) {
|
| + const std::set<std::string>& function_names =
|
| + extension_dispatcher_->function_names();
|
| + if (function_names->find(name) == function_names->end()) {
|
| NOTREACHED() << "Unexpected function " << name;
|
| return v8::Undefined();
|
| }
|
|
|
| - if (!ExtensionProcessBindings::CurrentContextHasPermission(name)) {
|
| - return ExtensionProcessBindings::ThrowPermissionDeniedException(name);
|
| - }
|
| + if (!CheckCurrentContextHasPermission(name))
|
| + return v8::Undefined();
|
|
|
| GURL source_url;
|
| WebFrame* webframe = WebFrame::frameForCurrentContext();
|
| @@ -553,16 +482,6 @@ v8::Extension* ExtensionProcessBindings::Get(
|
| return extension;
|
| }
|
|
|
| -void ExtensionProcessBindings::GetActiveExtensions(
|
| - std::set<std::string>* extension_ids) {
|
| - GetActiveExtensionIDs(extension_ids);
|
| -}
|
| -
|
| -void ExtensionProcessBindings::SetFunctionNames(
|
| - const std::vector<std::string>& names) {
|
| - ExtensionImpl::SetFunctionNames(names);
|
| -}
|
| -
|
| // static
|
| void ExtensionProcessBindings::HandleResponse(int request_id, bool success,
|
| const std::string& response,
|
| @@ -594,90 +513,3 @@ void ExtensionProcessBindings::HandleResponse(int request_id, bool success,
|
| request->second->context.Clear();
|
| pending_requests.erase(request);
|
| }
|
| -
|
| -// static
|
| -void ExtensionProcessBindings::SetPageActions(
|
| - const std::string& extension_id,
|
| - const std::vector<std::string>& page_actions) {
|
| - PageActionIdMap& page_action_map = *GetPageActionMap();
|
| - if (!page_actions.empty()) {
|
| - page_action_map[extension_id] = page_actions;
|
| - } else {
|
| - if (page_action_map.find(extension_id) != page_action_map.end())
|
| - page_action_map.erase(extension_id);
|
| - }
|
| -}
|
| -
|
| -// static
|
| -void ExtensionProcessBindings::SetAPIPermissions(
|
| - const std::string& extension_id,
|
| - const std::set<std::string>& permissions) {
|
| - PermissionsList& permissions_list = *GetPermissionsList(extension_id);
|
| - permissions_list.clear();
|
| - permissions_list.insert(permissions.begin(), permissions.end());
|
| -
|
| - // The RenderViewTests set API permissions without an |extension_id|. If
|
| - // there's no ID, there will be no extension URL and no need to proceed.
|
| - if (extension_id.empty()) return;
|
| -
|
| - // Grant access to chrome://extension-icon resources if they have the
|
| - // 'management' permission.
|
| - if (permissions_list.find(Extension::kManagementPermission) !=
|
| - permissions_list.end()) {
|
| - WebSecurityPolicy::addOriginAccessWhitelistEntry(
|
| - Extension::GetBaseURLFromExtensionId(extension_id),
|
| - WebKit::WebString::fromUTF8(chrome::kChromeUIScheme),
|
| - WebKit::WebString::fromUTF8(chrome::kChromeUIExtensionIconHost),
|
| - false);
|
| - }
|
| -}
|
| -
|
| -// static
|
| -void ExtensionProcessBindings::SetHostPermissions(
|
| - const GURL& extension_url,
|
| - const std::vector<URLPattern>& permissions) {
|
| - for (size_t i = 0; i < permissions.size(); ++i) {
|
| - const char* schemes[] = {
|
| - chrome::kHttpScheme,
|
| - chrome::kHttpsScheme,
|
| - chrome::kFileScheme,
|
| - chrome::kChromeUIScheme,
|
| - };
|
| - for (size_t j = 0; j < arraysize(schemes); ++j) {
|
| - if (permissions[i].MatchesScheme(schemes[j])) {
|
| - WebSecurityPolicy::addOriginAccessWhitelistEntry(
|
| - extension_url,
|
| - WebKit::WebString::fromUTF8(schemes[j]),
|
| - WebKit::WebString::fromUTF8(permissions[i].host()),
|
| - permissions[i].match_subdomains());
|
| - }
|
| - }
|
| - }
|
| -}
|
| -
|
| -// static
|
| -bool ExtensionProcessBindings::CurrentContextHasPermission(
|
| - const std::string& function_name) {
|
| - std::string extension_id = ExtensionImpl::ExtensionIdForCurrentContext();
|
| - return HasPermission(extension_id, function_name);
|
| -}
|
| -
|
| -// static
|
| -bool ExtensionProcessBindings::HasPermission(const std::string& extension_id,
|
| - const std::string& permission) {
|
| - PermissionsList& permissions_list = *GetPermissionsList(extension_id);
|
| - return Extension::HasApiPermission(permissions_list, permission);
|
| -}
|
| -
|
| -// static
|
| -v8::Handle<v8::Value>
|
| - ExtensionProcessBindings::ThrowPermissionDeniedException(
|
| - const std::string& function_name) {
|
| - static const char kMessage[] =
|
| - "You do not have permission to use '%s'. Be sure to declare"
|
| - " in your manifest what permissions you need.";
|
| - std::string error_msg = StringPrintf(kMessage, function_name.c_str());
|
| -
|
| - return v8::ThrowException(v8::Exception::Error(
|
| - v8::String::New(error_msg.c_str())));
|
| -}
|
|
|