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

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

Issue 10698163: Make miscellaneous_bindings.js not depend on onLoad(). (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 5 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/extension_dispatcher.h" 5 #include "chrome/renderer/extensions/extension_dispatcher.h"
6 6
7 #include "base/callback.h" 7 #include "base/callback.h"
8 #include "base/command_line.h" 8 #include "base/command_line.h"
9 #include "base/memory/scoped_ptr.h" 9 #include "base/memory/scoped_ptr.h"
10 #include "base/string_piece.h" 10 #include "base/string_piece.h"
(...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after
188 const Extension* extension) { 188 const Extension* extension) {
189 if (!render_view) 189 if (!render_view)
190 return false; 190 return false;
191 191
192 ExtensionHelper* helper = ExtensionHelper::Get(render_view); 192 ExtensionHelper* helper = ExtensionHelper::Get(render_view);
193 return (extension && extension->has_lazy_background_page() && 193 return (extension && extension->has_lazy_background_page() &&
194 helper->view_type() == chrome::VIEW_TYPE_EXTENSION_BACKGROUND_PAGE); 194 helper->view_type() == chrome::VIEW_TYPE_EXTENSION_BACKGROUND_PAGE);
195 } 195 }
196 }; 196 };
197 197
198 class ProcessInfoNativeHandler : public ChromeV8Extension {
199 public:
200 explicit ProcessInfoNativeHandler(
201 ExtensionDispatcher* dispatcher,
202 const std::string& extension_id,
203 const std::string& context_type,
204 bool is_incognito_context,
205 int manifest_version)
206 : ChromeV8Extension(dispatcher),
207 extension_id_(extension_id),
208 context_type_(context_type),
209 is_incognito_context_(is_incognito_context),
210 manifest_version_(manifest_version) {
211 RouteFunction("GetExtensionId",
212 base::Bind(&ProcessInfoNativeHandler::GetExtensionId,
213 base::Unretained(this)));
214 RouteFunction("GetContextType",
215 base::Bind(&ProcessInfoNativeHandler::GetContextType,
216 base::Unretained(this)));
217 RouteFunction("IsIncognitoContext",
218 base::Bind(&ProcessInfoNativeHandler::IsIncognitoContext,
219 base::Unretained(this)));
220 RouteFunction("GetManifestVersion",
221 base::Bind(&ProcessInfoNativeHandler::GetManifestVersion,
222 base::Unretained(this)));
223 }
224
225 v8::Handle<v8::Value> GetExtensionId(const v8::Arguments& args) {
226 return v8::String::New(extension_id_.c_str());
227 }
228
229 v8::Handle<v8::Value> GetContextType(const v8::Arguments& args) {
230 return v8::String::New(context_type_.c_str());
231 }
232
233 v8::Handle<v8::Value> IsIncognitoContext(const v8::Arguments& args) {
234 return v8::Boolean::New(is_incognito_context_);
235 }
236
237 v8::Handle<v8::Value> GetManifestVersion(const v8::Arguments& args) {
238 return v8::Integer::New(manifest_version_);
239 }
240
241 private:
242 std::string extension_id_;
243 std::string context_type_;
244 bool is_incognito_context_;
245 int manifest_version_;
246 };
247
198 class ChannelNativeHandler : public NativeHandler { 248 class ChannelNativeHandler : public NativeHandler {
199 public: 249 public:
200 explicit ChannelNativeHandler(chrome::VersionInfo::Channel channel) 250 explicit ChannelNativeHandler(chrome::VersionInfo::Channel channel)
201 : channel_(channel) { 251 : channel_(channel) {
202 RouteFunction("IsDevChannel", 252 RouteFunction("IsDevChannel",
203 base::Bind(&ChannelNativeHandler::IsDevChannel, 253 base::Bind(&ChannelNativeHandler::IsDevChannel,
204 base::Unretained(this))); 254 base::Unretained(this)));
205 } 255 }
206 256
207 v8::Handle<v8::Value> IsDevChannel(const v8::Arguments& args) { 257 v8::Handle<v8::Value> IsDevChannel(const v8::Arguments& args) {
(...skipping 475 matching lines...) Expand 10 before | Expand all | Expand 10 after
683 733
684 module_system->RegisterNativeHandler("chrome_hidden", 734 module_system->RegisterNativeHandler("chrome_hidden",
685 scoped_ptr<NativeHandler>(new ChromeHiddenNativeHandler())); 735 scoped_ptr<NativeHandler>(new ChromeHiddenNativeHandler()));
686 module_system->RegisterNativeHandler("print", 736 module_system->RegisterNativeHandler("print",
687 scoped_ptr<NativeHandler>(new PrintNativeHandler())); 737 scoped_ptr<NativeHandler>(new PrintNativeHandler()));
688 module_system->RegisterNativeHandler("lazy_background_page", 738 module_system->RegisterNativeHandler("lazy_background_page",
689 scoped_ptr<NativeHandler>(new LazyBackgroundPageNativeHandler(this))); 739 scoped_ptr<NativeHandler>(new LazyBackgroundPageNativeHandler(this)));
690 module_system->RegisterNativeHandler("channel", 740 module_system->RegisterNativeHandler("channel",
691 scoped_ptr<NativeHandler>(new ChannelNativeHandler( 741 scoped_ptr<NativeHandler>(new ChannelNativeHandler(
692 static_cast<chrome::VersionInfo::Channel>(chrome_channel_)))); 742 static_cast<chrome::VersionInfo::Channel>(chrome_channel_))));
743
744 int manifest_version = extension ? extension->manifest_version() : 1;
745 module_system->RegisterNativeHandler("process",
746 scoped_ptr<NativeHandler>(new ProcessInfoNativeHandler(
747 this, context->GetExtensionID(),
748 context->GetContextTypeDescription(),
749 ChromeRenderProcessObserver::is_incognito_process(),
750 manifest_version)));
693 // Create the 'chrome' variable if it doesn't already exist. 751 // Create the 'chrome' variable if it doesn't already exist.
694 { 752 {
695 v8::HandleScope handle_scope; 753 v8::HandleScope handle_scope;
696 v8::Handle<v8::String> chrome_string(v8::String::New("chrome")); 754 v8::Handle<v8::String> chrome_string(v8::String::New("chrome"));
697 v8::Handle<v8::Object> global(v8::Context::GetCurrent()->Global()); 755 v8::Handle<v8::Object> global(v8::Context::GetCurrent()->Global());
698 v8::Handle<v8::Value> chrome(global->Get(chrome_string)); 756 v8::Handle<v8::Value> chrome(global->Get(chrome_string));
699 if (chrome.IsEmpty() || chrome->IsUndefined()) 757 if (chrome.IsEmpty() || chrome->IsUndefined())
700 global->Set(chrome_string, v8::Object::New()); 758 global->Set(chrome_string, v8::Object::New());
701 } 759 }
702 760
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
737 if (IsWithinPlatformApp(frame)) 795 if (IsWithinPlatformApp(frame))
738 module_system->Require("platformApp"); 796 module_system->Require("platformApp");
739 797
740 if (context_type == Feature::BLESSED_EXTENSION_CONTEXT && 798 if (context_type == Feature::BLESSED_EXTENSION_CONTEXT &&
741 extension && extension->HasAPIPermission(APIPermission::kBrowserTag)) { 799 extension && extension->HasAPIPermission(APIPermission::kBrowserTag)) {
742 module_system->Require("browserTag"); 800 module_system->Require("browserTag");
743 } 801 }
744 802
745 context->set_module_system(module_system.Pass()); 803 context->set_module_system(module_system.Pass());
746 804
747 int manifest_version = 1;
748 if (extension)
749 manifest_version = extension->manifest_version();
750 context->DispatchOnLoadEvent( 805 context->DispatchOnLoadEvent(
751 ChromeRenderProcessObserver::is_incognito_process(), 806 ChromeRenderProcessObserver::is_incognito_process(),
752 manifest_version); 807 manifest_version);
753 808
754 VLOG(1) << "Num tracked contexts: " << v8_context_set_.size(); 809 VLOG(1) << "Num tracked contexts: " << v8_context_set_.size();
755 } 810 }
756 811
757 std::string ExtensionDispatcher::GetExtensionID(const WebFrame* frame, 812 std::string ExtensionDispatcher::GetExtensionID(const WebFrame* frame,
758 int world_id) { 813 int world_id) {
759 if (world_id != 0) { 814 if (world_id != 0) {
(...skipping 272 matching lines...) Expand 10 before | Expand all | Expand 10 after
1032 // APIs, they don't get extension bindings injected. If we end up here it 1087 // APIs, they don't get extension bindings injected. If we end up here it
1033 // means that a sandboxed page somehow managed to invoke an API anyway, so 1088 // means that a sandboxed page somehow managed to invoke an API anyway, so
1034 // we should abort. 1089 // we should abort.
1035 WebKit::WebFrame* frame = context->web_frame(); 1090 WebKit::WebFrame* frame = context->web_frame();
1036 ExtensionURLInfo url_info(frame->document().securityOrigin(), 1091 ExtensionURLInfo url_info(frame->document().securityOrigin(),
1037 UserScriptSlave::GetDataSourceURLForFrame(frame)); 1092 UserScriptSlave::GetDataSourceURLForFrame(frame));
1038 CHECK(!extensions_.IsSandboxedPage(url_info)); 1093 CHECK(!extensions_.IsSandboxedPage(url_info));
1039 1094
1040 return true; 1095 return true;
1041 } 1096 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698