| 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 <map> | 5 #include <map> |
| 6 #include <set> | 6 #include <set> |
| 7 #include <string> | 7 #include <string> |
| 8 #include <vector> | 8 #include <vector> |
| 9 | 9 |
| 10 #include "chrome/renderer/extensions/extension_process_bindings.h" | 10 #include "chrome/renderer/extensions/extension_process_bindings.h" |
| 11 | 11 |
| 12 #include "base/json_reader.h" | 12 #include "base/json_reader.h" |
| 13 #include "base/singleton.h" | 13 #include "base/singleton.h" |
| 14 #include "chrome/common/extensions/extension.h" | 14 #include "chrome/common/extensions/extension.h" |
| 15 #include "chrome/common/extensions/extension_message_bundle.h" | 15 #include "chrome/common/extensions/extension_message_bundle.h" |
| 16 #include "chrome/common/extensions/url_pattern.h" | 16 #include "chrome/common/extensions/url_pattern.h" |
| 17 #include "chrome/common/render_messages.h" | 17 #include "chrome/common/render_messages.h" |
| 18 #include "chrome/common/url_constants.h" | 18 #include "chrome/common/url_constants.h" |
| 19 #include "chrome/renderer/extensions/bindings_utils.h" | 19 #include "chrome/renderer/extensions/bindings_utils.h" |
| 20 #include "chrome/renderer/extensions/event_bindings.h" | 20 #include "chrome/renderer/extensions/event_bindings.h" |
| 21 #include "chrome/renderer/extensions/js_only_v8_extensions.h" | 21 #include "chrome/renderer/extensions/js_only_v8_extensions.h" |
| 22 #include "chrome/renderer/extensions/renderer_extension_bindings.h" | 22 #include "chrome/renderer/extensions/renderer_extension_bindings.h" |
| 23 #include "chrome/renderer/render_view.h" | 23 #include "chrome/renderer/render_view.h" |
| 24 #include "grit/common_resources.h" | 24 #include "grit/common_resources.h" |
| 25 #include "grit/renderer_resources.h" | 25 #include "grit/renderer_resources.h" |
| 26 #include "third_party/skia/include/core/SkBitmap.h" | 26 #include "third_party/skia/include/core/SkBitmap.h" |
| 27 #include "webkit/api/public/WebFrame.h" | 27 #include "webkit/api/public/WebFrame.h" |
| 28 #include "webkit/api/public/WebURL.h" | 28 #include "webkit/api/public/WebURL.h" |
| 29 #include "webkit/api/public/WebKit.h" | 29 #include "webkit/api/public/WebKit.h" |
| 30 #include "webkit/api/public/WebSecurityPolicy.h" |
| 30 | 31 |
| 31 using bindings_utils::GetStringResource; | 32 using bindings_utils::GetStringResource; |
| 32 using bindings_utils::ContextInfo; | 33 using bindings_utils::ContextInfo; |
| 33 using bindings_utils::ContextList; | 34 using bindings_utils::ContextList; |
| 34 using bindings_utils::GetContexts; | 35 using bindings_utils::GetContexts; |
| 35 using bindings_utils::GetPendingRequestMap; | 36 using bindings_utils::GetPendingRequestMap; |
| 36 using bindings_utils::PendingRequest; | 37 using bindings_utils::PendingRequest; |
| 37 using bindings_utils::PendingRequestMap; | 38 using bindings_utils::PendingRequestMap; |
| 38 using bindings_utils::ExtensionBase; | 39 using bindings_utils::ExtensionBase; |
| 39 using WebKit::WebFrame; | 40 using WebKit::WebFrame; |
| 41 using WebKit::WebSecurityPolicy; |
| 40 using WebKit::WebView; | 42 using WebKit::WebView; |
| 41 | 43 |
| 42 namespace { | 44 namespace { |
| 43 | 45 |
| 44 // A map of extension ID to vector of page action ids. | 46 // A map of extension ID to vector of page action ids. |
| 45 typedef std::map< std::string, std::vector<std::string> > PageActionIdMap; | 47 typedef std::map< std::string, std::vector<std::string> > PageActionIdMap; |
| 46 | 48 |
| 47 // A map of permission name to whether its enabled for this extension. | 49 // A map of permission name to whether its enabled for this extension. |
| 48 typedef std::map<std::string, bool> PermissionsMap; | 50 typedef std::map<std::string, bool> PermissionsMap; |
| 49 | 51 |
| (...skipping 488 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 538 permissions_map[Extension::kPermissionNames[i]] = false; | 540 permissions_map[Extension::kPermissionNames[i]] = false; |
| 539 for (size_t i = 0; i < permissions.size(); ++i) | 541 for (size_t i = 0; i < permissions.size(); ++i) |
| 540 permissions_map[permissions[i]] = true; | 542 permissions_map[permissions[i]] = true; |
| 541 } | 543 } |
| 542 | 544 |
| 543 // static | 545 // static |
| 544 void ExtensionProcessBindings::SetHostPermissions( | 546 void ExtensionProcessBindings::SetHostPermissions( |
| 545 const GURL& extension_url, | 547 const GURL& extension_url, |
| 546 const std::vector<URLPattern>& permissions) { | 548 const std::vector<URLPattern>& permissions) { |
| 547 for (size_t i = 0; i < permissions.size(); ++i) { | 549 for (size_t i = 0; i < permissions.size(); ++i) { |
| 548 WebKit::whiteListAccessFromOrigin( | 550 WebSecurityPolicy::whiteListAccessFromOrigin( |
| 549 extension_url, | 551 extension_url, |
| 550 WebKit::WebString::fromUTF8(permissions[i].scheme()), | 552 WebKit::WebString::fromUTF8(permissions[i].scheme()), |
| 551 WebKit::WebString::fromUTF8(permissions[i].host()), | 553 WebKit::WebString::fromUTF8(permissions[i].host()), |
| 552 permissions[i].match_subdomains()); | 554 permissions[i].match_subdomains()); |
| 553 } | 555 } |
| 554 } | 556 } |
| 555 | 557 |
| 556 // Given a name like "tabs.onConnect", return the permission name required | 558 // Given a name like "tabs.onConnect", return the permission name required |
| 557 // to access that API ("tabs" in this example). | 559 // to access that API ("tabs" in this example). |
| 558 static std::string GetPermissionName(const std::string& function_name) { | 560 static std::string GetPermissionName(const std::string& function_name) { |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 604 return; | 606 return; |
| 605 | 607 |
| 606 v8::HandleScope handle_scope; | 608 v8::HandleScope handle_scope; |
| 607 WebFrame* frame = view->mainFrame(); | 609 WebFrame* frame = view->mainFrame(); |
| 608 v8::Local<v8::Context> context = frame->mainWorldScriptContext(); | 610 v8::Local<v8::Context> context = frame->mainWorldScriptContext(); |
| 609 v8::Handle<v8::Value> argv[1]; | 611 v8::Handle<v8::Value> argv[1]; |
| 610 argv[0] = v8::String::New(type_str); | 612 argv[0] = v8::String::New(type_str); |
| 611 bindings_utils::CallFunctionInContext(context, "setViewType", | 613 bindings_utils::CallFunctionInContext(context, "setViewType", |
| 612 arraysize(argv), argv); | 614 arraysize(argv), argv); |
| 613 } | 615 } |
| OLD | NEW |