OLD | NEW |
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 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 | 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> |
11 | 11 |
| 12 #include "base/command_line.h" |
12 #include "base/json/json_reader.h" | 13 #include "base/json/json_reader.h" |
13 #include "base/singleton.h" | 14 #include "base/singleton.h" |
| 15 #include "chrome/common/child_process_logging.h" |
| 16 #include "chrome/common/chrome_switches.h" |
14 #include "chrome/common/extensions/extension.h" | 17 #include "chrome/common/extensions/extension.h" |
15 #include "chrome/common/extensions/extension_message_bundle.h" | 18 #include "chrome/common/extensions/extension_message_bundle.h" |
16 #include "chrome/common/extensions/url_pattern.h" | 19 #include "chrome/common/extensions/url_pattern.h" |
17 #include "chrome/common/render_messages.h" | 20 #include "chrome/common/render_messages.h" |
18 #include "chrome/common/url_constants.h" | 21 #include "chrome/common/url_constants.h" |
19 #include "chrome/renderer/extensions/bindings_utils.h" | 22 #include "chrome/renderer/extensions/bindings_utils.h" |
20 #include "chrome/renderer/extensions/event_bindings.h" | 23 #include "chrome/renderer/extensions/event_bindings.h" |
21 #include "chrome/renderer/extensions/js_only_v8_extensions.h" | 24 #include "chrome/renderer/extensions/js_only_v8_extensions.h" |
22 #include "chrome/renderer/extensions/renderer_extension_bindings.h" | 25 #include "chrome/renderer/extensions/renderer_extension_bindings.h" |
23 #include "chrome/renderer/render_view.h" | 26 #include "chrome/renderer/render_view.h" |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
95 static L10nMessagesMap* GetL10nMessagesMap(const std::string extension_id) { | 98 static L10nMessagesMap* GetL10nMessagesMap(const std::string extension_id) { |
96 ExtensionToL10nMessagesMap::iterator it = | 99 ExtensionToL10nMessagesMap::iterator it = |
97 Singleton<SingletonData>()->extension_l10n_messages_map_.find(extension_id); | 100 Singleton<SingletonData>()->extension_l10n_messages_map_.find(extension_id); |
98 if (it != Singleton<SingletonData>()->extension_l10n_messages_map_.end()) { | 101 if (it != Singleton<SingletonData>()->extension_l10n_messages_map_.end()) { |
99 return &(it->second); | 102 return &(it->second); |
100 } else { | 103 } else { |
101 return NULL; | 104 return NULL; |
102 } | 105 } |
103 } | 106 } |
104 | 107 |
| 108 static std::vector<std::string> GetActiveExtensionIDs() { |
| 109 std::vector<std::string> extension_ids; |
| 110 ExtensionPermissionsMap& permissions = |
| 111 Singleton<SingletonData>()->permissions_; |
| 112 |
| 113 for (ExtensionPermissionsMap::iterator iter = permissions.begin(); |
| 114 iter != permissions.end(); ++iter) { |
| 115 extension_ids.push_back(iter->first); |
| 116 } |
| 117 |
| 118 return extension_ids; |
| 119 } |
| 120 |
105 // A RenderViewVisitor class that iterates through the set of available | 121 // A RenderViewVisitor class that iterates through the set of available |
106 // views, looking for a view of the given type, in the given browser window | 122 // views, looking for a view of the given type, in the given browser window |
107 // and within the given extension. | 123 // and within the given extension. |
108 // Used to accumulate the list of views associated with an extension. | 124 // Used to accumulate the list of views associated with an extension. |
109 class ExtensionViewAccumulator : public RenderViewVisitor { | 125 class ExtensionViewAccumulator : public RenderViewVisitor { |
110 public: | 126 public: |
111 ExtensionViewAccumulator(const std::string& extension_id, | 127 ExtensionViewAccumulator(const std::string& extension_id, |
112 int browser_window_id, | 128 int browser_window_id, |
113 ViewType::Type view_type) | 129 ViewType::Type view_type) |
114 : extension_id_(extension_id), | 130 : extension_id_(extension_id), |
(...skipping 504 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
619 void ExtensionProcessBindings::SetAPIPermissions( | 635 void ExtensionProcessBindings::SetAPIPermissions( |
620 const std::string& extension_id, | 636 const std::string& extension_id, |
621 const std::vector<std::string>& permissions) { | 637 const std::vector<std::string>& permissions) { |
622 PermissionsMap& permissions_map = *GetPermissionsMap(extension_id); | 638 PermissionsMap& permissions_map = *GetPermissionsMap(extension_id); |
623 | 639 |
624 // Default all the API permissions to off. We will reset them below. | 640 // Default all the API permissions to off. We will reset them below. |
625 for (size_t i = 0; i < Extension::kNumPermissions; ++i) | 641 for (size_t i = 0; i < Extension::kNumPermissions; ++i) |
626 permissions_map[Extension::kPermissionNames[i]] = false; | 642 permissions_map[Extension::kPermissionNames[i]] = false; |
627 for (size_t i = 0; i < permissions.size(); ++i) | 643 for (size_t i = 0; i < permissions.size(); ++i) |
628 permissions_map[permissions[i]] = true; | 644 permissions_map[permissions[i]] = true; |
| 645 |
| 646 // Ugly hack. We also update our list of active extensions here. This always |
| 647 // gets called, even if the extension has no api permissions. In single |
| 648 // process, this has already been done in the browser code. |
| 649 if (!CommandLine::ForCurrentProcess()->HasSwitch(switches::kSingleProcess)) |
| 650 child_process_logging::SetActiveExtensions(GetActiveExtensionIDs()); |
629 } | 651 } |
630 | 652 |
631 // static | 653 // static |
632 void ExtensionProcessBindings::SetHostPermissions( | 654 void ExtensionProcessBindings::SetHostPermissions( |
633 const GURL& extension_url, | 655 const GURL& extension_url, |
634 const std::vector<URLPattern>& permissions) { | 656 const std::vector<URLPattern>& permissions) { |
635 for (size_t i = 0; i < permissions.size(); ++i) { | 657 for (size_t i = 0; i < permissions.size(); ++i) { |
636 WebSecurityPolicy::whiteListAccessFromOrigin( | 658 WebSecurityPolicy::whiteListAccessFromOrigin( |
637 extension_url, | 659 extension_url, |
638 WebKit::WebString::fromUTF8(permissions[i].scheme()), | 660 WebKit::WebString::fromUTF8(permissions[i].scheme()), |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
692 return; | 714 return; |
693 | 715 |
694 v8::HandleScope handle_scope; | 716 v8::HandleScope handle_scope; |
695 WebFrame* frame = view->mainFrame(); | 717 WebFrame* frame = view->mainFrame(); |
696 v8::Local<v8::Context> context = frame->mainWorldScriptContext(); | 718 v8::Local<v8::Context> context = frame->mainWorldScriptContext(); |
697 v8::Handle<v8::Value> argv[1]; | 719 v8::Handle<v8::Value> argv[1]; |
698 argv[0] = v8::String::New(type_str); | 720 argv[0] = v8::String::New(type_str); |
699 bindings_utils::CallFunctionInContext(context, "setViewType", | 721 bindings_utils::CallFunctionInContext(context, "setViewType", |
700 arraysize(argv), argv); | 722 arraysize(argv), argv); |
701 } | 723 } |
OLD | NEW |