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

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

Issue 15091002: Lazily load API schemas from resource files and convert all APIs to features (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: changes Created 7 years, 6 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 | Annotate | Revision Log
OLDNEW
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_context.h" 5 #include "chrome/renderer/extensions/chrome_v8_context.h"
6 6
7 #include "base/logging.h" 7 #include "base/logging.h"
8 #include "base/memory/scoped_ptr.h" 8 #include "base/memory/scoped_ptr.h"
9 #include "base/strings/string_split.h" 9 #include "base/strings/string_split.h"
10 #include "base/values.h" 10 #include "base/values.h"
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
59 return extension_.get() ? extension_->id() : std::string(); 59 return extension_.get() ? extension_->id() : std::string();
60 } 60 }
61 61
62 content::RenderView* ChromeV8Context::GetRenderView() const { 62 content::RenderView* ChromeV8Context::GetRenderView() const {
63 if (web_frame_ && web_frame_->view()) 63 if (web_frame_ && web_frame_->view())
64 return content::RenderView::FromWebView(web_frame_->view()); 64 return content::RenderView::FromWebView(web_frame_->view());
65 else 65 else
66 return NULL; 66 return NULL;
67 } 67 }
68 68
69 GURL ChromeV8Context::GetURL() const {
70 return UserScriptSlave::GetDataSourceURLForFrame(web_frame_);
71 }
72
69 v8::Local<v8::Value> ChromeV8Context::CallFunction( 73 v8::Local<v8::Value> ChromeV8Context::CallFunction(
70 v8::Handle<v8::Function> function, 74 v8::Handle<v8::Function> function,
71 int argc, 75 int argc,
72 v8::Handle<v8::Value> argv[]) const { 76 v8::Handle<v8::Value> argv[]) const {
73 v8::HandleScope handle_scope; 77 v8::HandleScope handle_scope;
74 WebKit::WebScopedMicrotaskSuppression suppression; 78 WebKit::WebScopedMicrotaskSuppression suppression;
75 if (!is_valid()) 79 if (!is_valid())
76 return handle_scope.Close(v8::Undefined()); 80 return handle_scope.Close(v8::Undefined());
77 81
78 v8::Handle<v8::Object> global = v8_context()->Global(); 82 v8::Handle<v8::Object> global = v8_context()->Global();
79 if (!web_frame_) 83 if (!web_frame_)
80 return handle_scope.Close(function->Call(global, argc, argv)); 84 return handle_scope.Close(function->Call(global, argc, argv));
81 return handle_scope.Close( 85 return handle_scope.Close(
82 web_frame_->callFunctionEvenIfScriptDisabled(function, 86 web_frame_->callFunctionEvenIfScriptDisabled(function,
83 global, 87 global,
84 argc, 88 argc,
85 argv)); 89 argv));
86 } 90 }
87 91
88 bool ChromeV8Context::IsAnyFeatureAvailableToContext( 92 bool ChromeV8Context::IsAnyFeatureAvailableToContext(
89 const std::string& api_name) { 93 const std::string& api_name) {
90 return ExtensionAPI::GetSharedInstance()->IsAnyFeatureAvailableToContext( 94 return ExtensionAPI::GetSharedInstance()->IsAnyFeatureAvailableToContext(
91 api_name, 95 api_name,
92 context_type_, 96 context_type_,
93 UserScriptSlave::GetDataSourceURLForFrame(web_frame_)); 97 UserScriptSlave::GetDataSourceURLForFrame(web_frame_));
94 } 98 }
95 99
96 Feature::Availability ChromeV8Context::GetAvailability( 100 Feature::Availability ChromeV8Context::GetAvailability(
97 const std::string& api_name) { 101 const std::string& api_name) {
98 return ExtensionAPI::GetSharedInstance()->IsAvailable( 102 return ExtensionAPI::GetSharedInstance()->IsAvailable(api_name,
99 api_name, 103 extension_.get(),
100 extension_.get(), 104 context_type_,
101 context_type_, 105 GetURL());
102 UserScriptSlave::GetDataSourceURLForFrame(web_frame_));
103 } 106 }
104 107
105 void ChromeV8Context::DispatchOnUnloadEvent() { 108 void ChromeV8Context::DispatchOnUnloadEvent() {
106 module_system_->CallModuleMethod("unload_event", "dispatch"); 109 module_system_->CallModuleMethod("unload_event", "dispatch");
107 } 110 }
108 111
109 std::string ChromeV8Context::GetContextTypeDescription() { 112 std::string ChromeV8Context::GetContextTypeDescription() {
110 switch (context_type_) { 113 switch (context_type_) {
111 case Feature::UNSPECIFIED_CONTEXT: return "UNSPECIFIED"; 114 case Feature::UNSPECIFIED_CONTEXT: return "UNSPECIFIED";
112 case Feature::BLESSED_EXTENSION_CONTEXT: return "BLESSED_EXTENSION"; 115 case Feature::BLESSED_EXTENSION_CONTEXT: return "BLESSED_EXTENSION";
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
145 // string if a validation error has occured. 148 // string if a validation error has occured.
146 if (DCHECK_IS_ON()) { 149 if (DCHECK_IS_ON()) {
147 if (!retval.IsEmpty() && !retval->IsUndefined()) { 150 if (!retval.IsEmpty() && !retval->IsUndefined()) {
148 std::string error = *v8::String::AsciiValue(retval); 151 std::string error = *v8::String::AsciiValue(retval);
149 DCHECK(false) << error; 152 DCHECK(false) << error;
150 } 153 }
151 } 154 }
152 } 155 }
153 156
154 } // namespace extensions 157 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698