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