Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(111)

Side by Side Diff: chrome/renderer/extensions/chrome_v8_extension.cc

Issue 8659009: Consider the origin when computing extension permissions (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: '' Created 9 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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" 11 #include "chrome/common/extensions/extension.h"
12 #include "chrome/common/extensions/extension_set.h" 12 #include "chrome/common/extensions/extension_set.h"
13 #include "chrome/common/extensions/api/extension_api.h" 13 #include "chrome/common/extensions/api/extension_api.h"
14 #include "chrome/renderer/extensions/chrome_v8_context.h" 14 #include "chrome/renderer/extensions/chrome_v8_context.h"
15 #include "chrome/renderer/extensions/extension_dispatcher.h" 15 #include "chrome/renderer/extensions/extension_dispatcher.h"
16 #include "content/public/renderer/render_view.h" 16 #include "content/public/renderer/render_view.h"
17 #include "third_party/WebKit/Source/WebKit/chromium/public/WebDocument.h" 17 #include "third_party/WebKit/Source/WebKit/chromium/public/WebDocument.h"
18 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h" 18 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h"
19 #include "third_party/WebKit/Source/WebKit/chromium/public/WebView.h" 19 #include "third_party/WebKit/Source/WebKit/chromium/public/WebView.h"
20 #include "ui/base/resource/resource_bundle.h" 20 #include "ui/base/resource/resource_bundle.h"
21 21
22 using extensions::ExtensionAPI; 22 using extensions::ExtensionAPI;
23 using WebKit::WebDocument;
23 using WebKit::WebFrame; 24 using WebKit::WebFrame;
24 using WebKit::WebView; 25 using WebKit::WebView;
25 26
26 namespace { 27 namespace {
27 28
28 const char kChromeHidden[] = "chromeHidden"; 29 const char kChromeHidden[] = "chromeHidden";
29 30
30 #ifndef NDEBUG 31 #ifndef NDEBUG
31 const char kValidateCallbacks[] = "validateCallbacks"; 32 const char kValidateCallbacks[] = "validateCallbacks";
32 #endif 33 #endif
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
102 return NULL; 103 return NULL;
103 else 104 else
104 return iter->second.get(); 105 return iter->second.get();
105 } 106 }
106 107
107 const Extension* ChromeV8Extension::GetExtensionForCurrentRenderView() const { 108 const Extension* ChromeV8Extension::GetExtensionForCurrentRenderView() const {
108 content::RenderView* renderview = GetCurrentRenderView(); 109 content::RenderView* renderview = GetCurrentRenderView();
109 if (!renderview) 110 if (!renderview)
110 return NULL; // this can happen as a tab is closing. 111 return NULL; // this can happen as a tab is closing.
111 112
112 GURL url = renderview->GetWebView()->mainFrame()->document().url(); 113 WebDocument document = renderview->GetWebView()->mainFrame()->document();
114 GURL url = document.url();
113 const ExtensionSet* extensions = extension_dispatcher_->extensions(); 115 const ExtensionSet* extensions = extension_dispatcher_->extensions();
114 if (!extensions->ExtensionBindingsAllowed(url)) 116 if (!extensions->ExtensionBindingsAllowed(document.securityOrigin(), url))
115 return NULL; 117 return NULL;
116 118
117 return extensions->GetByURL(url); 119 return extensions->GetByURL(document.securityOrigin(), url);
118 } 120 }
119 121
120 bool ChromeV8Extension::CheckCurrentContextAccessToExtensionAPI( 122 bool ChromeV8Extension::CheckCurrentContextAccessToExtensionAPI(
121 const std::string& function_name) const { 123 const std::string& function_name) const {
122 ChromeV8Context* context = 124 ChromeV8Context* context =
123 extension_dispatcher_->v8_context_set().GetCurrent(); 125 extension_dispatcher_->v8_context_set().GetCurrent();
124 if (!context) { 126 if (!context) {
125 DLOG(ERROR) << "Not in a v8::Context"; 127 DLOG(ERROR) << "Not in a v8::Context";
126 return false; 128 return false;
127 } 129 }
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after
227 if (args.Length() < 1) 229 if (args.Length() < 1)
228 return v8::Undefined(); 230 return v8::Undefined();
229 231
230 std::vector<std::string> components; 232 std::vector<std::string> components;
231 for (int i = 0; i < args.Length(); ++i) 233 for (int i = 0; i < args.Length(); ++i)
232 components.push_back(*v8::String::Utf8Value(args[i]->ToString())); 234 components.push_back(*v8::String::Utf8Value(args[i]->ToString()));
233 235
234 LOG(ERROR) << JoinString(components, ','); 236 LOG(ERROR) << JoinString(components, ',');
235 return v8::Undefined(); 237 return v8::Undefined();
236 } 238 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698