| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/chrome_v8_extension.h" | 5 #include "chrome/renderer/extensions/chrome_v8_extension.h" |
| 6 | 6 |
| 7 #include "base/logging.h" | 7 #include "base/logging.h" |
| 8 #include "base/lazy_instance.h" | 8 #include "base/lazy_instance.h" |
| 9 #include "base/stringprintf.h" | 9 #include "base/stringprintf.h" |
| 10 #include "base/string_util.h" | 10 #include "base/string_util.h" |
| 11 #include "chrome/common/extensions/extension.h" | |
| 12 #include "chrome/common/extensions/extension_set.h" | |
| 13 #include "chrome/common/extensions/api/extension_api.h" | |
| 14 #include "chrome/renderer/extensions/chrome_v8_context.h" | |
| 15 #include "chrome/renderer/extensions/extension_dispatcher.h" | 11 #include "chrome/renderer/extensions/extension_dispatcher.h" |
| 16 #include "content/public/renderer/render_view.h" | 12 #include "content/public/renderer/render_view.h" |
| 17 #include "third_party/WebKit/Source/WebKit/chromium/public/WebDocument.h" | 13 #include "third_party/WebKit/Source/WebKit/chromium/public/WebDocument.h" |
| 18 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h" | 14 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h" |
| 19 #include "third_party/WebKit/Source/WebKit/chromium/public/WebView.h" | 15 #include "third_party/WebKit/Source/WebKit/chromium/public/WebView.h" |
| 20 #include "ui/base/resource/resource_bundle.h" | 16 #include "ui/base/resource/resource_bundle.h" |
| 21 | 17 |
| 22 using extensions::ExtensionAPI; | |
| 23 using WebKit::WebDocument; | 18 using WebKit::WebDocument; |
| 24 using WebKit::WebFrame; | 19 using WebKit::WebFrame; |
| 25 using WebKit::WebView; | 20 using WebKit::WebView; |
| 26 | 21 |
| 27 namespace { | 22 namespace { |
| 28 | 23 |
| 29 static base::LazyInstance<ChromeV8Extension::InstanceSet> g_instances = | 24 static base::LazyInstance<ChromeV8Extension::InstanceSet> g_instances = |
| 30 LAZY_INSTANCE_INITIALIZER; | 25 LAZY_INSTANCE_INITIALIZER; |
| 31 | 26 |
| 32 } // namespace | 27 } // namespace |
| (...skipping 21 matching lines...) Expand all Loading... |
| 54 } | 49 } |
| 55 | 50 |
| 56 ChromeV8Extension::~ChromeV8Extension() { | 51 ChromeV8Extension::~ChromeV8Extension() { |
| 57 g_instances.Get().erase(this); | 52 g_instances.Get().erase(this); |
| 58 } | 53 } |
| 59 | 54 |
| 60 // static | 55 // static |
| 61 const ChromeV8Extension::InstanceSet& ChromeV8Extension::GetAll() { | 56 const ChromeV8Extension::InstanceSet& ChromeV8Extension::GetAll() { |
| 62 return g_instances.Get(); | 57 return g_instances.Get(); |
| 63 } | 58 } |
| 64 | |
| 65 const Extension* ChromeV8Extension::GetExtensionForCurrentRenderView() const { | |
| 66 content::RenderView* renderview = GetCurrentRenderView(); | |
| 67 if (!renderview) | |
| 68 return NULL; // this can happen as a tab is closing. | |
| 69 | |
| 70 WebDocument document = renderview->GetWebView()->mainFrame()->document(); | |
| 71 GURL url = document.url(); | |
| 72 const ExtensionSet* extensions = extension_dispatcher_->extensions(); | |
| 73 if (!extensions->ExtensionBindingsAllowed( | |
| 74 ExtensionURLInfo(document.securityOrigin(), url))) | |
| 75 return NULL; | |
| 76 | |
| 77 return extensions->GetExtensionOrAppByURL( | |
| 78 ExtensionURLInfo(document.securityOrigin(), url)); | |
| 79 } | |
| OLD | NEW |