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

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

Issue 173166: Implement granular cross-origin XHR for extensions. (Closed)
Patch Set: some cleanup Created 11 years, 4 months 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
OLDNEW
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 "base/singleton.h" 7 #include "base/singleton.h"
8 #include "chrome/common/extensions/extension.h" 8 #include "chrome/common/extensions/extension.h"
9 #include "chrome/common/extensions/url_pattern.h"
9 #include "chrome/common/render_messages.h" 10 #include "chrome/common/render_messages.h"
10 #include "chrome/common/url_constants.h" 11 #include "chrome/common/url_constants.h"
11 #include "chrome/renderer/extensions/bindings_utils.h" 12 #include "chrome/renderer/extensions/bindings_utils.h"
12 #include "chrome/renderer/extensions/event_bindings.h" 13 #include "chrome/renderer/extensions/event_bindings.h"
13 #include "chrome/renderer/extensions/renderer_extension_bindings.h" 14 #include "chrome/renderer/extensions/renderer_extension_bindings.h"
14 #include "chrome/renderer/js_only_v8_extensions.h" 15 #include "chrome/renderer/js_only_v8_extensions.h"
15 #include "chrome/renderer/render_view.h" 16 #include "chrome/renderer/render_view.h"
16 #include "grit/common_resources.h" 17 #include "grit/common_resources.h"
17 #include "grit/renderer_resources.h" 18 #include "grit/renderer_resources.h"
18 #include "webkit/api/public/WebFrame.h" 19 #include "webkit/api/public/WebFrame.h"
20 #include "webkit/api/public/WebURL.h"
21 #include "webkit/api/public/WebKit.h"
19 22
20 using bindings_utils::GetStringResource; 23 using bindings_utils::GetStringResource;
21 using bindings_utils::ContextInfo; 24 using bindings_utils::ContextInfo;
22 using bindings_utils::ContextList; 25 using bindings_utils::ContextList;
23 using bindings_utils::GetContexts; 26 using bindings_utils::GetContexts;
24 using bindings_utils::GetPendingRequestMap; 27 using bindings_utils::GetPendingRequestMap;
25 using bindings_utils::PendingRequest; 28 using bindings_utils::PendingRequest;
26 using bindings_utils::PendingRequestMap; 29 using bindings_utils::PendingRequestMap;
27 using bindings_utils::ExtensionBase; 30 using bindings_utils::ExtensionBase;
28 31
(...skipping 282 matching lines...) Expand 10 before | Expand all | Expand 10 after
311 PageActionIdMap& page_action_map = *GetPageActionMap(); 314 PageActionIdMap& page_action_map = *GetPageActionMap();
312 if (!page_actions.empty()) { 315 if (!page_actions.empty()) {
313 page_action_map[extension_id] = page_actions; 316 page_action_map[extension_id] = page_actions;
314 } else { 317 } else {
315 if (page_action_map.find(extension_id) != page_action_map.end()) 318 if (page_action_map.find(extension_id) != page_action_map.end())
316 page_action_map.erase(extension_id); 319 page_action_map.erase(extension_id);
317 } 320 }
318 } 321 }
319 322
320 // static 323 // static
321 void ExtensionProcessBindings::SetPermissions( 324 void ExtensionProcessBindings::SetAPIPermissions(
322 const std::string& extension_id, 325 const std::string& extension_id,
323 const std::vector<std::string>& permissions) { 326 const std::vector<std::string>& permissions) {
324 PermissionsMap& permissions_map = *GetPermissionsMap(extension_id); 327 PermissionsMap& permissions_map = *GetPermissionsMap(extension_id);
325 328
326 // Default all permissions to false, then enable the ones in the vector. 329 // Default all the API permissions to off. We will reset them below.
327 for (size_t i = 0; i < Extension::kNumPermissions; ++i) 330 for (size_t i = 0; i < Extension::kNumPermissions; ++i)
328 permissions_map[Extension::kPermissionNames[i]] = false; 331 permissions_map[Extension::kPermissionNames[i]] = false;
329 for (size_t i = 0; i < permissions.size(); ++i) 332 for (size_t i = 0; i < permissions.size(); ++i)
330 permissions_map[permissions[i]] = true; 333 permissions_map[permissions[i]] = true;
331 } 334 }
332 335
336 // static
337 void ExtensionProcessBindings::SetHostPermissions(
338 const GURL& extension_url,
339 const std::vector<URLPattern>& permissions) {
340 for (size_t i = 0; i < permissions.size(); ++i) {
341 WebKit::whiteListAccessFromOrigin(
342 extension_url,
343 WebKit::WebString::fromUTF8(permissions[i].scheme()),
344 WebKit::WebString::fromUTF8(permissions[i].host()),
345 permissions[i].match_subdomains());
346 }
347 }
348
333 // Given a name like "tabs.onConnect", return the permission name required 349 // Given a name like "tabs.onConnect", return the permission name required
334 // to access that API ("tabs" in this example). 350 // to access that API ("tabs" in this example).
335 static std::string GetPermissionName(const std::string& function_name) { 351 static std::string GetPermissionName(const std::string& function_name) {
336 size_t first_dot = function_name.find('.'); 352 size_t first_dot = function_name.find('.');
337 std::string permission_name = function_name.substr(0, first_dot); 353 std::string permission_name = function_name.substr(0, first_dot);
338 if (permission_name == "windows") 354 if (permission_name == "windows")
339 return "tabs"; // windows and tabs are the same permission. 355 return "tabs"; // windows and tabs are the same permission.
340 return permission_name; 356 return permission_name;
341 } 357 }
342 358
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
381 397
382 v8::Local<v8::Function> function = 398 v8::Local<v8::Function> function =
383 v8::Local<v8::Function>::Cast(console_error); 399 v8::Local<v8::Function>::Cast(console_error);
384 v8::Local<v8::Value> argv[] = { v8::String::New(error_msg.c_str()) }; 400 v8::Local<v8::Value> argv[] = { v8::String::New(error_msg.c_str()) };
385 if (!function.IsEmpty()) 401 if (!function.IsEmpty())
386 function->Call(console->ToObject(), arraysize(argv), argv); 402 function->Call(console->ToObject(), arraysize(argv), argv);
387 403
388 return v8::Undefined(); 404 return v8::Undefined();
389 #endif 405 #endif
390 } 406 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698